简体   繁体   中英

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. 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. Its python based but has all of the fiddly bits worked out along with all of the projection libraries and files. If you have lots of files to fix/modify QGIS also has built in python scripting. Honestly, don't try and reinvent the wheel when it comes to mapping.

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

See Also https://gis.stackexchange.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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