Reputation: 73
I've got a csv of metadata (metadata_df
) for some images I'm trying to process. I extract the geometry in the metadata to make a Point geometry object, then create a geodataframe using this geometry & the original metadata.
df = metadata_df
epsg_code='4979'
geometry = [Point(xyz) for xyz in zip(df['lon'], df['lat'], df['alt'])]
gdf1 = gpd.GeoDataFrame(df, geometry=geometry, crs='EPSG:'+epsg_code)
then convert this geodataframe to a different crs using to_crs
.
gdf2 = gdf1.to_crs("EPSG:4978")
But to_crs
strips the z data from the point geometry. Any ideas how to keep the z data during the 4978 transformation / make to_crs
output a POINT Z instead of a POINT?
print(gdf1.geometry.head())
0 POINT Z (-110.72734 43.71498 4629.18463)
1 POINT Z (-110.72974 43.74431 4625.70121)
2 POINT Z (-110.73011 43.77137 4614.43130)
3 POINT Z (-110.73102 43.80133 4612.92112)
4 POINT Z (-110.73159 43.83043 4598.42577)
Name: geometry, dtype: geometry
print(gdf2.geometry.head())
0 POINT (-1634202.022 -4318557.192)
1 POINT (-1633585.179 -4316381.716)
2 POINT (-1632877.279 -4314426.871)
3 POINT (-1632130.428 -4312246.197)
4 POINT (-1631381.075 -4310136.444)
Name: geometry, dtype: geometry
Version information:
GeoPandas 0.9.0
PyProj 3.3.1
PyGeos 0.12
Upvotes: 1
Views: 1590
Reputation: 1
Using EPSG=4326 code will sustain the z value. eg:dataframe = dataframe.to_crs(epsg=4326)
Upvotes: 0