Opened 3 years ago
Last modified 3 years ago
#1142 new defect
GeoJSON writer should not write null coordinates
| Reported by: | caspervdw | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 3.11.0 |
| Component: | Default | Version: | main |
| Severity: | Annoyance | Keywords: | |
| Cc: |
Description
The GeoJSON writer writes NaN coordinates to null.
>>> pygeos.to_geojson(pygeos.Geometry("LINESTRING (1 nan, 2 2)"))
'{"type":"LineString","coordinates":[[1.0,null],[2.0,2.0]]}'
The inverse operation however does not work:
>>> pygeos.from_geojson('{"type":"LineString","coordinates":[[1.0,null],[2.0,2.0]]}')
GEOSException: ParseException: Error parsing JSON: '[json.exception.type_error.302] type must be number, but is null'
There is a lot to say about allowing nan coordinates at all, but as they are allowed now and the writer handles them properly, I would expect the reader handles them as well.
Change History (2)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
| Summary: | GeoJSON reader cannot read null coordinates → GeoJSON writer should not write null coordinates |
|---|
Note:
See TracTickets
for help on using tickets.

The issue is not on the reader, but on the writer. A null member in the coordinate array is illegal. https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1 : "A position is an array of numbers"