1

I am working with GeoPandas and a Point GeoDataFrame. I have data points in WGS84 (EPSG=4326) that are located in New Zealand. I am trying to project them to a local UTM, but I cannot get the geometry of the GeoDataFrame to update with the new UTM coordinates.

Here is an example GeoDataFrame:

import geopandas as gpd
from pyproj import CRS
long = [172.083916, 172.086549, 172.093403]
lat = [-43.594391, -43.594758, -43.595249]
gdf_pt = gpd.GeoDataFrame(geometry=gpd.points_from_xy(long, lat))
gdf_pt.crs = 4326
display(gdf_pt)
print(gdf_pt.crs)

enter image description here

Failed Attempt #1 to project to EPSG=2193

myproject = gdf_pt.copy()
myproject.crs = 2193
print(myproject.crs)
display(myproject)

enter image description here

Failed Attempt #2

myproject['geometry'] = myproject['geometry'].to_crs(epsg=2193)
display(myproject)

enter image description here

I also tried it with EPSG=32759, another suitable NZ UTM... same issue

What am I doing wrong?

3

By setting the crs attribute to the new CRS (2193), you are assigning a CRS definition (you are setting the metadata), however the coordinates remain unchanged so the CRS is now incorrect (you have not changed the data to match the assigned CRS). For more info, see the Managing Projections: Reprojecting docs.

You need to reproject the coordinates using the GeoDataFrame.to_crs method.

myproject = gdf_pt.to_crs(2193)
print(myproject)
print(myproject.crs)

Output:

                          geometry
0  POINT (1526055.119 5172768.014)
1  POINT (1526268.100 5172729.595)
2  POINT (1526821.938 5172681.124)
epsg:2193
1
  • That's so obvious and makes sense, thanks. I don't understand why myproject['geometry'] = myproject['geometry'].to_crs(epsg=2193) doesn't work?
    – a11
    Jul 18 '20 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.