diff --git a/doc/09_voronoi.md b/doc/09_voronoi.md index c3ec501..1a19103 100644 --- a/doc/09_voronoi.md +++ b/doc/09_voronoi.md @@ -27,9 +27,12 @@ PostGIS wil include this in future versions ([doc for dev branch](http://postgis ```sql WITH a AS ( SELECT - ARRAY[ST_GeomFromText('POINT(2.1744 41.403)'),ST_GeomFromText('POINT(2.1228 41.380)'),ST_GeomFromText('POINT(2.1511 41.374)'),ST_GeomFromText('POINT(2.1528 41.413)'),ST_GeomFromText('POINT(2.165 41.391)'),ST_GeomFromText('POINT(2.1498 41.371)'),ST_GeomFromText('POINT(2.1533 41.368)'),ST_GeomFromText('POINT(2.131386 41.41399)')] AS geomin + ARRAY[ST_GeomFromText('POINT(2.1744 41.403)', 4326),ST_GeomFromText('POINT(2.1228 41.380)', 4326),ST_GeomFromText('POINT(2.1511 41.374)', 4326),ST_GeomFromText('POINT(2.1528 41.413)', 4326),ST_GeomFromText('POINT(2.165 41.391)', 4326),ST_GeomFromText('POINT(2.1498 41.371)', 4326),ST_GeomFromText('POINT(2.1533 41.368)', 4326),ST_GeomFromText('POINT(2.131386 41.41399)', 4326)] AS geomin ) SELECT - CDB_voronoi(geomin, 0.2, 1e-9) as result + st_transform( + (st_dump(CDB_voronoi(geomin, 0.2, 1e-9) + )).geom + , 3857) as the_geom_webmercator FROM a; ``` diff --git a/src/pg/sql/09_voronoi.sql b/src/pg/sql/09_voronoi.sql index 20de189..361525c 100644 --- a/src/pg/sql/09_voronoi.sql +++ b/src/pg/sql/09_voronoi.sql @@ -25,7 +25,7 @@ BEGIN convexhull_1 as ( SELECT ST_ConvexHull(ST_Collect(geomin)) as g, - buffer * |/ st_area(ST_ConvexHull(ST_Collect(geomin))) as r + buffer * |/ (st_area(ST_ConvexHull(ST_Collect(geomin)))/PI()) as r ), clipper as( SELECT @@ -145,15 +145,26 @@ BEGIN SELECT (st_dump(v.g)).geom as g FROM voro_cells v + ), + clipped_voro as( + SELECT + ST_intersection(c.g, v.g) as g + FROM + voro_set v, + clipper c + WHERE + ST_GeometryType(v.g) = 'ST_Polygon' ) SELECT st_collect( - ST_Transform(ST_intersection(c.g, v.g), 4326) + ST_Transform( + ST_ConvexHull(g), + 4326 + ) ) INTO geomout FROM - voro_set v, - clipper c; + clipped_voro; RETURN geomout; END; $$ language plpgsql IMMUTABLE; diff --git a/src/pg/test/expected/09_voronoi_test.out b/src/pg/test/expected/09_voronoi_test.out index 1ccc695..58b9e50 100644 --- a/src/pg/test/expected/09_voronoi_test.out +++ b/src/pg/test/expected/09_voronoi_test.out @@ -2,6 +2,6 @@ SET client_min_messages TO WARNING; \set ECHO none avg_area ---------------------- - 0.000200480682454162 + 0.000178661700690617 (1 row)