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

apply_mapshapper_commands not working? #121

Closed
dblodgett-usgs opened this issue Mar 10, 2022 · 3 comments
Closed

apply_mapshapper_commands not working? #121

dblodgett-usgs opened this issue Mar 10, 2022 · 3 comments

Comments

@dblodgett-usgs
Copy link
Contributor

I could work on a solution given a little head start, but maybe this is an easy fix?

nc <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
try(rmapshaper::apply_mapshaper_commands(nc, "-clean"))
#> Registered S3 method overwritten by 'geojsonlint':
#>   method         from 
#>   print.location dplyr
#> Error in context_eval(join(src), private$context, serialize, await) : 
#>   Error in V8 context: TypeError: Cannot use 'in' operator to search for '324' in c(0.114, 0.061, 0.143, 0.07, 0.153, 0.097, 0.062, 0.091, 0.118, 0.124, 0.114, 0.153, 0.143, 0.109, 0.072, 0.19, 0.053, 0.199, 0.081, 0.063, 0.044, 0.064, 0.086, 0.128, 0.108, 0.17, 0.111, 0.18, 0.104, 0.077, 0.142, 0.059, 0.131, 0.122, 0.08, 0.118, 0.219, 0.118, 0.155, 0.069, 0.066, 0.145, 0.134, 0.1, 0.099, 0.116, 0.201, 0.18, 0.094, 0.134, 0.168, 0.106, 0.168, 0.207, 0.144, 0.094, 0.203, 0.141, 0.07, 0.065, 0.146, 0.142, 0.154, 0.118, 0.078, 0.125, 0.181, 0.143, 0.091, 0.13, 0.103, 0.095, 0.078, 
#> 0.104, 0.098, 0.091, 0.06, 0.131, 0.241, 0.082, 0.12, 0.172, 0.121, 0.163, 0.138, 0.098, 0.167, 0.204, 0.121, 0.051, 0.177, 0.08, 0.195, 0.24, 0.125, 0.225, 0.214, 0.24, 0.042, 0.212)
#>     at Object.internal.patchMissingFields (<anonymous>:1:61210)
#>     at Object.internal.fixInconsistentFields (<anonymous>:1:60718)
#>     at Object.internal.importJSONTable (<anonymous>:1:339272)
#>     at Object.internal.importJSON (<anonymous>:1:349410)
#>     at Object.internal.importContent (<anonymous>:1:349956)
#>     at Object.api.importFile (<anonymous>:1:353685)
#>     at Object.api.importFiles (<anonymous>:1:352298)
#>     at Object.api.runCommand (<anonymous>:1:518510)
#>     at nextCommand (<anonymous>:1:527690)
#>     at <anonymous>:1:528416
try(rmapshaper::apply_mapshaper_commands(nc, "-clean", sys = TRUE))
#> Warning in if (read_write) {: the condition has length > 1 and only the first
#> element will be used
#> Error : Expected string vector of length 1

tmp_file <- tempfile(fileext = ".geojson")
sf::write_sf(nc, tmp_file)  

tmp_file2 <- tempfile(fileext = ".geojson")

system2(rmapshaper::check_sys_mapshaper(), 
        args = c(tmp_file, "-clean", "-o", tmp_file2))
#> mapshaper version 0.5.68 is installed and on your PATH

plot(sf::read_sf(tmp_file2)["AREA"])

Created on 2022-03-09 by the reprex package (v2.0.1)

@ateucher
Copy link
Owner

apply_mapshaper_commands() works only on geojson strings or files, not directly on sf or Spatial* objects. So this works:

nc <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
rmapshaper::apply_mapshaper_commands(geojsonsf::sf_geojson(nc), "-clean", force_FC = TRUE)

It would certainly be possible to make apply_mapshaper_commands a S3 generic and write methods for sf etc objects...

@dblodgett-usgs
Copy link
Contributor Author

Oh interesting. OK. That makes sense. Do you mind if we put that into an example? Not sure if that would cause CRAN check issues or anything.

@ateucher
Copy link
Owner

Sure, that's a great idea. I am in the process of converting most of the internals to using the geojsonsf package in the geojsonsf branch. I can create an example out of this, but if you want to do a PR for it, please do it against that branch. Thanks!

ateucher added a commit that referenced this issue Apr 12, 2022
documentation in apply_mapshaper_commands fixes #121
ateucher added a commit that referenced this issue Apr 4, 2023
* Start experimenting with geojsonsf

* Fix tests

* Fix test

* Remove geo_list methods

* Change sp examples to sf

* Add geojsonsf, move geojsonio to Suggests

* document

* Remove test that just tests mapshaper

* Use rgdal directly to write sp to tempfile (no geojsonio)

* Define and use expect_equivalent_json to test geojson strings

* Fix tests and examples

* Document

* Make sure sf_to_GeoJSON always returns an FC

* No longer need to install Rcpp from source

* Add test helper to ignore df column order

* Clean up scratch folder

* Update DESCRIPTION

* use checkout@v2

* Simpler example

* change all proj -> crs

* Error in clip_erase when non-identical crs

* Methods for json rather than geo_json; also use jsonify::validate_json instead of geojsonlint

* Update min geojsonsf version and add Remotes to DESCRIPTION

* Don't support POSIXlt

* set test encoding

* remove last geojson method

* silence rgdal CRS warnings; remove geojsonio refs

* document

* Update NEWS

* namespace methods::slot

* test encoding with sf and sp

* Suppress crs assignment warning

* Add test for #91

* Temporarily use geojsonsf branch with encoding fix

* update encoding test for names and values

* Use PR for geojsonsf remote (windows encoding)

* Actions: Use ubuntu-gis-unstable ppa

* Tweaks to GH Actions

* Update CI

* Remove docker-based CI workflow

* CI: don't install spatial sysreqs since installing binaries from rspm

* Udpate imports versions, remove remote from geojsonsf

* Try new minimal CI workflow

* Use v2 actions

* Add old linux to test old v8

* Update gitignore

* CI: Change old Ubuntu from 16.04 to 18.04

* Edit R-CMD-check badge, render README

* documentation in apply_mapshaper_commands fixes #121

* Simplify cmd arg construction by setting NULL defaults

* Use ... to pass common args to apply_mapshaper_commands

* Add quiet parameter. Closes #125

* Add global sys_mem option

* document

* Use ... in clip & erase for common args

* documentation

* Add node mapshaper to CI

* typo

* Remove usages of rgdal and rgeos. Closes #129

* render readme and document

* Update GH actions

* Tweak news, build readme

* sp -> sf

---------

Co-authored-by: David Blodgett <[email protected]>
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