Let's say I have a table point with ~10.000 rows. Each row contains a POINT(x, y).
I also have a table polygon with POLYGONS(...).
The points in the point table are unequally distributed in space. There are areas with a lot of points, there are areas with little points. I want to draw sample of the table points of let's say 100, that is as much as possible equally distributed in one of the polygons from table polygon.
point
id geom name
1 ... point1
2 ... point2
3 ... ...
4 ... ...
... ... ...
... ... ...
polygon
id geom name
1 ... poly1
2 ... poly2
3 ... ...
4 ... ...
... ... ...
... ... ...
What is the best way to do this with postgres/postgis?
This is a screenshot of the points and the underlying polygons. These are 97300 points. The speed of the query giving me the sample does not really matter, since I only draw this sample once.

ST_ClusterKMeanswith 100 custers -> select the closest point to the cluster centroid per cluster. – geozelot Apr 16 '22 at 10:43