From 0a26d2be99b97d05abf6391fd42772431b4c4fd3 Mon Sep 17 00:00:00 2001 From: Eduard Popov Date: Mon, 22 May 2017 11:01:31 +1000 Subject: [PATCH] Housenumber and POI calc optimisation (#247) Using NPoints(Centroid) = NPoints, thanks edpop --- layers/housenumber/housenumber_centroid.sql | 8 +++++++- layers/poi/poi_polygon_update.sql | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/layers/housenumber/housenumber_centroid.sql b/layers/housenumber/housenumber_centroid.sql index 20e323c6..2ea3e9df 100644 --- a/layers/housenumber/housenumber_centroid.sql +++ b/layers/housenumber/housenumber_centroid.sql @@ -4,7 +4,13 @@ DROP TRIGGER IF EXISTS trigger_refresh ON housenumber.updates; -- etldoc: osm_housenumber_point -> osm_housenumber_point CREATE OR REPLACE FUNCTION convert_housenumber_point() RETURNS VOID AS $$ BEGIN - UPDATE osm_housenumber_point SET geometry=ST_PointOnSurface(geometry) WHERE ST_GeometryType(geometry) <> 'ST_Point'; + UPDATE osm_housenumber_point + SET geometry = + CASE WHEN ST_NPoints(ST_ConvexHull(geometry))=ST_NPoints(geometry) + THEN ST_Centroid(geometry) + ELSE ST_PointOnSurface(geometry) + END + WHERE ST_GeometryType(geometry) <> 'ST_Point'; END; $$ LANGUAGE plpgsql; diff --git a/layers/poi/poi_polygon_update.sql b/layers/poi/poi_polygon_update.sql index 891ae2ed..7154092e 100644 --- a/layers/poi/poi_polygon_update.sql +++ b/layers/poi/poi_polygon_update.sql @@ -5,7 +5,13 @@ DROP TRIGGER IF EXISTS trigger_refresh ON poi.updates; CREATE OR REPLACE FUNCTION convert_poi_point() RETURNS VOID AS $$ BEGIN - UPDATE osm_poi_polygon SET geometry=ST_PointOnSurface(geometry) WHERE ST_GeometryType(geometry) <> 'ST_Point'; + UPDATE osm_poi_polygon + SET geometry = + CASE WHEN ST_NPoints(ST_ConvexHull(geometry))=ST_NPoints(geometry) + THEN ST_Centroid(geometry) + ELSE ST_PointOnSurface(geometry) + END + WHERE ST_GeometryType(geometry) <> 'ST_Point'; ANALYZE osm_poi_polygon; END; $$ LANGUAGE plpgsql;