[gdal-dev] best method to check points in polygon?

G. Allegri giohappy at gmail.com
Wed May 6 16:19:32 EDT 2009


Hi Mateusz.
At now I do the following:

for g in self._selectionGeometries:
	for i in range(self._centroids.GetGeometryCount()):
		p = self._centroids.GetGeometryRef(i)
			if p.Intersect(p):
			indexes.append(i)

which is not the faster code on the earth! But it's faster then
asserting Contains or Within, at least from my test. How would you use
them to extract points from the two geometries, without iteration?

2009/5/6 Mateusz Loskot <mateusz at loskot.net>:
> G. Allegri wrote:
>>
>> I need to check "points in polygon" over various thousands of points
>> and regional scale polygons. A for loop iteration + intersect() over
>> the points geometries is absolutely inefficient.
>
> What you you need is OGRGeometry::Within or OGRGeometry::Contains,
> not intersect.
>
> Best regards,
> --
> Mateusz Loskot, http://mateusz.loskot.net
>


More information about the gdal-dev mailing list