Make st_make_valid in sf package work (windows)

1.8k views Asked by At

I am currently trying to get the sf::st_make_valid() function work under R 3.3.3 (Windows).

My problem is that the sf package does not build against the liblwgeom library. To install liblwgeom under windows, I tried installing the osgeo4w that according to its installation options lists the liblwgeom library. Still, after installing the liblwgeom through the osgeo4w installer, sf does not recognize the liblwgeom library.

From sf documentation on valid functionality: It is only available if the package was linked against liblwgeom, which is currently not the case for the binary CRAN distributions; see the package source code repository for instructions how to install liblwgeom

Any suggestions?

install.packages("sf")
library(sf)
Linking to GEOS 3.5.0, GDAL 2.1.1, proj.4 4.9.3

If sf recognized the liblwgeom library, it should be indicated when loading the sf package.

Anyone has experience with how to enable st_make_valid functionality in the sf package and how to install liblwgeom on Windows?

2

There are 2 answers

1
Edzer Pebesma On BEST ANSWER

If you have rtools installed, you should now be able to get this by installing package lwgeom from https://github.com/r-spatial/lwgeom/

0
Calum You On

I've been trying to get this working as well. The developer does not currently know what the best approach is to get this working as asked, unfortunately.

A solution that worked for me, mostly, depending on the type of geometries you are trying to use st_make_valid on, is to use st_buffer(x, 0.0). This is described in more detail in this blog post. As far as I can understand, it replaces your geometry with all points zero distance from it, and attempts to resolve things that would make polygons invalid. I used it to deal with self-intersection in polygons.