Converting Latitude And Longitude To Utm Coordinates In Pyspark
I have dataframe contain longitude and latitude coordinates for each point. I want to convert the geographical coordinates for each point to UTM coordinates. I tried to use utm mo
Solution 1:
Something like this,
import pyspark.sql.functions as F
import utm
from pyspark.sql.types import *
utm_udf_x = F.udf(lambda x,y: utm.from_latlon(x,y)[0], FloatType())
utm_udf_y = F.udf(lambda x,y: utm.from_latlon(x,y)[1], FloatType())
df = df.withColumn('UTM_x',utm_udf_x(F.col('lat'), F.col('lon')))
df = df.withColumn('UTM_y',utm_udf_y(F.col('lat'), F.col('lon')))
Although I am not sure why did you write [1]
at the end.
Post a Comment for "Converting Latitude And Longitude To Utm Coordinates In Pyspark"