gpt4 book ai didi

python - 如何使用 python 查找 ESRI shapefile 中特定纬度/经度的信息?

转载 作者:太空狗 更新时间:2023-10-30 00:57:48 25 4
gpt4 key购买 nike

我有一个 ESRI shapefile(来自这里:http://pubs.usgs.gov/ds/425/)。我希望使用 python 在给定的纬度/经度下从形状文件(在本例中为表面 Material )中查找信息。

解决这个问题的最佳方法是什么?

谢谢。

最终解决方案:

#!/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)

最佳答案

检查 Python Shapefile Library

这应该给你几何和不同的信息。

关于python - 如何使用 python 查找 ESRI shapefile 中特定纬度/经度的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4596843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com