我如何使用 pyproj 模块从路径中获取文件并自动更改它?
该文件还包括多行数据。它可能需要在所有坐标上运行一个循环并改变它们?
我已根据您的建议将此代码添加到问题中。
import os,shutil
import json
from pyproj import Proj,transform
#Create Desktop Folder
path= os.path.expanduser('~/Desktop/NAD83_to_WGS84')
path2=os.path.expanduser(path+'/EPSG_4326.json')
#Any file path for original 2263 file
original_2263= "C:\path\EPSG_2263.json"
#Creates new folder
def newpath(path_input):
if not os.path.exists(path_input):
os.makedirs(path)
#copies original 2263 into new folder.
def oldintonew():
config=shutil.copy(original_2263,path)
#Makes a second copy
def secondtime():
config=shutil.copy(original_2263,path2)
p_web=Proj(init='EPSG:4326')
with open (path2) as src:
fc_in=json.load(src)
# Define dictionary representation of output feature collection
fc_out = {'features': [],
'type': 'FeatureCollection'}
# Iterate through each feature of the feature collection
for feature in fc_in['features']:
feature_out = feature.copy()
new_coords = []
# Project/transform coordinate pairs of each ring
# (iteration required in case geometry type is MultiPolygon, or
there are holes)
for ring in feature['geometry']['coordinates']:
x2, y2 = p_web(*zip(*ring))
new_coords.append(zip(x2, y2))
# Append transformed coordinates to output feature
feature_out['geometry']['coordinates'] = new_coords
# Append feature to output featureCollection
fc_out['features'].append(feature_out)
print(fc_out)
newpath(path)
oldintonew()
secondtime()
现在我收到一条错误消息“TypeError:zip() argument after* must be an iterable, not float”