I am using the sf
R package to work with a shapefile (with a species distribution).
> sp #this is the shapefile
returns:
Simple feature collection with 1 feature and 1 field
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -11539950 ymin: 4933183 xmax: 11985800 ymax: 8012809
epsg (SRID): NA
proj4string: +proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs
scntfcN geometry
3096 Myodes rutilus MULTIPOLYGON (((5070195 797...
These are the shapefile crs and plot:
> crs(sp) #show the original crs
[1] "+proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs"
> plot(sp) #plot the original shapefile
I want to reproject the shapefile from the Mollweide projection to the WGS84 geographic crs:
> sp_reproj <- st_transform(sp, 4326) #reproject the shapefile
> crs(sp_reproj)
returns:
[1] "+proj=longlat +datum=WGS84 +no_defs"
but when I try to plot it, I get this error:
> plot(sp_reproj)
Error in CPL_geos_is_empty(st_geometry(x)) :
Evaluation error: IllegalArgumentException: point array must contain 0 or 1 elements.
Furthermore, if I write the shapefile
> st_write(sp_reproj, "Reprojection.shp")
and open it with QGIS, I have this:
Strangely, the holes (lakes) seems to have been filled.
Further notes: 1) the original sp shapefile seems to be valid and not empty
> st_is_valid(sp)
[1] TRUE
> st_is_empty(sp)
[1] FALSE
2) My final aim is not just to plot the reprojected shapefile, but to intersect it with a raster. However, I get the same error as when plotting, so the problem should be in the shapefile not in the operation.
3) Actually, the sp
shapefile come from a bigger shapefile with thousand of sf features. This one is the only one that gives me that error.
4) Here the original and reprojected shapefiles
Why I get this error? And why the reprojection fill the holes in the original shapefile?