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

Mateusz Loskot mateusz at loskot.net
Wed May 6 17:33:53 EDT 2009


G. Allegri wrote:
> 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):
-------------------------^^^^^^^^^^^^^^^^^

p in same 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.

Intersect is a different predicate (answers different question) than
Contains and Within. I don't understand from the code above what's your
goal. Perhaps "which is faster" is just a wrong question.

> How would you use them to extract points from the two geometries,
> without iteration?

Extract?
They are predicates. Meaning, all these functions give binary answer
(true or false) about relation between two geometries.

See samples here:

http://trac.osgeo.org/gdal/browser/trunk/autotest/ogr/ogr_geos.py

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org


More information about the gdal-dev mailing list