有没有一种方法可以在Python中将多边形形状文件转换为坐标



我正试图通过欧空局哨兵数据中心从哨兵2号下载卫星图像。

我用来获取shapefile层的范围以设置查询的代码不是在lat/long坐标中,而是在奇怪的数字中。我认真地遵循了实用说明,但运气不佳。

任何关于如何解决这个问题的建议或帮助都将不胜感激!

以下是代码:

# Get the shapefile layer's extent
driver = ogr.GetDriverByName("ESRI Shapefile")
ds = driver.Open(shapefile, 0)
lyr = ds.GetLayer()
extent = lyr.GetExtent()
print("Extent of the area of interest (shapefile):n", extent)
# get projection information from the shapefile to reproject the images to
outSpatialRef = lyr.GetSpatialRef().ExportToWkt()
ds = None # close file
print("nSpatial referencing information of the shapefile:n", outSpatialRef)
Extent of the area of interest (shapefile):
(363337.9978, 406749.40699999966, 565178.6085999999, 633117.0013999995)
Spatial referencing information of the shapefile:
PROJCS["OSGB_1936_British_National_Grid",GEOGCS["GCS_OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["false_easting",400000.0],PARAMETER["false_northing",-100000.0],PARAMETER["central_meridian",-2.0],PARAMETER["scale_factor",0.9996012717],PARAMETER["latitude_of_origin",49.0],UNIT["Meter",1.0]]
#   extent of our shapefile in the right format for the Data Hub API.
def bbox(extent):
# Create a Polygon from the extent tuple
box = ogr.Geometry(ogr.wkbLinearRing)
box.AddPoint(extent[0],extent[2])
box.AddPoint(extent[1], extent[2])
box.AddPoint(extent[1], extent[3])
box.AddPoint(extent[0], extent[3])
box.AddPoint(extent[0],extent[2])
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(box)
return poly
# Let's see what it does
print(extent)
print(bbox(extent))
(363337.9978, 406749.40699999966, 565178.6085999999, 633117.0013999995)
POLYGON ((363337.9978 565178.6086 0,406749.407 565178.6086 0,406749.407 633117.001399999 0,363337.9978 633117.001399999 0,363337.9978 565178.6086 0))

事实证明,shapefile所在的坐标系非常关键,它应该位于GCS_WGS_1984中。

相关内容

  • 没有找到相关文章

最新更新