python ogr 坐标系
时间: 2023-10-03 14:07:55 浏览: 125
Python的ogr库(开放地理空间库)是用于处理矢量地理数据的库。在ogr库中,坐标系是通过SpatialReference类来表示的。
要设置坐标系,可以使用SpatialReference类的SetWellKnownGeogCS方法,该方法接受一个坐标系的名称作为参数。例如,要设置WGS84坐标系(经纬度坐标系),可以使用以下代码:
```python
import ogr
# 创建一个SpatialReference对象
spatial_ref = ogr.osr.SpatialReference()
# 设置坐标系为WGS84
spatial_ref.SetWellKnownGeogCS("WGS84")
# 打印坐标系名称
print(spatial_ref.GetAttrValue("GEOGCS"))
```
如果你有一个自定义的坐标系,可以使用SetFromUserInput方法来设置它。该方法接受一个代表坐标系的字符串作为参数。例如,要设置UTM投影坐标系,可以使用以下代码:
```python
import ogr
# 创建一个SpatialReference对象
spatial_ref = ogr.osr.SpatialReference()
# 设置坐标系为UTM投影坐标系(Zone 10N)
spatial_ref.SetFromUserInput("EPSG:32610")
# 打印坐标系名称
print(spatial_ref.GetAttrValue("GEOGCS"))
```
以上代码示例中,`GetAttrValue`方法用于获取坐标系的名称。你还可以使用其他方法来获取更多关于坐标系的信息,比如获取投影单位、投影参数等。
阅读全文
相关推荐


















