GDAL / Python:如何从SpatialReference获取坐标系名称?


18

在Python中,使用GDAL,我提取了栅格投影作为WKT字符串,如下所示:

wkt = dataset.GetProjection()
# wkt is 'PROJCS["GDA_1994_Transverse_Mercator",GEOGCS["GDA_1994",DATUM["GDA_1994",SPHEROID["GRS_1980",6378137,298.2572221010002],TOWGS84[0,0,0,0,0,0,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["Meter",1]]'

使用WKT字符串,我可以创建一个SpatialReference实例,如下所示:

src = osr.SpatialReference()
src.ImportFromWkt(wkt)

这很容易。我可以src很容易地从诸如UTM区域等中提取投影的几个参数。但是我不知道如何提取类似投影名称的内容,即"GDA_1994_Transverse_Mercator"。这肯定是有可能的,但是就其所有用途而言,Python API文档也可能不存在。

如何提取投影和地理坐标系的名称?

Answers:


46

请参阅OGR Projections教程OGRSpatialReference类。特别是,GetAttrValue方法。

这是一个可行的示例。

from osgeo import gdal,osr
ds=gdal.Open(r'SOMERASTER.TIF')
prj=ds.GetProjection()
print prj

srs=osr.SpatialReference(wkt=prj)
if srs.IsProjected:
    print srs.GetAttrValue('projcs')
print srs.GetAttrValue('geogcs')

对于我的光栅,此打印:

PROJCS["WGS 84 / UTM zone 55N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",147],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32655"]]
'WGS 84 / UTM zone 55N'
'WGS 84'
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.