【发布时间】:2021-06-22 11:15:26
【问题描述】:
我正在尝试使用模块 pyproj 编写一个 python 函数,它将基于两个因素进行坐标转换 - 文件名的结尾和 2 行的名称。
例如:if self.file_crs == 'IG' 如果文件结尾是 IG 代表爱尔兰网格
与
for idx,el in enumerate(row):
if keys[idx].capitalize() in ['Easting', 'Northing']:
如果这两列分别称为Easting 和Northing
然后运行
inProj = Proj(init='epsg:29903') # Irish Grid
outProj = Proj(init='epsg:4326') # WGS84
x1, y1 = row[1], row[2] # easting, northing
x2, y2 = transform(inProj, outProj, x1, y1)
row[1], row[2] = y2, x2
我怎样才能将这些组合起来看起来像:
if self.file_crs == 'IG' and keys[idx].capitalize() in ['Easting', 'Northing']:
inProj = Proj(init='epsg:29903') # Irish Grid
outProj = Proj(init='epsg:4326') # WGS84
x1, y1 = row[1], row[2] # easting, northing
x2, y2 = transform(inProj, outProj, x1, y1)
row[1], row[2] = y2, x2
我需要能够事先引用 idx,以便在我的“if”语句中识别它
编辑
keys 是正在解析的 csv 中的行名。
if line_count == 0:
keys = row
行如下
| Name | Easting | Northing | Time |
|---|---|---|---|
| Test1 | 169973 | 77712 | 01/01/2020 09:51:03 AM |
【问题讨论】:
-
keys和row是什么? -
@quamrana 抱歉,请参阅已编辑的问题!
-
您的意思是
keys是列名,row是一次一行吗?你能举个例子吗? -
@quamrana 完全正确!是的,我已经包含了一个行的例子
-
首先我会说你应该检查
line_count == 0时的列名,如果它们不是你所期望的则抛出异常。这将消除其中一种复杂性。
标签: python python-3.x if-statement pyproj