<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal>David,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>If you need to generate random points from a polygon:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Use ST_GeneratePoints: <a href="https://postgis.net/docs/en/ST_GeneratePoints.html">https://postgis.net/docs/en/ST_GeneratePoints.html</a><o:p></o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><a href="https://postgis.net/docs/en/ST_Buffer.html">https://postgis.net/docs/en/ST_Buffer.html</a><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>SELECT ST_GeneratePoints(ST_Buffer(<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> ST_GeomFromText(<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> 'LINESTRING(50 50,150 150,150 50)'<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> ), 0.5, 'endcap=square join=round'), 1000);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> <o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>And then use something like <a href="https://postgis.net/docs/en/ST_Subdivide.html">https://postgis.net/docs/en/ST_Subdivide.html</a> to chop up the polygons.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>To get a linestring out of that (It will be closed), you can take the boundary of any of the above<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><a href="https://postgis.net/docs/ST_Boundary.html">https://postgis.net/docs/ST_Boundary.html</a><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hope that helps,<o:p></o:p></p><p class=MsoNormal>Regina<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b>From:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> <b>On Behalf Of </b>Shaozhong SHI<br><b>Sent:</b> Friday, September 8, 2023 7:56 AM<br><b>To:</b> PostGIS Users Discussion <postgis-users@lists.osgeo.org><br><b>Subject:</b> [postgis-users] generate a geometry column of random point, line and polygon<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Is a simple way to do this?<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Regards,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>David<o:p></o:p></p></div></div></div></div></body></html>