stplanr icon indicating copy to clipboard operation
stplanr copied to clipboard

geo_buffer throws Error in rep(dist, ...)

Open ambuehll opened this issue 3 years ago • 4 comments

Hi there

first of all, thanks for the great package. I had used it for a long time. Somehow my old script broke recently.

What I wanted: a buffer of width 7500m around a single point. this used to be quite straight-forward. I changed the sp to a SF, but still doesn't help. Now I get: Error in rep(dist, length.out = length(x)) : attempt to replicate an object of type 'closure'

Here is an MWE:

 CBDcoo <- c( -9.150055, 38.725095)
 CBDcoo <- SpatialPoints(matrix( CBDcoo,ncol = 2),proj4string = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
    library(sf)
 CBDcoo <- st_as_sf(CBDcoo)
 center_poly <- stplanr::geo_buffer(CBDcoo,dist=7500)

Any help would be appreciated.

lib_versions
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
       "3.9.1"        "3.2.1"        "7.2.1"         "true"         "true"        "7.2.1" 

R 4.1.2 stplanr 1.0.1 Windows

Thanks, Lukas

ambuehll avatar Aug 28 '22 13:08 ambuehll

Hi @ambuehll, thanks for the report and the reproducible example. I am not sure what is causing your issue but it works fine on my computer:

library(sp)
CBDcoo <- c( -9.150055, 38.725095)
CBDcoo <- SpatialPoints(matrix( CBDcoo,ncol = 2),proj4string = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.0; sf_use_s2() is TRUE
CBDcoo <- st_as_sf(CBDcoo)
center_poly <- stplanr::geo_buffer(CBDcoo,dist=7500)
plot(center_poly)

Created on 2022-08-30 with reprex v2.0.2

Robinlovelace avatar Aug 29 '22 23:08 Robinlovelace

It seems you're using slightly out-dated versions of PROJ etc. I cannot be sure that is the cause but could you try running the code on an environment with more-up-to-date system dependencies?

Robinlovelace avatar Aug 29 '22 23:08 Robinlovelace

Thanks for the quick answer. I tried it out with another windows server (even though with an older PROJ version) and it worked again! Not sure where the problem lies. If I find more, I'll re-post.

ambuehll avatar Aug 30 '22 12:08 ambuehll

Intermediate versions of PROJ seem to be the culprit. If this is the default version installed with the most recent version of sf that is not good and very glad you alerted me to it. In this case, not much I can do atm but wish you good luck!

Robinlovelace avatar Aug 30 '22 13:08 Robinlovelace