Tengo un shapefile de ESRI (desde aquí: http://pubs.usgs.gov/ds/425/). Estoy buscando usar Python para buscar información del archivo de formas (material superficial en este caso) en una latitud/longitud determinada.¿Cómo usar Python para buscar información en latitud/longitud específica en un archivo shape de ESRI?
¿Cuál es la mejor manera de resolver este problema?
Gracias.
solución final:
#!/usr/bin/python
from osgeo import ogr, osr
dataset = ogr.Open('./USGS_DS_425_SHAPES/Surficial_materials.shp')
layer = dataset.GetLayerByIndex(0)
layer.ResetReading()
# Location for New Orleans: 29.98 N, -90.25 E
point = ogr.CreateGeometryFromWkt("POINT(-90.25 29.98)")
# Transform the point into the specified coordinate system from WGS84
spatialRef = osr.SpatialReference()
spatialRef.ImportFromEPSG(4326)
coordTransform = osr.CoordinateTransformation(
spatialRef, layer.GetSpatialRef())
point.Transform(coordTransform)
for feature in layer:
if feature.GetGeometryRef().Contains(point):
break
for i in range(feature.GetFieldCount()):
print feature.GetField(i)
Si el punto no se encuentra en ninguna de las 'características', entonces las últimas características se tratarán como la coincidencia (y se imprimirán sus campos). Declararía una variable separada 'matched_feature' y la asignaría inmediatamente antes del' break', luego la usaría para el siguiente ciclo en lugar de la variable 'feature' –