mbtyers / riverdist

River Network Distance Computation and Applications
23 stars 1 forks source link

riverdist vulnerable to forthcoming changes in sp and rgdal #16

Closed rsbivand closed 1 year ago

rsbivand commented 4 years ago

Running revdep checks for current rgdal on R-Forge - see:

https://stat.ethz.ch/pipermail/r-sig-geo/2019-November/027801.html

shows the errors in the attached check log, related to use of PROJ&/GDAL3 and required changes to sp and rgdal. If useful find a reference to a docker image in this thread:

https://github.com/r-spatial/discuss/issues/28

Changes will occur quite fast, and packages need to be prepared.

* checking examples ... ERROR
Running examples in ‘riverdist-Ex.R’ failed
The error most likely occurred in:

> ### Name: line2network
> ### Title: Create a River Network Object from a Shapefile
> ### Aliases: line2network
> 
> ### ** Examples
> 
> filepath <- system.file("extdata", package="riverdist")
> 
> Gulk_UTM5 <- line2network(path=filepath, layer="Gulk_UTM5")

 Units: m 
> plot(Gulk_UTM5)
> 
> # # Re-projecting in Alaska Albers Equal Area projection:
> 
> AKalbers <- "+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 
+     +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
>     
> Gulk_AKalbers <- line2network(path=filepath, layer="Gulk_UTM5", reproject=AKalbers)
Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO") :
  Discarded datum North_American_Datum_1983 in CRS definition,
 but +towgs84= values preserved
Warning in .spTransform_Line(input[[i]], to_args = to_args, from_args = from_args,  :
  812 projected point(s) not finite
non finite transformation detected:
           [,1]    [,2] [,3] [,4]
  [1,] 894793.4 6922087  Inf  Inf
  [2,] 894701.3 6922101  Inf  Inf
  [3,] 894598.4 6922159  Inf  Inf
...
rsbivand commented 4 years ago

This is now an error:

* checking examples ... ERROR
Running examples in ‘riverdist-Ex.R’ failed
The error most likely occurred in:

> ### Name: xy2segvert
> ### Title: Convert XY Coordinates to River Locations
> ### Aliases: xy2segvert
> 
> ### ** Examples
> 
> data(Gulk,fakefish)
> head(fakefish)
         x       y seg vert fish.id flight flight.date
1 885976.9 6951164   1  595       8      1  2015-04-01
2 891727.6 6943194   1  399      10      1  2015-04-01
3 893895.8 6940549   1  352      14      1  2015-04-01
4 893894.9 6929195   1  116       7      1  2015-04-01
5 878936.0 6959825   1  806      11      1  2015-04-01
6 889340.7 6948910   1  505       9      1  2015-04-01
> 
> fakefish.riv <- xy2segvert(x=fakefish$x, y=fakefish$y, rivers=Gulk)
> head(fakefish.riv)
  seg vert  snapdist
1   1  595 329.34419
2   1  399  40.27721
3   1  352 402.52259
4   1  116 525.06623
5   1  806 355.32753
6   1  505  11.34949
> 
> plot(x=Gulk, xlim=c(862000,882000), ylim=c(6978000,6993000))
> points(fakefish$x, fakefish$y, pch=16, col=2)
> riverpoints(seg=fakefish.riv$seg, vert=fakefish.riv$vert, rivers=Gulk, pch=15, col=4)
> 
> 
> ## converting a matrix of points stored in long-lat to Alaska Albers Equal Area:
> data(line98, Kenai1)
> head(line98)  # note that coordinates are stored in long-lat, NOT lat-long
          [,1]     [,2]
[1,] -150.6810 60.60532
[2,] -150.6793 60.60723
[3,] -150.6792 60.60760
[4,] -150.6792 60.60799
[5,] -150.6793 60.60838
[6,] -150.6794 60.60874
> 
> library(rgdal)
Loading required package: sp
rgdal: version: 1.5-3, (SVN revision (unknown))
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
 Path to GDAL shared files: /usr/local/share/gdal
 GDAL binary built with GEOS: TRUE 
 Loaded PROJ.4 runtime: Rel. 6.3.0, January 1st, 2020, [PJ_VERSION: 630]
 Path to PROJ.4 shared files: /usr/local/share/proj
 Linking to sp version: 1.3-4 
> line98albers <- project(line98,proj="+proj=aea +lat_1=55 +lat_2=65 
+     +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs 
+     +ellps=GRS80 +towgs84=0,0,0")
proj_create: unrecognized format / unknown name
Error in project(line98, proj = "+proj=aea +lat_1=55 +lat_2=65 \n    +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs \n    +ellps=GRS80 +towgs84=0,0,0") : 
  coordinate operation creation failed: generic error of unknown origin
Execution halted
rsbivand commented 4 years ago

rgdal will be released shortly, please read: https://www.r-spatial.org/r/2020/03/17/wkt.html for more background. Now I see:

* checking examples ... ERROR
Running examples in ‘riverdist-Ex.R’ failed
The error most likely occurred in:

> ### Name: xy2segvert
> ### Title: Convert XY Coordinates to River Locations
> ### Aliases: xy2segvert
> 
> ### ** Examples
> 
> data(Gulk,fakefish)
> head(fakefish)
         x       y seg vert fish.id flight flight.date
1 885976.9 6951164   1  595       8      1  2015-04-01
2 891727.6 6943194   1  399      10      1  2015-04-01
3 893895.8 6940549   1  352      14      1  2015-04-01
4 893894.9 6929195   1  116       7      1  2015-04-01
5 878936.0 6959825   1  806      11      1  2015-04-01
6 889340.7 6948910   1  505       9      1  2015-04-01
> 
> fakefish.riv <- xy2segvert(x=fakefish$x, y=fakefish$y, rivers=Gulk)
> head(fakefish.riv)
  seg vert  snapdist
1   1  595 329.34419
2   1  399  40.27721
3   1  352 402.52259
4   1  116 525.06623
5   1  806 355.32753
6   1  505  11.34949
> 
> plot(x=Gulk, xlim=c(862000,882000), ylim=c(6978000,6993000))
> points(fakefish$x, fakefish$y, pch=16, col=2)
> riverpoints(seg=fakefish.riv$seg, vert=fakefish.riv$vert, rivers=Gulk, pch=15, col=4)
> 
> 
> ## converting a matrix of points stored in long-lat to Alaska Albers Equal Area:
> data(line98, Kenai1)
> head(line98)  # note that coordinates are stored in long-lat, NOT lat-long
          [,1]     [,2]
[1,] -150.6810 60.60532
[2,] -150.6793 60.60723
[3,] -150.6792 60.60760
[4,] -150.6792 60.60799
[5,] -150.6793 60.60838
[6,] -150.6794 60.60874
> 
> library(rgdal)
Loading required package: sp
rgdal: version: 1.5-6, (SVN revision 950M)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
 Path to GDAL shared files: /usr/local/share/gdal
 GDAL binary built with GEOS: TRUE 
 Loaded PROJ.4 runtime: Rel. 7.0.0, March 1st, 2020, [PJ_VERSION: 700]
 Path to PROJ.4 shared files: /home/rsb/.local/share/proj:/usr/local/share/proj:/usr/local/share/proj
 PROJ CDN enabled: FALSE 
 Linking to sp version: 1.4-1 
> line98albers <- project(line98,proj="+proj=aea +lat_1=55 +lat_2=65 
+     +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs 
+     +ellps=GRS80 +towgs84=0,0,0")
proj_create: unrecognized format / unknown name
Error in project(line98, proj = "+proj=aea +lat_1=55 +lat_2=65 \n    +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs \n    +ellps=GRS80 +towgs84=0,0,0") : 
  coordinate operation creation failed: generic error of unknown origin
Execution halted
rsbivand commented 4 years ago

Remove the +towgs84=0,0,0 in line 49, man/xy2segvert.Rd. It is redundant, and with recent PROJ and GDAL makes them think that your string is a coordinate operation, not a CRS. With this revision your package does not generate errors, just a note.

rsbivand commented 4 years ago

Can confirm that with:

line98albers <- project(line98,proj=paste0("+proj=aea +lat_1=55 +lat_2=65", 
    " +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs")) 

the package passes CMD check.