-
Notifications
You must be signed in to change notification settings - Fork 12
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
Error with rmapshaper::ms_clip #175
Comments
Interesting, thanks for reporting @jldupouey. Are you able to share the files you are trying to clip? |
The large one is over 25MB, the upper limit for my GitHub repository. Sending larger files seems to be painful. |
Could you put it in a dropbox/google drive folder? |
Here it is: https://filesender.renater.fr/?s=download&token=540cfb37-ebe1-46c8-936e-99b0f72383c5 and my script:
|
Hi @jldupouey this runs ok for me. How much memory does your machine have? I ran it allocating only 16GB and it completed in about 55s; I wonder if you might be overallocating memory if you don't have enough free (i.e., < 30GB, or another process is using a lot)? library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(geojsonsf)
library(rmapshaper)
check_sys_mapshaper()
#> mapshaper version 0.6.102 is installed and on your PATH
#> mapshaper-xl
#> "/opt/homebrew/bin/mapshaper-xl"
MySfLayer <- st_read("~/Downloads/MyLayers/MySfLayer.gpkg")
MySfClippingLayer <- st_read("~/Downloads/MyLayers/MySfClippingLayer.gpkg")
MySfLayerWGS <- st_transform(MySfLayer, crs = 4326)
MySfClippingLayerWGS <- st_transform(MySfClippingLayer, crs = 4326)
tictoc::tic()
ClipSf <- ms_clip(
MySfLayerWGS,
MySfClippingLayerWGS,
sys = TRUE,
sys_mem = 16
)
tictoc::toc()
#> 56.772 sec elapsed Created on 2025-02-27 with reprex v2.1.1 |
Thanks for the help. I have reinstalled everything (R, Node, mapshaper, R libraries ...). I still can't run the ms_clip command. I have 60 GB of memory. I have tested with different values of sys-mem, without any success. I have no other jobs running and there is plenty of free memory available while running ms_clip. It seems that the problem comes from the R side (rmapshaper/R memory management/rmapshaper-sf interactions...?), as the following command works perfectly: shell("mapshaper MyLayer.shp -clip MyClippingLayer.shp -o Clip.shp") One solution, of course, is to run mapshaper's shell commands. But rmapshaper was a very nice interface, which among other things avoided the burden of reading and writing external files. |
I agree it doesn't seem like the problem is with the mapshaper node library, something is happening in rmapshaper. Unfortunately since I can't reproduce it I don't know what the issue is. I can see if I can reproduce it on a Windows machine over the weekend |
I am trying to clip a (rather large) sf layer using another (small) sf layer using rmaspshaper::ms_clip:
ms_clip(MySfLayer,MySfClippingLayer,sys=TRUE,sys_mem=30)
Despite using the system mapshaper library (option sys=TRUE) and a large memory allocation (option sys_mem=30), the process is very long (hours...).
The latest version of mapshaper seems to be installed correctly:
I have the latest versions of R and rmapshaper installed.
When I do the same clipping directly, using mapshaper installed on the same Windows system, the operation is fast. It seems that rmapshaper is not using the system mapshaper library. Or maybe there is something sf does in ms_clip that is long?
I tried converting the layers to GeoJSON first. It seems to go further, and to use the system library, but now I get an error:
I am not sure if this is a bug, but I do not understand the origin of the problem.
The text was updated successfully, but these errors were encountered: