I can't use the gDistance function of rgeos without a R crash even when I used the example script:

pt1 = readWKT("POINT(0.5 0.5)")
pt2 = readWKT("POINT(2 2)")

 *** caught segfault ***
address (nil), cause 'unknown'

 1: .Call("rgeos_distance", .RGEOS_HANDLE, spgeom1, spgeom2,byid, PACKAGE = "rgeos")
 2: RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance")
 3: gDistance(pt1, pt2, T)

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"

rgeos version: 0.3-19, (SVN revision 524) GEOS runtime version: 3.5.0-CAPI-1.9.0 r0 Linking to sp version: 1.2-3

Anyone have an idea ?

Edit: sessionInfo() gives

R version 3.3.1 (2016-06-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Scientific Linux release 6.6 (Carbon)

I just tested gBuffer and it does not work as well

pt1 = readWKT("POINT(0.5 0.5)")

 *** caught segfault ***
address (nil), cause 'unknown'

 1: .Call("rgeos_buffer", .RGEOS_HANDLE, spgeom, byid, id, width,     quadsegs, capStyle, joinStyle, mitreLimit, PACKAGE = "rgeos")
 2: gBuffer(pt1)

Edit2 : I did some additional tests : the problem occurs whatever the rgeos version I use. When I use geos version <3.4.2 gDistance produces this error:

GeometryComponentFilter.cpp:35: virtual void    geos::geom::GeometryComponentFilter::filter_ro(const geos::geom::Geometry*): Assertion `0' failed. Abandon

while gBuffer(pt1) works ! As rcs wrote, this error has been reported (and seems unsolved) stat.ethz.ch/pipermail/r-sig-geo/2015-February/022311.html

For version >3.5.0 neither gDistance nor gBuffer work but no error mess is outputted (only the segfault, see above)

Edit 3: I tried to go through the C-code of rgeos and I noticed that the segfault appears in this function:

GEOSGeom rgeos_xy2Pt(SEXP env, double x, double y)


s = GEOSCoordSeq_create_r(GEOShandle, (unsigned int) 1, (unsigned int) 2);

return an empty pointer that causes the segfault in

GEOSCoordSeq_setX_r(GEOShandle, s, 0, x)
  • Works for me and the only difference is R 3.2.3 and my "GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921". Could you also add your operating system? (Mine's Linux Mint/Ubuntu Trusty)
    – Spacedman
    Aug 30, 2016 at 10:41
  • @user3507085 please add the output of sessionInfo() to your question; it works also an my system (Ubuntu 16.04/R 3.3.1/rgeos version: 0.3-19, (SVN revision 524)/GEOS runtime version: 3.5.0-CAPI-1.9.0 r4084)
    – rcs
    Aug 30, 2016 at 10:57
  • By the way do you know what does mean the r4084 of CAPI ? Aug 30, 2016 at 11:45

1 Answer 1


No problem on Fedora 24 with gcc 6.1.1, GEOS 3.5.0 installed from source.

If you believe what you wrote about the location of the problem, r525 protects s, testing against NULL (I hope). Install rgeos after checking the source out from R-Forge.

r# are SVN revisions (obvious for all pre-gits), and refer to discrete revisions to the source repository - they are not OS-specific.

The OP needs to ensure that rgeos is really linking to the GEOS used for installation, I suspect multiple binary GEOS installs on the LD PATH.

Report back only on R-sig-geo, if the OP deigns to post.

Main take-away, RHEL/CENTOS 6 is EOL, especially if you install dependencies binary.

  • Indeed the problem came from different version of geos on my system (one was used for installation and the other one for loading of rgeos) . Thx Sep 1, 2016 at 8:44
  • Seems like there may be different issues related to a) old geos version, and b) rgeos and sp using different version of geos. Had the 'geometryComponent Assert failure' error using geos 3.3.2, gcc 4.4.7. Upgraded to geos 3.6.1, got anonymous segfault. re-compiled 'sp' package, it works now. (Centos 6.9)
    – Ott Toomet
    Apr 23, 2017 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.