SymbolixAU / geojsonsf

Conversion between sf and geojson
Other
82 stars 7 forks source link

'z_range' attribute inconsistency #100

Closed coolbutuseless closed 4 months ago

coolbutuseless commented 1 year ago

Great work on the extensive test suite you have included with geojsonsf - really shows how tricky this parsing can be!

There appears to be a small inconsistency on how/when z_range attribute is calculated for MULTIPOINT

In the first example, the first point has XYZ coords, and the second point has XY coords. No z_range attribute is produced.

In the second example, the first point has XY. The second point has XYZ. In this case, a z_range attribute is included.

I'm not certain if this is an actual inconsistency, or something particular to the requirements of sf

library(geojsonsf)

js0 <- '{"type":"MultiPoint","coordinates":[[0.0,0.0,0.0],[1.0,1.0]]}'
sfc0 <- geojson_sfc(js0)
attr(sfc0, 'z_range')
#> NULL

js1 <- '{"type":"MultiPoint","coordinates":[[0.0,0.0],[1.0,1.0,1.0]]}'
sfc1 <- geojson_sfc(js1)
attr(sfc1, 'z_range')
#> zmin zmax 
#>    1    1 
#> attr(,"class")
#> [1] "z_range"

Created on 2023-08-26 with reprex v2.0.2

dcooley commented 1 year ago

thanks - the cause is in {sfheaders} requiring an std::isnan() check - https://github.com/dcooley/sfheaders/issues/100 - I've put a fix on master for z_range, but not m_range yet.

On a side note, both this issue and the {shfeaders} one are number 100 !

dcooley commented 4 months ago

updated sfheaders dependency so this now works:

library(geojsonsf)

js0 <- '{"type":"MultiPoint","coordinates":[[0.0,0.0,0.0],[1.0,1.0]]}'
sfc0 <- geojson_sfc(js0)
attr(sfc0, 'z_range')
# zmin zmax 
# 0    0 
# attr(,"class")
# [1] "z_range"

js1 <- '{"type":"MultiPoint","coordinates":[[0.0,0.0],[1.0,1.0,1.0]]}'
sfc1 <- geojson_sfc(js1)
attr(sfc1, 'z_range')
# zmin zmax 
# 1    1 
# attr(,"class")
# [1] "z_range"