# [postgis-users] Sample - Points into Polygons

Thijs van den Berg thijs at sitmo.com
Fri May 25 15:01:19 PDT 2018

```Or associate each point with a grid cell id using scaling and rounding of
coordinates cell_id=int(x/cell_width)+rn_cols*(y/cell_width). If it were a
3x3 tic tac toe grid you'd have 0,1,2,..,8.

Then select distinct points on that grid cell id?

Op 25 mei 2018 23:42 schreef "Darafei "Komяpa" Praliaskouski" <me at komzpa.net
>:

> Hi,
>
>
> First step, by area, calculate expected number of points in polygon.
>
> Then, depending on quality/speed tradeoff,
>
> fast: for each polygon you make ST_GeneratePoints, and for each point take
> 1 closest point using KNN query, then apply DISTINCT to filter duplicates.
>
> with some eyecandy guarantees: take KMeans of all the points in polygon
> with K you calculated. In each cluster, take ST_GeometricMedian. Take point
> from each cluster closest to cluster center.
>
>
>
> сб, 26 мая 2018, 00:26 карыстальнік Vispo Leblanc <vispoleblanc at gmail.com>
> напісаў:
>
>> Hello PostGIS users,
>>
>>
>>
>> I have one table with thousand of polygons and another one with million
>> of points. I would like to select all the points that are within the
>> polygons, BUT I just want a sample of the data. Let me explain.
>>
>>
>>
>> Let’s say I have a polygon of 1,000 square meter with 60 points, ideally
>> I would like to take only 1 points. But if the polygon is 10,000 square
>> meter with 600 points then ideally I would take only 10 points. Also, in a
>> perfect world, I would only select a sample of points that are spread out
>> enough to be representative of the polygons. Let’s take the 10,000 square
>> meters polygon for example, I would only select 10 points that are
>> everywhere in the polygon and not 10 points that are within 10 meters of
>> each other’s.
>>
>>
>>
>> I draw the following diagram to explain:
>>
>>
>> [image: image.png]
>>
>> Please let me know if you have any ideas or functions I can use to solve
>> my problem.
>>
>>
>>
>> Thank you :-)
>>
>> Vispo
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/postgis-users
>
>
> _______________________________________________
> 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/20180526/96a3f180/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 56937 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20180526/96a3f180/attachment.png>
```