It seems that pygeos incorrectly reports that 'has_z' is false in case the first z-coordinate is NaN. This leads to the z-dimension getting culled in shapely/geopandas.
Traced this bug after getting funky results in geopandas.
geopandas/geopandas#1888
import numpy as np
import pygeos
import shapely.wkb
coords1 = [
(1, 2, 3),
(1, 1, np.NaN),
]
coords2 = [
(1, 1, np.NaN),
(1, 2, 3),
]
for coords in [coords1, coords2]:
geom1 = pygeos.creation.linestrings(coords)
print(pygeos.geometry.get_coordinate_dimension(geom1))
print(pygeos.predicates.has_z(geom1))
print(pygeos.coordinates.get_coordinates(geom1, include_z=True))
geom2 = shapely.wkb.loads(pygeos.to_wkb(geom1))
print(np.array(geom2.coords))
print('\n')
Output
3
True
[[ 1. 2. 3.]
[ 1. 1. nan]]
[[ 1. 2. 3.]
[ 1. 1. nan]]
3
False
[[ 1. 1. nan]
[ 1. 2. 3.]]
[[1. 1.]
[1. 2.]]
It seems that pygeos incorrectly reports that 'has_z' is false in case the first z-coordinate is NaN. This leads to the z-dimension getting culled in shapely/geopandas.
Traced this bug after getting funky results in geopandas.
geopandas/geopandas#1888
Output