Repository navigation
Open
Description
This is a minimal reproducible example that crashes the R session on Windows 64 bits using sp 1.4.1 but also former versions
- Windows 7, R 3.5.1, 32 bits ✔️
- Windows 7, R 3.5.1, 64 bits ❌
- Windows 7, R 3.6.1, 32 bits ✔️
- Windows 7, R 3.6.1, 64 bits ❌
- Windows 7, R 4.0.0, 32 bits ✔️
- Windows 7, R 4.0.0, 64 bits ❌
- Linux, R 3.6.2, 64 bits ✔️
wkt = "PROJCS[\"NAD83 (2011) / Conus Albers\",GEOGCS[\"GCS_NAD_1983_2011\",DATUM[\"D_NAD_1983_2011\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101,AUTHORITY[\"EPSG\",7019]],AUTHORITY[\"EPSG\",1116]],PRIMEM[\"Greenwich\",0.0,AUTHORITY[\"EPSG\",8901]],UNIT[\"Degree\",0.0174532925199433,AUTHORITY[\"EPSG\",9102]],AUTHORITY[\"EPSG\",6318]],PROJECTION[\"Albers\",AUTHORITY[\"Esri\",43007]],PARAMETER[\"False_Easting\",0.0,AUTHORITY[\"Esri\",100001]],PARAMETER[\"False_Northing\",0.0,AUTHORITY[\"Esri\",100002]],PARAMETER[\"Central_Meridian\",-96.0,AUTHORITY[\"Esri\",100010]],PARAMETER[\"Standard_Parallel_1\",29.5,AUTHORITY[\"Esri\",100025]],PARAMETER[\"Standard_Parallel_2\",45.5,AUTHORITY[\"Esri\",100026]],PARAMETER[\"Latitude_Of_Origin\",23.0,AUTHORITY[\"Esri\",100021]],UNIT[\"Meter\",1.0,AUTHORITY[\"EPSG\",9001]]],VERTCS[\"NAVD_1988\",VDATUM[\"North_American_Vertical_Datum_1988\",AUTHORITY[\"EPSG\",5103]],PARAMETER[\"Vertical_Shift\",0.0,AUTHORITY[\"Esri\",100006]],PARAMETER[\"Direction\",1.0,AUTHORITY[\"Esri\",100007]],UNIT[\"Meter\",1.0,AUTHORITY[\"EPSG\",9001]],AUTHORITY[\"EPSG\",5703]]"
proj4 = rgdal::showP4(wkt)
crs = sp::CRS(proj4) # crashThis issue is related to lidR #323. For the context the WKT string was read from a LAS file format 1.4.
The bug is not always reproducible. To reproduce it with certainty I restart my virtual machine and run a fresh R session in Rstudio. If I restart an R session after a crash the code fails nicely as expected.
crs = sp::CRS(proj4)
#> Error in sp::CRS(proj4) : conic lat_1 = -lat_2Metadata
Metadata
Assignees
Labels
No labels
Activity
edzer commentedon Mar 3, 2020
with former versions, do you mean also former versions of
sp? If so, also before 1.4.0? @rsbivandJean-Romain commentedon Mar 3, 2020
Well on my Windows virtual machine my packages are not always up-to-date. In some above mentioned R versions
spwas in version 1.3.x. In R 3.5.1 64 bits it is 1.3.2. In R 3.6.1 64 bits it is 1.4.1rsbivand commentedon Mar 3, 2020
Jean-Romain commentedon Mar 3, 2020
I'm not a windows user. I only have a virtual machine to reproduce some windows specific issues. I'm installing the packages using
install.packageand I'm relying on CRAN binaries. I don't actually know how and wheregdalandprojare installed. Please tell me how I can get these information on Windows.The
rgdalversions were 1.4.7 (on R 3.6.1) and 1.4.8 (on R 3.5.1 and R 4.0.0).No other package are involved. I provided a minimal reproducible example. What do you mean by with proj 6 and gdal 3, your choice of workflow will stop working
rsbivand commentedon Mar 4, 2020
First, if you are a lidR developer, read r-spatial/discuss#28 and the links there to see that your workflows need careful revision to adapt to ongoing changes in sf, sp and rgdal. Then read the output messages on attaching sf or rgdal (
rgdal::rgdal_extSoftVersion()too). They display the running versions of PROJ, GDAL, etc. These may have bundled metadata files (Windows and OSX CRAN binaries do bundle metadata files).Look carefully at:
Can you say which dialect of WKT this is?
On my rgdal, I see:
all of which drop the
VERTCS[]node. It was always dropped in PROJ anyway, I think.I can reproduce the crash on Windows 10, R 3.6.2, sp 1.4-1 and rgdal 1.4-8 (CRAN binaries), which has PROJ 4.9.3 and GDAL 2.2.3, . A work-around is to avoid going back to rgdal in
sp::CRS(proj4, doCheckCRSArgs=FALSE), as the string is by default checked in PROJ. The failure occurs in compiled code in rgdal in RGDAL_checkCRSArgs(), but will take time to debug.To just put the trusted PROJ string into the CRS object, use the work-around. We need active collaboration to find out the dialect of your WKT string, so that our current PROJ >= 6 and GDAL >= 3 workflows do not discard
VERTCS[], which your data really do need.rsbivand commentedon Mar 4, 2020
On Windows 32-bit, I see:
which is what you see sometimes (PROJ error).
and
On Linux, with recent PROJ/GDAL:
rsbivand commentedon Mar 4, 2020
My best guess is that you are feeding a very modern WKT representation into an old version of GDAL/PROJ. Turning off
morphFromESRI=returns an empty string on Win 64-bits predictably. So probably the logic in PROJ (4.9.3) fails if asked to morph from ESRI (the shapefile .prj WKT1 representation) when the WKT isn't 1 but newer. PROJ never returns, so the error is not trapped. PROJ 4.9.3 is not going to be patched, so no point filing a bug there; 7.0.0 was released 1 March. I'll turn all the morph*ESRI to FALSE in rgdal, but lidR and others needs to check WKT strings very carefully.rsbivand commentedon Mar 4, 2020
Roll-my-own Windows rgdal binary at http://spatial.nhh.no/R/rgdal/rgdal_1.5-6.zip (PROJ 4.9.3, GDAL 2.2.3), source at http://spatial.nhh.no/R/rgdal/rgdal_1.5-6.tar.gz. The CRS will be trashed, but it should stop crashes. Report back, please.
Jean-Romain commentedon Mar 4, 2020
No. Actually I have only few knowledge about projections. I didn't even know there was some dialects of WTK. My rlas package provides the ability to read the raw content of
.lasand.lazfiles used to store laser point clouds. My lidR package provides tools to process such point clouds and it tries to transform the raw CRS read 'as is' by rlas into something that fits with the R spatial ecosystem.In a
lasfile, depending on the format, the CRS is either an EPSG code or a WKT string. When it is an EPSG code I'm doingwhen it is a WTK string I'm doing
This is (almost) all the CRS related jobs done by lidR. It belongs in those 2 lines of code. The other parts being only the transfer of the CRS from the input (a point cloud) to the outputs (raster, sp, sf objects).
The
.lasfile format 1.4 (with a WTK string) is still pretty rare but are going to be more represented. This is the second file I actually encounter. In the first one the WKT wasI already read those links (you reported an issue I fixed in lidR r-lidar/lidR#299) but to be honest I hardly understand a third of the problem and I'm lost with all the forthcoming changes ; the current state of the art being already confusing (as I said I'm not enough knowledgeable about CRS)
I tried in R 3.6.1 x64 and it returned
NAwithout crash.rsbivand commentedon Mar 4, 2020
Thanks for checking. I'll be some time before rgdal is released. The problem with the current workflows (after just glancing) is that with LAS 1.4 you will have a WKT representation with VERTCS[], but by converting to PROJ and instantiating an sp::CRS, you lose most of the important information. In principle, using development sf
SetFromUserInputbranch, becoming master soon, you input the WKT. For sp and PROJ >=6, GDAL >= 3, the WKT can be fed through the newSRS_string=argument tosp::CRS(), which is then used in rgdal.Unfortunately, passing both of the WKT strings you've provided to the PROJ command line application
projinfoleads to errors. There seem to be either unmatched square brackets or other issues. Are the raw LAS files available anywhere for download, with a script to read them? It feels as though either here the copies are incomplete, or that the dialect of WKT used by LAS is not for now compatible with PROJ. If the latter, I'll raise this on the PROJ developers list.edzer commentedon Mar 4, 2020
FYI, branch
SetFromUserInputhas just been merged in master, to be released within 2 weeks.Jean-Romain commentedon Mar 4, 2020
The las file is available here. You can read the header of the file in R with
I also checked the file with
lasinfofromLAStoolsa command line software to processlasfiles. It prints the same string so no issue from rlas itself.As a conclusion your advice is to use
crs = sp::CRS(SRS_string = wkt). However it returns NA on my computer (Linux, R 3.6.3, PROJ6, GDAL3, sp 1.4.0, rgdal 1.4.8)To me it is not a big problem:
RasterLayerorSpatialPoints*), thePROJformat is the way and the vertical CS rarely makes sense.LAScompatible with the R spatial ecosystem.rsbivand commentedon Mar 5, 2020
None of these raw strings from LAS files (1.4, WKT specified) seem to render as expected in
projinfo:eliocamp commentedon Mar 24, 2020
I'm having a perhaps related issue. Using
sp::CRS()crashes with strange errors (probably at the C level, but I don't know enough to be sure) but only when knitting!This is running with reprex:
Created on 2020-03-24 by the reprex package (v0.3.0)
But if I try to knit this document
I get.
munmap_chunk(): invalid pointer.Strangely, if I remove the last line ("proj"), then I get a different error:
double free or corruption (out). Another error I get isfree(): invalid pointer. It seems that adding or removing valid R code aroundproj <- sp::CRS("+proj=longlat +datum=WGS84")changes the error slightly, but it always fails.I'm on Ubuntu 64bits and using the latest
sppackage from CRAN (version 1.4-1)Session info
rsbivand commentedon Mar 24, 2020
Jean-Romain commentedon Mar 24, 2020
I believed it was to an update of either
rmarkdownitself or a lib it depends on. But @eliocamp is rightrmarkdownworks well. The fails is somehow related tosporrgdal. You should open a new issue.Jean-Romain commentedon Mar 24, 2020
It affects
roxygenas well.eliocamp commentedon Mar 24, 2020
Here's the result from library(rgdal)
Running with debug didn't shine much light into the issue because when run outside markdown, it all works well.
rsbivand commentedon Mar 24, 2020
eliocamp commentedon Mar 24, 2020
Reinstalling rgdal (with the usual install.packages from CRAN) fixed it!
That was very weird.
rsbivand commentedon Mar 24, 2020
Jean-Romain commentedon Mar 24, 2020
Everything looks good on my side as well. Thank you it was a very annoying trouble.