Mar*_*erc 5 python geospatial osgeo epsg fiona
使用fiona和使用Python处理坐标系时osgeo,似乎有很多方法可以通过导入/导出不同的crs格式来定义坐标系,例如:
FIONA:
from fiona.crs import from_epsg,from_string,to_string
# Import crs from different formats:
wgs = from_epsg(4326)
wgs = from_string("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ")
# Export crs as proj4 string
wgs_proj4_string = to_string(wgs)
Run Code Online (Sandbox Code Playgroud)
OSGEO:
from osgeo import osr
srs = osr.SpatialReference()
srs.ImportFromESRI(['GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'])
srs.ImportFromProj4("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
srs.ImportFromEPSG(4326)
#the import options are very rich
# Export to different formats
srs.ExportToProj4()
srs.ExportToWkt()
srs.ExportToXML()
#... many export options!
Run Code Online (Sandbox Code Playgroud)
但是,我注意到,这两个库都允许通过其EPSG代码轻松定义crs,但是它们都缺少逆函数(将crs导出为ESPG代码)。
我最接近EPSG代码的方式是:
srs.AutoIdentifyEPSG()
epsg = srs.GetAuthorityCode(None)
Run Code Online (Sandbox Code Playgroud)
但是它似乎并不那么可靠,而且其他提议的解决方案似乎也包括大量的调整或至少与Web服务相关。
问题:
有人可以向我展示一种简单,直接的方式将CRS导出为python中的EPSG代码吗?像是to_epsg()在里Fiona还是ExportToEPSG()在里osgeo?
有人可以解释一下整个互联网上EPSG出口可能性如此不足的理论背景,特别是与EPSG代码易于导入相比。对于没有高级地理空间专业知识的人来说,使坐标系易于识别和使用不是EPSG代码的全部目的吗?它不应该像CRS的ID一样使用并因此易于检索吗?
可以尝试 pyproj CRS:https://pyproj4.github.io/pyproj/stable/examples.html#converting-crs-to-a- Different-format
from pyproj import CRS
from fiona.crs import to_string, from_epsg
fiona_crs = from_epsg(28356)
proj4_crs = CRS.from_proj4(to_string(fiona_crs))
srid = proj4_crs.to_epsg()
Run Code Online (Sandbox Code Playgroud)
尽管由于某种原因这不适用于 EPSG 4326,但不幸的是(to_epsg 在这种情况下返回 None),不知道为什么。
| 归档时间: |
|
| 查看次数: |
563 次 |
| 最近记录: |