ENH: Prevent creation of geometries with NaN coordinates
See original GitHub issueIt 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. https://github.com/geopandas/geopandas/issues/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.]]
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
d3 fitSize gives NaN values - Stack Overflow
I want to make my d3 map fit to a svg container created with dynamic width and height attributes. It works so far...
Read more >#2179 (ST_MakeValid support for NaN values.) – PostGIS
Pretend all NaN values are an arbitrary value (0.0) ? Drop all Coordinates with any NaN ordinate value (including Z and M?) Return...
Read more >What the different data filters do? - libpointmatcher
This filter can be applied to remove points which contain a NaN coordinate, thus producing a "clean" dataset. Required descriptors: none. Output descriptor: ......
Read more >Using MATLAB Graphics
To create a text annotation using the text function, you must specify the text and its location in the graph, using x- and...
Read more >gmt — GMT 6.5.0 documentation
Allows users to create a matrix of panels with automatic labeling and ... In case of longitude–latitude plots, this will keep the spacing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d like to make a bold proposal: block
NaN
in geometry creation functions (just skip NaN coordinates, like we do withNone
for polygon/multi geometries)Associated with this, we might create
force_2d
andforce_3d
functions. Theforce_3d
takes an optional argumentz_value
, which cannot be NaN and defaults to0.0
(like with PostGIS: https://postgis.net/docs/ST_Force_3D.html)Using a well-defined NODATA value for Z values seems better than using
NaN
; in the raster they are actually a number that has a NODATA interpretation, as opposed to something that is unrepresentable as a number. The raster dataset should define this NODATA value, so you can just use that, right? In either case, you run the risk of any interpolation applied to Z values unless you handle the NODATA values properly, and using a defined number sidesteps all the issues around GEOS andNaN
.