0

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
Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
E. Case
  • 67
  • 1
  • 2
  • 11
  • 1
    is pyGeos installed? this seems relevant: https://geopandas.org/en/stable/getting_started/install.html?highlight=z#using-the-optional-pygeos-dependency – Michael Delgado Jul 14 '22 at 23:57
  • pygeos is installed and that does seem relevant! I'll play around with it. thanks. – E. Case Jul 16 '22 at 17:05
  • 1
    this fixed the problem. To unset pygeos, follow these instructions, using the variable/value "USE_PYGEOS=0" https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-and-linux to se – E. Case Jul 18 '22 at 16:12

1 Answers1

0

Using EPSG=4326 code will sustain the z value. eg:dataframe = dataframe.to_crs(epsg=4326)

Manasa
  • 1