inasafe / inasafe-fba

Next generation of InaSAFE that includes support for forecast based action
MIT License
1 stars 8 forks source link

Document Road Type Vulnerability score mapping #76

Closed lucernae closed 4 years ago

lucernae commented 4 years ago

@NyakudyaA can you just clarify that we have some sort of functions to evaluate road vulnerability score? There is a GeoServer styles that uses road score, but I haven't found database functions that evaluates this scores.

NyakudyaA commented 4 years ago

Here it is @lucernae

CREATE OR REPLACE FUNCTION kartoza_road_score_mapper () RETURNS trigger LANGUAGE plpgsql
AS $$
BEGIN
     SELECT
        CASE
            WHEN new.road_type = 'Motorway link' THEN 1
            WHEN new.road_type = 'Motorway or highway' THEN 0.8
            WHEN new.road_type = 'Primary link' THEN 0.7
            WHEN new.road_type = 'Primary road' THEN 0.6
            WHEN new.road_type = 'Road,residential,living street, etc' THEN 0.2
            WHEN new.road_type = 'Secondary' THEN 0.3
            WHEN new.road_type = 'Secondary link' THEN 0.3
            WHEN new.road_type = 'Tertiary' THEN 0.4
            WHEN new.road_type = 'Tertiary link' THEN 0.4
            WHEN new.road_type = 'Track' THEN 0.1
        END
     INTO new.road_type_score
     FROM osm_buildings
    ;
  RETURN NEW;
  END
  $$;
CREATE TRIGGER road_type_score_tg AFTER INSERT OR UPDATE ON osm_roads FOR EACH ROW EXECUTE PROCEDURE
    kartoza_road_score_mapper();
lucernae commented 4 years ago

Done we can close