[gdal-dev] Best way to test wheter point is contained in Polygon

Jose Gomez-Dans jgomezdans at gmail.com
Mon Sep 22 10:35:08 EDT 2008


Hi,
I have a raster file and a vector file. I want to assign to each pixel in my
raster size a value derived from the vector file (which are polygons). To do
this, I want to test that the centroid of my pixel lies within a given
polygon. In the past, I have done this gdal_rasterize-ing the polygon file,
and going through numpy arrays. It is a bit cumbersome, and the
rasterization is not really needed with OGR. However, it seems that if my
pixel centroid is (x,y), I will need to go through all features in my layer,
extract the geometry and do a Contains() test for my (x,y) point. I can cut
the number of iterations (I guess, not tried) by using a SpatialFilter on my
vector layer, so only one (ish) geometry is returned, so I would only need
to do one Contains test (I do have a _lot_ of polygons in this file)

Is there some other (better) way of doing this? I'm using the python ogr
bindings.

Thanks!
Jose

-- 
Centre for Terrestrial Carbon Dynamics
Department of Geography, University College London
Gower Street, London WC1E 6BT, UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20080922/d10f0ef6/attachment.html


More information about the gdal-dev mailing list