less than 1 minute read

UTM (Universal Transverse Mercator) coordinates

df_raw[['name_thai','coordinates_x','coordinates_y']].head()
name_thai coordinates_x coordinates_y
0 āļŠāļ–āļēāļ™āļĩāļŦāļĄāļ­āļŠāļīāļ• 667955.316838 1.526435e+06
1 āļŠāļ–āļēāļ™āļĩāļŠāļ°āļžāļēāļ™āļ„āļ§āļēāļĒ 667518.538626 1.525461e+06
2 āļŠāļ–āļēāļ™āļĩāļ­āļēāļĢāļĩāļĒāđŒ 666980.056603 1.523898e+06
3 āļŠāļ–āļēāļ™āļĩāļŠāļ™āļēāļĄāđ€āļ›āđ‰āļē 666707.778693 1.523115e+06
4 āļŠāļ–āļēāļ™āļĩāļ­āļ™āļļāđ€āļŠāļēāļ§āļĢāļĩāļĒāđŒāļŠāļąāļĒ 666173.478204 1.522018e+06

Convert a UTM coordinate into latitude and longitude coordinates

!pip install -q django  
from django.contrib.gis.geos import Polygon
from pprint import pprint
coor = (df_raw[['coordinates_x','coordinates_y']]).to_numpy().tolist()
#Polygon first and last coordinate should be identical (linear ring)
coor.append(coor[0])

poly_thai = Polygon(coor, srid=32647)
poly_gps = poly_thai.transform(4326, clone=True) #4326
#pprint(poly_gps.coords)
df_lat_long = pd.DataFrame(poly_gps[0], columns=['longitude','latitude'])
df_lat_long.head()
longitude latitude
0 100.553787 13.802568
1 100.549689 13.793794
2 100.544616 13.779691
3 100.542052 13.772630
4 100.537046 13.762744

Merge latitude and longitude columns

df_station = df_raw.merge(df_lat_long, left_index=True, right_index=True)
df_station[['name_thai','coordinates_x','coordinates_y','longitude','latitude']].head()
name_thai coordinates_x coordinates_y longitude latitude
0 āļŠāļ–āļēāļ™āļĩāļŦāļĄāļ­āļŠāļīāļ• 667955.316838 1.526435e+06 100.553787 13.802568
1 āļŠāļ–āļēāļ™āļĩāļŠāļ°āļžāļēāļ™āļ„āļ§āļēāļĒ 667518.538626 1.525461e+06 100.549689 13.793794
2 āļŠāļ–āļēāļ™āļĩāļ­āļēāļĢāļĩāļĒāđŒ 666980.056603 1.523898e+06 100.544616 13.779691
3 āļŠāļ–āļēāļ™āļĩāļŠāļ™āļēāļĄāđ€āļ›āđ‰āļē 666707.778693 1.523115e+06 100.542052 13.772630
4 āļŠāļ–āļēāļ™āļĩāļ­āļ™āļļāđ€āļŠāļēāļ§āļĢāļĩāļĒāđŒāļŠāļąāļĒ 666173.478204 1.522018e+06 100.537046 13.762744