Error in `st_transform` on Ubuntu (`Error in CPL_transform(x, crs, aoi, pipeline, reverse):`)
RemkoDuursma opened this issue · comments
With a routine st_transform
I get the following error on Ubuntu 18
Error in CPL_transform(x, crs, aoi, pipeline, reverse) :
OGRCreateCoordinateTransformation() returned NULL: PROJ available?
In addition: Warning message:
In CPL_transform(x, crs, aoi, pipeline, reverse) :
GDAL Error 1: No PROJ.4 translation for source SRS, coordinate transformation initialization has failed.
Reproducible example:
data <- structure(list(adres_key = "abcde", centroide = structure(list(
structure(c(5.48118574362483, 51.441978759039), class = c("XY",
"POINT", "sfg"))), class = c("sfc_POINT", "sfc"), precision = 0, bbox = structure(c(xmin = 5.48118574362483,
ymin = 51.441978759039, xmax = 5.48118574362483, ymax = 51.441978759039
), class = "bbox"), crs = structure(list(input = "EPSG:4326",
wkt = "GEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"unknown\"],\n AREA[\"World\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]"), class = "crs"), n_empty = 0L)), row.names = 1L, sf_column = "centroide", agr = structure(c(adres_key = NA_integer_), .Label = c("constant",
"aggregate", "identity"), class = "factor"), class = c("sf",
"data.frame"))
library(sf)
st_transform(data, 28992) # no projections seem to work
The above works fine on my (windows) laptop, but not on our Ubuntu 18 server.
I updated sf
(0.9.4 - the dev version, also tested 0.9.3).
On loading sf
I get : GEOS (3.6.2), GDAL (2.2.3), PROJ (4.9.3).
These are the most recent packages on Ubuntu 18.04.1 (according to apt-get install
).
A very similar issue was posted here (so).
I can replicate on PROJ 5.2.0/GDAL 2.2.4. I got around it by coercing to sp, resetting the input CRS, and coercing back:
data_sp <- as(data, "Spatial")
wkt(data_sp) # did get populated - shouldn't
proj4string(data_sp) # NA
#Warning message:
# In proj4string(data_sp) : CRS object has comment, which is lost in output
proj4string(data_sp) <- CRS("+init=epsg:4326")
st_as_sf(spTransform(data_sp, CRS("+init=epsg:28992")))
#Simple feature collection with 1 feature and 1 field
#CRS: +init=epsg:28992 +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.2369,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +units=m +no_defs
# adres_key geometry
#578 1 abcde POINT (161534.3 383657.9)
So the transformational is findable in (very) old PROJ/GDAL. In current:
> library(sf)
Linking to GEOS 3.8.1, GDAL 3.1.0, PROJ 7.0.1
> st_transform(data, 28992)
Simple feature collection with 1 feature and 1 field
geometry type: POINT
dimension: XY
bbox: xmin: 161534.3 ymin: 383657.9 xmax: 161534.3 ymax: 383657.9
projected CRS: Amersfoort / RD New
adres_key centroide
1 abcde POINT (161534.3 383657.9)
My guess is that Windows is running PROJ 6.3.1 and GDAL 3.0.4.
Yes, this looks like an object written with GDAL vesion that supports WKT2 being read with a GDAL version that does not support WKT2. The solution is to reset (replace) the crs component of data
, e.g. with
st_crs(data) = 4326 # and ignore the subsequent warning
In case this works, please add a link to the solution at the SO page.
Wow, that works! Thanks! We were worried this had to do with various GDAL/PROJ/GEOM library versions...
To be complete, individual geometry columns may need their own crs
reset, e.g. st_crs(data$geopoint) <- 4326
.
Thanks for the quick response - a huge relief.