Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geojsonsf::geojson_sf add NA_character_ in "input" field of "crs" which make the object unusable by sf package #83

Closed
etiennekintzler opened this issue Jun 6, 2020 · 5 comments

Comments

@etiennekintzler
Copy link

etiennekintzler commented Jun 6, 2020

I am using:

  • geojsonsf version 1.3.3
  • sf version 0.8-1
  • R version 3.6.3 (2020-02-29)
  • os Ubuntu 18.04.4 LTS.

Below is a minimal example:

geojson <- '{ "type" : "Point", "coordinates" : [0, 0] }'
sf_obj <- geojsonsf::geojson_sf(geojson) 
sf::st_is_valid(sf_obj)

yields the following error :

Error in CPL_geos_is_valid(x[i], as.logical(NA_on_exception)) : 
  Not compatible with requested type: [type=character; target=integer].

Digging down and comparing the dput with a functional one (from sf::read_sf) showed that the issue is that the call to _geojsonsf_rcpp_read_sf_file add two fields "input" and "wkt" to the "crs" attributes in the "geometry" with values NA_character_ while (according to what I understood from the error) it should be NA_integer_.

Replacing NA_character_ with NA_integer_ solve the issue:

attr(sf_obj$geometry, "crs")$input <- NA_integer_
sf::st_is_valid(sf_obj) # OK now

The error also vanish when importing with default crs option such as sf_obj <- geojsonsf::geojson_sf(geojson, crs=4326) since no fields "input" and "wkt" are created in crs attributes (and then no inappropriate NA_character_ values).

@dcooley
Copy link
Collaborator

dcooley commented Jun 7, 2020

Thanks for reporting this. However, there's a couple of things going on here, notably with the update to sf from v0.9, where the crs object is changing

Pre-0.9 versions of sf used crs (coordinate reference system) objects represented as lists with two components, epsg (possibly set as NA) and proj4string:

now, with sf >= 0.9, crs objects are lists with two components, input and wkt:


So I'm updating geojsonsf to align with sf v0.9, where I think have I have this issue fixed.

Could you you do me a favour and test the latest dev version of geojsonsf using your current sf 0.8-1?

remotes::install_github("SymbolixAU/geojsonsf")

And tell me if you still get this error?

@etiennekintzler
Copy link
Author

etiennekintzler commented Jun 7, 2020

I just tried the exact same code and I now get the following error :

Error: C stack usage  7970148 is too close to the limit

As you mentioned using a sf version over 0.9 solves the problem.

@dcooley dcooley closed this as completed Jun 16, 2020
@etiennekintzler
Copy link
Author

etiennekintzler commented Jun 16, 2020

For you information the C stack usage error persists even after installing the last version d845e12 (If I use sf 0.8-1 of course)

@dcooley
Copy link
Collaborator

dcooley commented Jun 19, 2020

I'm adding an onAttach message to warn about the conflict between versions - https://github.com/SymbolixAU/geojsonsf/blob/master/R/onAttach.R

@etiennekintzler
Copy link
Author

Ok but why not make the package handle both version of sf ? Does it incurs more work than just fixing the attributes types in crs ?

Also the C stack usage error persists on the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants