[postgis-users] generate a geometry column of random point, line and polygon
Regina Obe
lr at pcorp.us
Fri Sep 8 07:19:40 PDT 2023
David,
For this are you needing to generate random points from a line or polygon or are you trying to generate random polygons, lines, and points?
If you need to generate random points from a polygon:
Use ST_GeneratePoints: https://postgis.net/docs/en/ST_GeneratePoints.html
Note there is a option seed argument, that will give you the same exact answer if you give it the same seed, but without that the generated points will be different each time.
As I recall, ST_GeneratePoints only works with areals so won’t work with a line, however you can buffer a line very thinly to do the same. Use a flat buffer:
https://postgis.net/docs/en/ST_Buffer.html
SELECT ST_GeneratePoints(ST_Buffer(
ST_GeomFromText(
'LINESTRING(50 50,150 150,150 50)'
), 0.5, 'endcap=square join=round'), 1000);
If you want to generate random polygons, you could use ST_ConcaveHull or ST_AlphaShape around the section of a polygon you did a ST_GeneratePoints on
And then use something like https://postgis.net/docs/en/ST_Subdivide.html to chop up the polygons.
To get a linestring out of that (It will be closed), you can take the boundary of any of the above
https://postgis.net/docs/ST_Boundary.html
Hope that helps,
Regina
From: postgis-users <postgis-users-bounces at lists.osgeo.org> On Behalf Of Shaozhong SHI
Sent: Friday, September 8, 2023 7:56 AM
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
Subject: [postgis-users] generate a geometry column of random point, line and polygon
Is a simple way to do this?
Regards,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20230908/c9d09068/attachment.htm>
More information about the postgis-users
mailing list