我有一个 ESRI shapefile(来自这里: http: //pubs.usgs.gov/ds/425/)。我希望使用 python 从给定纬度/经度的形状文件(在这种情况下为表面材料)中查找信息。
解决这个问题的最佳方法是什么?
谢谢。
最终解决方案:
#!/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)