简体   繁体   English

您如何重新投影shapefile?

[英]How do you reproject a shapefile?

I'm trying to change the projection of my shapefile from "epsg:26741" to "epsg:4326" using python code. 我正在尝试使用python代码将shapefile的投影从“ epsg:26741”更改为“ epsg:4326”。 I have looked up how to do this online and found some code, but when I run the code, it throws an error message. 我已经查找了如何在线执行此操作并找到了一些代码,但是当我运行代码时,它会引发错误消息。 This gets thrown specifically in the code below: 这在下面的代码中特别抛出:

from pyproj import Transformer

x = 5.0

y = 6.0

transformer = Transformer.from_crs("epsg:26741", "epsg:4326")

new_x, new_y = transformer.transform(x, y)

This generates the following error message: 这将生成以下错误消息:

runfile('/Users/isaak/Desktop/GIS_Layer_Programs/TestTransform.py', wdir='/Users/isaak/Desktop/GIS_Layer_Programs')
Traceback (most recent call last):

  File "<ipython-input-108-6daf357ca70c>", line 1, in <module>
    runfile('/Users/isaak/Desktop/GIS_Layer_Programs/TestTransform.py', wdir='/Users/isaak/Desktop/GIS_Layer_Programs')

  File "//anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "//anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/isaak/Desktop/GIS_Layer_Programs/TestTransform.py", line 6, in <module>
    new_x, new_y = transformer.transform(x, y)

  File "//anaconda3/lib/python3.7/pyproj/transformer.py", line 274, in transform

  File "pyproj/_transformer.pyx", line 122, in pyproj._transformer._Transformer._transform

  File "//anaconda3/lib/python3.7/enum.py", line 310, in __call__
    return cls.__new__(cls, value)

  File "//anaconda3/lib/python3.7/enum.py", line 571, in __new__
    raise exc

TypeError: error in TransformDirection._missing_: returned <TransformDirection.FORWARD: 'FORWARD'> instead of None or a valid member

I would take a serious look at QGIS. 我会认真看一下QGIS。 Its python based but has all of the fiddly bits worked out along with all of the projection libraries and files. 它基于python,但具有所有复杂的位以及所有投影库和文件。 If you have lots of files to fix/modify QGIS also has built in python scripting. 如果您有很多文件要修复/修改,则QGIS还内置了python脚本。 Honestly, don't try and reinvent the wheel when it comes to mapping. 老实说,在绘制地图时,请不要尝试重新发明轮子。

https://www.qgis.org/en/site/ https://www.qgis.org/en/site/

See Also https://gis.stackexchange.com/ 另请参见https://gis.stackexchange.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM