3
votes

I have a dataframe with earthquake data called eq that has columns listing latitude and longitude. using geopandas I created a point column with the following:

from geopandas import GeoSeries, GeoDataFrame
from shapely.geometry import Point
s = GeoSeries([Point(x,y) for x, y in zip(df['longitude'], df['latitude'])])
eq['geometry'] = s
eq.crs = {'init': 'epsg:4326', 'no_defs': True}
eq

Now I have a geometry column with lat lon coordinates but I want to change the projection to UTM. Can anyone help with the transformation?

1
Is 'epsf:4326' a typo and should be 'epsg:4326'? Please edit your question if so. - help-info.de
@help-info.de Thanks yes. - amwade2

1 Answers

3
votes

Latitude/longitude aren't really a projection, but sort of a default "unprojection". See this page for more details, but it probably means your data uses WGS84 or epsg:4326.

Let's build a dataset and, before we do any reprojection, we'll define the crs as epsg:4326

import geopandas as gpd
import pandas as pd
from shapely.geometry import Point
df = pd.DataFrame({'id': [1, 2, 3], 'population' : [2, 3, 10], 'longitude': [-80.2, -80.11, -81.0], 'latitude': [11.1, 11.1345, 11.2]})
s = gpd.GeoSeries([Point(x,y) for x, y in zip(df['longitude'], df['latitude'])])

geo_df = gpd.GeoDataFrame(df[['id', 'population']], geometry=s)
# Define crs for our geodataframe:
geo_df.crs = {'init': 'epsg:4326'} 

I'm not sure what you mean by "UTM projection". From the wikipedia page I see there are 60 different UTM projections depending on the area of the world. You can find the appropriate epsg code online, but I'll just give you an example with a random epsgcode. This is the one for zone 33N for example

How do you do the reprojection? You can easily get this info from the geopandas docs on projection. It's just one line:

geo_df = geo_df.to_crs({'init': 'epsg:3395'})

and the geometry isn't coded as latitude/longitude anymore:

    id  population  geometry
0   1   2   POINT (-8927823.161620541 1235228.11420853)
1   2   3   POINT (-8917804.407449147 1239116.84994171)
2   3   10  POINT (-9016878.754255159 1246501.097746004)