Hi!
2010/1/25 Tim Michelsen <[email protected]>
> How can I retrieve the attribute information from a SHP-file for a
> certain coordinate point?
>
> I would like to perform this lookup in pure python (no GIS overhead).
>
> Could someone point me to a starter or documentation with such examples?
>
It's not too clear what you mean by either your spatial query or by "pure
python". Assuming that pure python implies "I'm willing to use some fairly
standard libraries such as OGR" (if this is not the case, then I guess
Sean's answer applies ;-D), and assuming you want to retrieve all the
features within a given (spatial) box:
from osgeo import ogr
g = ogr.Open("myshapefile.shp")
L = g.GetLayer ( 0 )
L.SetSpatialFilterRect ( xmin, ymin, xmax, ymax )
for feat in L:
print feat.DumpReadable() #For example
print feat.GetFieldAsDouble(5) # Choose field #5 in your attribute table
print feat.GetGeometryRef ().ExportToWkt() # To export your geometry to
WKT format
print feat.GetGeometryRef ().ExportToKML() # To export your geometry to
KML format
Hope that helps,
Jose