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

ms_simplify 0.4.1 aborts R session #83

Closed
fabiocs8 opened this issue Nov 26, 2018 · 10 comments · Fixed by #118
Closed

ms_simplify 0.4.1 aborts R session #83

fabiocs8 opened this issue Nov 26, 2018 · 10 comments · Fixed by #118
Labels
Milestone

Comments

@fabiocs8
Copy link

Hi,

When executing the following code, ms_simplify causes R to abort after about 2 minutes running.

library(rgdal)               #1.3-6 version
library (rgeos)             #0.4-2 version
library(rmapshaper)    #0.4.1 version
shp.mun <- 
  readOGR("C:\\br_municipios\\."
          , "BRMUE250GC_SIR"
          , stringsAsFactors=FALSE
          , encoding="UTF-8"
  )
shp2 <- ms_simplify(shp.mun) # the execution of this line causes R 3.5.1 to abort

The map file can be found here https://1drv.ms/f/s!Av16Xvc5Na3Ngr12e_gRbjyZXjyh4g
OBS 1): gSimplify can handle this map, thus I believe that map´s format is ok
OBS 2): I successfully simplified other maps using ms_simplify, so my rmapshaper version is supposedly ok and well installed.

Please let me know if you need additional clarification.

Regards Fabio

@ateucher
Copy link
Owner

Hi Fabio,

Thanks for the report, I can reproduce this and will investigage. Interestingly, this works with sf:

library(sf)
library(rmapshaper)
shp.mun.sf <- read_sf("BRMUE250GC_SIR.shp")
shp2 <- ms_simplify(shp.mun)

@ateucher ateucher added the bug label Nov 27, 2018
@fabiocs8
Copy link
Author

fabiocs8 commented Nov 28, 2018 via email

@ateucher
Copy link
Owner

Yes, an sf object is an entirely different beast than a "Spatial" object from package sp, and there is no tidy method for sf objects.

I recommend checking out the sf package, and plotting sf objects directly with ggplot2 via geom_sf (I'm just guessing that's why you want to fortify).

If you want to stay with sp "Spatial" objects, a work-around is to convert to sf, run it through ms_simplify(), and then back to "Spatial":

library(rgdal)
library(sf)
library(rmapshaper)
library(broom)
shp_sp <- readOGR(".", "BRMUE250GC_SIR", stringsAsFactors = FALSE, encoding = "UTF-8")
shp_sf <- st_as_sf(shp_sp)
shp2_sf <- ms_simplify(shp_sf)
shp2_sp <- as(shp2_sf, "Spatial")
shp_tidy <- tidy(shp2_sp)

I will look at why it is crashing, but this should work in the meantime...

@fabiocs8
Copy link
Author

fabiocs8 commented Nov 28, 2018 via email

@ateucher
Copy link
Owner

My pleasure, thanks again for reporting this.

@fermumen
Copy link

Related perhaps. Also on version 0.4.1 my session aborts when simplifying the NTEM boundaries shape.

See an example here

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

@ateucher
Copy link
Owner

Thanks @fermm92 - it's due to the size of the spatial object and the memory limitations of V8 in which the javascript mapshaper engine is running. I will work on catching these limitations earlier so that it fails a little less dramatically.

You can use the sys = TRUE argument to use the system mapshaper, it worked well for me with this example (and quite quickly too). This does however require install node and the mapshaper module on your system: https://github.com/ateucher/rmapshaper#using-the-system-mapshaper

@fermumen
Copy link

Thanks for your answer @ateucher using sys = TRUE worked great!

@ateucher
Copy link
Owner

Excellent, glad it worked!

@ateucher
Copy link
Owner

This should be fixed by #118

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

Successfully merging a pull request may close this issue.

3 participants