[Gdal-dev] How determine if lat\lon point falls within a shapefile
Brian Hamlin
maplabs at light42.com
Sat Feb 23 20:26:32 EST 2008
if its Polygons you are looking at and not MultiPolygons, life will be
a little bit simpler
You can unroll your shapefile in Python and hit detect using any one of
a few classic algorithms
google "point polygon python"
if you have multipolygons, you have to check each one
if you have to transform coordinate systems, you need to do that first
check GDAL autotest for some samples, and a few in the source tree
itself
btw- you are using OGR, not GDAL itself
GDAL is basically for raster data, OGR is geometry
-Brian
On Feb 23, 2008, at 4:51 PM, Jim St.Cyr wrote:
>
> The shapefiles do use the same lat\lon coordinate system. What I've
> been
> struggling with is performing the actual point-in-polygon or
> point-in-bounding-box check. I've found formulas and packages such as
> 'sp'
> for 'R' but have yet to find something that ties it all together.
> Open the
> shapefile and then for each point get a yes or no answer or
> alternatively
> for a multi layer scenario be told which areas within the overall map a
> position falls within. A vendor we work with does it using MapInfo or
> ESRI
> runtimes but I would like to use a python based, OSS solution if
> possible.
>
> Thanks for the reply.
>
> Jim
>
>
> Tom Kazimiers wrote:
>>
>> Jim St.Cyr schrieb:
>>> I have a shapefile and a list of lat\long's that I would like to
>>> process
>>> in
>>> order to determine if they fall within the shapefile.
>>> GDAL-1.5-py2.5 is
>>> loaded on a windows XP machine and is correctly configured. I would
>>> appreciate it if someone could point me to a python script or
>>> appropriate
>>> documentation to get me strted. At this point I can't even determine
>>> which
>>> part of the GDAL package to use....
>>>
>>> Thanks much.
>>>
>>> Jim
>>>
>> Is the data of the shapefile also referenced with lat\long values of
>> the
>> same geographic coordinate system or do you need to translate them?
>> I think you could open the shapefile, get the bounding box stored in
>> the
>> file (maybe you have to go through all the shapes as the stored
>> bounding
>> box in the file must not be correct - at least I do this when loading
>> shapefiles) and then compare it to your value.
>>
>> bye,
>> Tom
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/How-determine-if-lat%5Clon-point-falls-within-a-
> shapefile-tp15618562p15659292.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
More information about the gdal-dev
mailing list