[postgis-users] Split polygons based on polygons' area

Darafei "Komяpa" Praliaskouski me at komzpa.net
Sun Jun 17 03:25:58 PDT 2018


The way I see it, for any kind of polygon:
 - Convert a polygon to a set of points proportional to the area by
ST_GeneratePoints (the more points, the more beautiful it will be, guess
1000 is ok);
 - Decide how many parts you'd like to split into,
(ST_Area(geom)/max_area), let it be K;
 - Take KMeans of the point cloud with K clusters;
 - For each cluster, take a ST_Centroid(ST_Collect(point));
 - Feed these centroids into ST_VoronoiPolygons, that will get you a mask
for each part of polygon;
 - ST_Intersection of original polygon and each cell of Voronoi polygons
will get you a good split of your polygon into K parts.

Will it work for you?

вс, 17 июн. 2018 г. в 13:11, Jibran Khan <jibran at envs.au.dk>:

> Hello everyone,
>
>
>
> I need some help in terms of splitting polygons based on the polygon area.
> I am using PostgreSQL 9.5.12/PostGIS 2.3 on Windows 10 (x64). I have two
> tables i.e. polygon (poly) and points (pts) in my Postgres db. Some of the
> polygons contain points inside them while, some do not (sample scenario
> below):
>
>
>
>
>
> The following query:
>
>
>
> /*Start of query*/
>
> Select
>
>     a.gid poly_id, count(b.geom) pt_cnt,
>
>     st_area(a.geom)::int poly_area
>
> FROM
>
>     poly a
>
> LEFT JOIN
>
>     pts b
>
> ON st_contains(a.geom, b.geom)
>
> GROUP BY a.gid
>
> Order by a.gid;
>
> /*End of query*/
>
>
>
> Returns the area of polygons (from left to right) as 1079, 744, 340
> square-meter, respectively. I need to split these polygons' geometry based
> on the area i.e. if area is above 100 meter-square, then each polygon needs
> to be divided/split into “approximate equal” parts (assuming that majority
> of the polygons are *straightforward* like above). The division does not
> have to be “strictly” equal. Does anyone know or have any idea how this can
> be achieved?
>
>
>
> *Side Notes:*
>
>
>
> ·         I earlier posted this question here at GIS SE
> <https://gis.stackexchange.com/questions/286184/postgis-how-do-i-split-polygon-in-equal-parts-based-on-polygon-area>
>
> ·         Also, came across this
> <https://gis.stackexchange.com/questions/239801/how-can-i-split-a-polygon-into-two-equal-parts-along-a-n-s-axis>
> relevant question but I guess my problem is different
>
>
>
> Any help or idea(s) would be highly appreciated.
>
>
>
> Best,
>
> /Jibran
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20180617/af8fb3e0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 11557 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20180617/af8fb3e0/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 11557 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20180617/af8fb3e0/attachment-0001.png>


More information about the postgis-users mailing list