I am trying to write a python function using the module pyproj which will do coordinate conversion based on two factors - the ending of the file name and the name of 2 rows.
For example: if self.file_crs == 'IG'
which is if the file ending is IG for Irish Grid
AND
for idx,el in enumerate(row):
if keys[idx].lower() in ['Easting', 'Northing']:
which is if the two columns are called Easting and Northing
THEN RUN
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
How can I combine these to look something like:
if self.file_crs == 'IG' and keys[idx].lower() 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
I need to be able to reference idx beforehand so it is recognised in my 'if' statement
EDIT
keys are the row names in the csv which is being parsed.
if line_count == 0:
keys = row
The rows are as follows
Name | Easting | Northing | Time |
---|---|---|---|
Test1 | 169973 | 77712 | 01/01/2020 09:51:03 AM |
Aucun commentaire:
Enregistrer un commentaire