I have a dataframe as below:
df = pd.DataFrame(
{
'epsg': [4326, 4326, 4326, 4203, 7844],
'latitude': [-34.58, -22.78, -33.45, -33.60, -30.48],
'longitude': [122.31, 120.2, 118.55, 140.77, 115.88]})
Here is the function to transform the lat/long if it is not based on 4326:
def transfform_lat_long(inproj:int, outproj:int, x1, y1):
proj = pyproj.Transformer.from_crs(inproj, outproj, always_xy=True)
x2, y2 = proj.transform(x1, y1)
return outproj, x2, y2
I try to apply the function over the data frame so that its lat/long/epsg will be updated if the epsg is not 4326
df[['epsg','latitude', 'longitude']] = df.apply(lambda row:
transfform_lat_long(row.epsg, 4326, row.latitude, row.longitude) if row.epsg != 4326)
It produces syntax error. Any help?