Managing WCMC Information
Protecting the Planet with PostGIS
How we are calculating complex protected area coverage statistics for all countries in the world.
Miguel Torres, Data Manager, UNEP-WCMC
Protecting the Planet with PostGIS How we are calculating complex - - PowerPoint PPT Presentation
Protecting the Planet with PostGIS How we are calculating complex protected area coverage statistics for all countries in the world. Miguel Torres, Data Manager, UNEP-WCMC Managing WCMC Information Protected Planet All Protected Areas of the
Managing WCMC Information
Miguel Torres, Data Manager, UNEP-WCMC
Managing WCMC Information
All Protected Areas of the World in one Website
Managing WCMC Information
All Protected Areas of the World in one Website
Managing WCMC Information
Protected Area Page
Managing WCMC Information
Github Repository
Managing WCMC Information
Dataset
Managing WCMC Information
Calculate every month, automatically:
Managing WCMC Information
Methodology
Managing WCMC Information
National Statistics
Managing WCMC Information
Overlapping Protected Areas
Managing WCMC Information
Overlapping Protected Areas
Managing WCMC Information
Overlapping Protected Areas
Managing WCMC Information
Overlapping Protected Areas
Managing WCMC Information
Dissolving All Geometries
SELECT iso3, ST_Union(the_geom) FROM standard_polygons GROUP BY iso3 Medebach, Germany
Managing WCMC Information
Splitting by Countries
SELECT iso3, ST_Union(the_geom) FROM standard_polygons WHERE iso3 = #{iso3} GROUP BY iso3 Gerês / Xurés, Portugal / Spain
Managing WCMC Information
Splitting by Type
SELECT iso3, ST_Union(the_geom) FROM standard_polygons WHERE iso3 = #{iso3} AND is_marine = #{type} GROUP BY iso3 Bijagós, Guinea Bissau
Managing WCMC Information
Adding Point Geometries
SELECT ST_UNION(the_geom) as the_geom FROM ( SELECT iso3, the_geom the_geom FROM standard_polygons WHERE iso3 = #{iso3} AND is_marine = #{type} GROUP BY iso3 UNION SELECT iso3, ST_Buffer(the_geom::geography, |/( rep_area*1000000 / pi() ))::geometry the_geom FROM standard_points WHERE iso3 = #{iso3} AND is_marine = #{type} ) a Mahajanga, Madagascar
Managing WCMC Information
Simplifying Geometries in Certain Countries
COMPLEX_COUNTRIES = { 'marine' => ['GBR','USA','CAN','MYT','CIV','AUS'], 'land' => ['DEU','USA','FRA','GBR','AUS','FIN','BGR','CAN', 'ESP','SWE','BEL','EST','IRL','ITA','LTU', 'NZL','POL','CHE'] } def geometry_attribute country, area_type if COMPLEX_COUNTRIES[area_type].include? country.iso_3 'ST_Makevalid(ST_Buffer(ST_Simplify(the_geom,0.005),0.0))' else 'the_geom' end end United States
Managing WCMC Information
Simplifying Geometries in Certain Countries
SELECT ST_UNION(the_geom) as the_geom FROM ( SELECT iso3, ST_Union(#{geometry_attribute(country, area_type)}) the_geom FROM standard_polygons WHERE iso3 = #{iso3} AND is_marine = #{type} UNION SELECT iso3, ST_Buffer(the_geom::geography, |/( rep_area*1000000 / pi() ))::geometry the_geom FROM standard_points WHERE iso3 = #{iso3} AND is_marine = #{type} ) a United States
Managing WCMC Information
Dealing with Transnational Protected Areas
SELECT ST_UNION(the_geom) as the_geom FROM ( SELECT iso3, #{geometry_attribute(country, area_type)} the_geom FROM standard_polygons WHERE iso3 = #{iso3} AND is_marine = #{type} UNION SELECT iso3, ST_Buffer(the_geom::geography, |/( rep_area*1000000 / pi() ))::geometry the_geom FROM standard_points WHERE iso3 = #{iso3} AND is_marine = #{type} UNION SELECT country.iso_3, ST_Intersection(country.land_geom, polygon.the_geom) the_geom FROM standard_polygons polygon INNER JOIN countries country ON ST_Intersects(country.land_geom, polygon.the_geom) WHERE polygon.iso3 LIKE '%,%' AND iso3 = #{iso3} AND is_marine = #{type} ) a Waterton Glacier International Peace Park, United States / Canada
Managing WCMC Information
Excluding Not Relevant for Statistics’ Protected Areas
SELECT ST_UNION(the_geom) as the_geom FROM ( SELECT iso3, #{geometry_attribute(country, area_type)} the_geom FROM standard_polygons WHERE iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') UNION SELECT iso3, ST_Buffer(the_geom::geography, |/( rep_area*1000000 / pi() ))::geometry the_geom FROM standard_points WHERE iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') UNION SELECT country.iso_3, ST_Intersection(country.land_geom, polygon.the_geom) the_geom FROM standard_polygons polygon INNER JOIN countries country ON ST_Intersects(country.land_geom, polygon.the_geom) WHERE polygon.iso3 LIKE '%,%' AND iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') ) a Nilgiri, India
Managing WCMC Information
Making Geometries Valid
SELECT ST_UNION(the_geom) as the_geom FROM ( SELECT iso3, #{geometry_attribute(country, area_type)} the_geom FROM standard_polygons WHERE iso3 = #{iso3} AND ST_IsValid(polygon.wkb_geometry) AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') UNION SELECT iso3, ST_Buffer(the_geom::geography, |/( rep_area*1000000 / pi() ))::geometry the_geom FROM standard_points WHERE iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') UNION SELECT country.iso_3, ST_Makevalid(ST_Intersection(ST_Buffer(country.land_geom,0.0), polygon. the_geom)) the_geom FROM standard_polygons polygon INNER JOIN countries country ON ST_Intersects(ST_Buffer(country.land_geom,0.0), polygon. the_geom) WHERE polygon.iso3 LIKE '%,%' AND iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') ) a Rio de Janeiro, Brazil
Managing WCMC Information
Updating the Table with the flat geometries
UPDATE countries SET #{type}_pas_geom = a.the_geom FROM( SELECT ST_UNION(the_geom) as the_geom FROM ( SELECT iso3, #{geometry_attribute(country, area_type)} the_geom FROM standard_polygons WHERE iso3 = #{iso3} AND ST_IsValid(polygon.wkb_geometry) AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') UNION SELECT iso3, ST_Buffer(the_geom::geography, |/( rep_area*1000000 / pi() ))::geometry the_geom FROM standard_points WHERE iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') UNION SELECT country.iso_3, ST_Makevalid(ST_Intersection(ST_Buffer(country.land_geom,0.0), polygon.the_geom)) the_geom FROM standard_polygons polygon INNER JOIN countries country ON ST_Intersects(ST_Buffer(country.land_geom,0.0), polygon.the_geom) WHERE polygon.iso3 LIKE '%,%' AND iso3 = #{iso3} AND is_marine = #{type} AND status NOT IN ('Proposed', 'Not Reported') AND desig NOT IN ('UNESCO-MAB Biosphere Reserve', 'UNESCO-MAB Réserve de Biosphère') ) b ) a Quiçama, Angola
Managing WCMC Information
Values to Calculate
Managing WCMC Information
Updating the Table with the flat geometries
SELECT land_area, eez_area, ts_area, pa_land_area + pa_marine_area, pa_land_area, pa_marine_area, (pa_land_area + pa_marine_area) / (land_area + eez_area + ts_area)*100, pa_land_area / land_area * 100, FROM ( SELECT id, ST_Area(ST_Transform(land_pas_geom,954009)) pa_land_area, ST_Area(ST_Transform(marine_pas_geom,954009)) pa_marine_area, ST_Area(ST_Transform(land_geom,954009)) land_area, ST_Area(ST_Transform(eez_geom,954009)) eez_area, ST_Area(ST_Transform(ts_geom,954009)) ts_Area FROM countries ) areas United States
Managing WCMC Information
Handling Null Values
SELECT land_area, eez_area, ts_area, COALESCE(pa_land_area,0) + COALESCE(pa_marine_area,0), pa_land_area, pa_marine_area, (COALESCE(pa_land_area,0) + COALESCE(pa_marine_area,0)) / (land_area + COALESCE(eez_area, 0) + COALESCE(ts_area,0))*100, COALESCE(pa_land_area,0) / land_area * 100, CASE WHEN eez_area = 0 THEN ELSE COALESCE(pa_eez_area,0) / eez_area * 100 END, CASE WHEN ts_area = 0 THEN ELSE COALESCE(pa_ts_area,0) / ts_area * 100 END FROM ( SELECT id, ST_Area(ST_Transform(land_pas_geom,954009)) pa_land_area, ST_Area(ST_Transform(marine_pas_geom,954009)) pa_marine_area, ST_Area(ST_Transform(land_geom,954009)) land_area, ST_Area(ST_Transform(eez_geom,954009)) eez_area, ST_Area(ST_Transform(ts_geom,954009)) ts_Area FROM countries ) areas China
Managing WCMC Information
Insert into Stats Table
INSERT INTO country_statistics ( country_id, land_area, eez_area, ts_area, pa_area, pa_land_area, pa_marine_area, pa_eez_area, pa_ts_area, percentage_pa_cover, percentage_pa_land_cover, percentage_pa_eez_cover, percentage_pa_ts_cover, created_at, updated_at ) SELECT land_area, eez_area, ts_area, COALESCE(pa_land_area,0) + COALESCE(pa_marine_area,0), pa_land_area, pa_marine_area, (COALESCE(pa_land_area,0) + COALESCE(pa_marine_area,0)) / (land_area + COALESCE(eez_area, 0) + COALESCE(ts_area,0))*100, COALESCE(pa_land_area,0) / land_area * 100, CASE WHEN eez_area = 0 THEN ELSE COALESCE(pa_eez_area,0) / eez_area * 100 END, CASE WHEN ts_area = 0 THEN ELSE COALESCE(pa_ts_area,0) / ts_area * 100 END FROM ( SELECT id, ST_Area(ST_Transform(land_pas_geom,954009)) pa_land_area, ST_Area(ST_Transform(marine_pas_geom,954009)) pa_marine_area, ST_Area(ST_Transform(land_geom,954009)) land_area, ST_Area(ST_Transform(eez_geom,954009)) eez_area, ST_Area(ST_Transform(ts_geom,954009)) ts_Area FROM countries ) areas Republic of Korea
Managing WCMC Information
Miguel Torres, Data Manager, UNEP-WCMC