Sf: Error when trying to reproject with PROJ

Created on 1 May 2020  路  10Comments  路  Source: r-spatial/sf

Context: https://github.com/Robinlovelace/geocompr/issues/531

I was trying to reproduce a figure of the 'Geocomputation with R' book but was unable to. The error mentions CPL_transform.

urb_1970_2030 = spData::urban_agglomerations %>% 
    filter(year %in% c(1970, 1990, 2010, 2030))

tm_shape(spData::world) +
    tm_polygons() +
    tm_shape(urb_1970_2030) +
    tm_symbols(col = "black", border.col = "white", size = "population_millions") +
    tm_facets(by = "year", nrow = 2, free.coords = FALSE)
#> Warning in CPL_transform(x, crs, aoi, pipeline, reverse): GDAL Error 1: No PROJ.
#> 4 translation for source SRS, coordinate transformation initialization has
#> failed.
#> Error in CPL_transform(x, crs, aoi, pipeline, reverse): OGRCreateCoordinateTransformation() returned NULL: PROJ available?

Checking both object's proj4string:

st_crs(world)$proj4string
#> [1] "+proj=longlat +datum=WGS84 +no_defs "

st_crs(urb_1970_2030)$proj4string
#> [1] ""

The same error rises again when trying to reproject urb_1970_2030 to world's CRS:

st_transform(urb_1970_2030, crs = "+proj=longlat +datum=WGS84 +no_defs ")
#> Warning in CPL_transform(x, crs, aoi, pipeline, reverse): GDAL Error 1: No PROJ.
#> 4 translation for source SRS, coordinate transformation initialization has
#> failed.
#> Error in CPL_transform(x, crs, aoi, pipeline, reverse): OGRCreateCoordinateTransformation() returned NULL: PROJ available?

Current versions of GEOS, GDAL and PROJ and operating system info:

library(sf)
#> Warning: package 'sf' was built under R version 3.6.3
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3

Sys.info()
#>           sysname           release           version          nodename 
#>         "Windows"          "10 x64"     "build 18363" "DESKTOP-PCVEI3N" 
#>           machine             login              user    effective_user 
#>          "x86-64"         "Usuario"         "Usuario"         "Usuario"

Most helpful comment

Pretty soon: https://cran.r-project.org/web/checks/check_results_sf.html - and then it takes 1-2 weeks before all windows version are built.

All 10 comments

Interesting, thanks for reporting. I've heard other reports of st_transform() failing on Windows machines, including from my colleague @mem48. Recent commits here I think show support for a newer version of GDAL for Windows but I'm not 100% sure.

Apologies for unsolicited tagging @edzer but am I right in thinking a new version of GDAL is on its way for sf?

This NEWS entry added in https://github.com/r-spatial/sf/commit/9afdfe22a2cb2d909008bfa92627fae62120d134 seems pretty unambiguous so it's less of a question and more of a heads-up:

Windows CRAN binaries use GDAL 3.0.4, PROJ 6.3.1 and GEOS 3.8.0, thanks to Jeroen Ooms' rwinlib work; #1275

@dhersz could you try installing the development version of sf and letting us know if that fixes the issue?

@dhersz what does

st_crs(urb_1970_2030)

give?

urb_1970_2030 crs:

st_crs(urb_1970_2030)
#> Coordinate Reference System:
#>   User input: EPSG:4326 
#>   wkt:
#> GEOGCRS["WGS 84",
#>     DATUM["World Geodetic System 1984",
#>         ELLIPSOID["WGS 84",6378137,298.257223563,
#>             LENGTHUNIT["metre",1]]],
#>     PRIMEM["Greenwich",0,
#>         ANGLEUNIT["degree",0.0174532925199433]],
#>     CS[ellipsoidal,2],
#>         AXIS["geodetic latitude (Lat)",north,
#>             ORDER[1],
#>             ANGLEUNIT["degree",0.0174532925199433]],
#>         AXIS["geodetic longitude (Lon)",east,
#>             ORDER[2],
#>             ANGLEUNIT["degree",0.0174532925199433]],
#>     USAGE[
#>         SCOPE["unknown"],
#>         AREA["World"],
#>         BBOX[-90,-180,90,180]],
#>     ID["EPSG",4326]]

I keep getting an error while trying to install the dev version of sf:

remotes::install_github("r-spatial/sf")
#> Downloading GitHub repo r-spatial/sf@master
#> 
#>          checking for file 'C:\Users\Usuario\AppData\Local\Temp\Rtmpsd96mc\remotes3a303dad354a\r-spatial-sf-508a2d1/DESCRIPTION' ...     checking for file 'C:\Users\Usuario\AppData\Local\Temp\Rtmpsd96mc\remotes3a303dad354a\r-spatial-sf-508a2d1/DESCRIPTION' ...   v  checking for file 'C:\Users\Usuario\AppData\Local\Temp\Rtmpsd96mc\remotes3a303dad354a\r-spatial-sf-508a2d1/DESCRIPTION' (789ms)
#>       -  preparing 'sf': (2.1s)
#>    checking DESCRIPTION meta-information ...     checking DESCRIPTION meta-information ...   v  checking DESCRIPTION meta-information
#> -  cleaning src
#>       -  checking for LF line-endings in source and make files and shell scripts (921ms)
#>       -  checking for empty or unneeded directories
#>       -  building 'sf_0.9-3.tar.gz'
#>   Warning:     Warning: file 'sf/cleanup' did not have execute permissions: corrected
#>      Warning: file 'sf/configure' did not have execute permissions: corrected
#>      
#> 
#> Installing package into 'C:/Users/Usuario/Documents/R/win-library/3.6'
#> (as 'lib' is unspecified)
#> Error: Failed to install 'sf' from GitHub:
#>   (convertido do aviso) installation of package 'C:/Users/Usuario/AppData/Local/Temp/Rtmpsd96mc/file3a3053d55516/sf_0.9-3.tar.gz' had non-zero exit status

Yes, you're feeding a WKT2 crs into an sf built on a GDAL version that doesn't support WKT2. We've seen that earlier in the context of the geocomputation book.

For installing newer sf: where is the error message? Did you post all output? Do you have rtools installed?

Cool, is there any quick fix to it? Is it possible to update the GDAL version used by sf in my computer, or something like it? Sorry if this question is too basic.

Regarding the installation, I posted all the output. I have rtools installed.

reset the crs with

st_crs(urb_1970_2030) = 4326

ignore the warning, and continue.

It worked, thanks!

@dhersz , you can also try using remotes::install_github("nowosad/spDataLarge").

@edzer may I asked when we can expect GDAL3/PROJ6 sf for Windows on CRAN?

Pretty soon: https://cran.r-project.org/web/checks/check_results_sf.html - and then it takes 1-2 weeks before all windows version are built.

Was this page helpful?
0 / 5 - 0 ratings