Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-generate spatial objects to prevent warnings #393

Closed
agila5 opened this issue Apr 29, 2020 · 6 comments
Closed

Re-generate spatial objects to prevent warnings #393

agila5 opened this issue Apr 29, 2020 · 6 comments

Comments

@agila5
Copy link
Collaborator

agila5 commented Apr 29, 2020

# packages
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(stplanr)

# create sln
sln <- SpatialLinesNetwork(route_network_sf)
summary(sln)
#> Weight attribute field: lengthIGRAPH a0d7ca6 U-W- 52 80 -- 
#> + attr: x (g/n), y (g/n), n (g/n), weight (e/n)
#> Warning in `$.crs`(attr(object, "crs"), "proj4string"): CRS uses proj4string,
#> which is deprecated.
#>       All             geometry      length       
#>  Min.   :0   LINESTRING   :80   Min.   :  13.44  
#>  1st Qu.:0   epsg:4326    : 0   1st Qu.: 114.49  
#>  Median :0   +proj=long...: 0   Median : 205.68  
#>  Mean   :0                      Mean   : 353.03  
#>  3rd Qu.:0                      3rd Qu.: 373.74  
#>  Max.   :0                      Max.   :2660.27

Created on 2020-04-29 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.3 (2020-02-29)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Italian_Italy.1252          
#>  ctype    Italian_Italy.1252          
#>  tz       Europe/Berlin               
#>  date     2020-04-29                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version    date       lib source        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)
#>  backports     1.1.5      2019-10-02 [1] CRAN (R 3.6.1)
#>  callr         3.4.2      2020-02-12 [1] CRAN (R 3.6.2)
#>  class         7.3-15     2019-01-01 [2] CRAN (R 3.6.3)
#>  classInt      0.4-2      2019-10-17 [1] CRAN (R 3.6.1)
#>  cli           2.0.2      2020-02-28 [1] CRAN (R 3.6.3)
#>  codetools     0.2-16     2018-12-24 [2] CRAN (R 3.6.3)
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)
#>  curl          4.3        2019-12-02 [1] CRAN (R 3.6.1)
#>  DBI           1.1.0      2019-12-15 [1] CRAN (R 3.6.3)
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)
#>  devtools      2.2.2      2020-02-17 [1] CRAN (R 3.6.2)
#>  digest        0.6.25     2020-02-23 [1] CRAN (R 3.6.3)
#>  dplyr         0.8.5      2020-03-07 [1] CRAN (R 3.6.3)
#>  e1071         1.7-3      2019-11-26 [1] CRAN (R 3.6.1)
#>  ellipsis      0.3.0      2019-09-20 [1] CRAN (R 3.6.1)
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)
#>  fansi         0.4.1      2020-01-08 [1] CRAN (R 3.6.2)
#>  foreign       0.8-75     2020-01-20 [2] CRAN (R 3.6.3)
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.3)
#>  geosphere     1.5-10     2019-05-26 [1] CRAN (R 3.6.1)
#>  glue          1.3.2      2020-03-12 [1] CRAN (R 3.6.3)
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)
#>  htmltools     0.4.0      2019-10-04 [1] CRAN (R 3.6.1)
#>  igraph        1.2.4.2    2019-11-27 [1] CRAN (R 3.6.1)
#>  KernSmooth    2.23-16    2019-10-15 [2] CRAN (R 3.6.3)
#>  knitr         1.28       2020-02-06 [1] CRAN (R 3.6.2)
#>  lattice       0.20-38    2018-11-04 [2] CRAN (R 3.6.3)
#>  lwgeom        0.2-1      2020-01-31 [1] CRAN (R 3.6.2)
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)
#>  maptools      0.9-9      2019-12-01 [1] CRAN (R 3.6.1)
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)
#>  pillar        1.4.3      2019-12-20 [1] CRAN (R 3.6.2)
#>  pkgbuild      1.0.6      2019-10-09 [1] CRAN (R 3.6.1)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 3.6.1)
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)
#>  prettyunits   1.1.1      2020-01-24 [1] CRAN (R 3.6.2)
#>  processx      3.4.2      2020-02-09 [1] CRAN (R 3.6.2)
#>  ps            1.3.2      2020-02-13 [1] CRAN (R 3.6.2)
#>  purrr         0.3.3      2019-10-18 [1] CRAN (R 3.6.1)
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.1)
#>  raster        3.0-12     2020-01-30 [1] CRAN (R 3.6.2)
#>  Rcpp          1.0.4      2020-03-17 [1] CRAN (R 3.6.3)
#>  remotes       2.1.1      2020-02-15 [1] CRAN (R 3.6.2)
#>  rgeos         0.5-2      2019-10-03 [1] CRAN (R 3.6.1)
#>  rlang         0.4.5      2020-03-01 [1] CRAN (R 3.6.3)
#>  rmarkdown     2.1        2020-01-20 [1] CRAN (R 3.6.2)
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)
#>  sf          * 0.9-2      2020-04-14 [1] CRAN (R 3.6.3)
#>  sp            1.4-1      2020-02-28 [1] CRAN (R 3.6.3)
#>  stplanr     * 0.5.2.9000 2020-04-10 [1] local         
#>  stringi       1.4.6      2020-02-17 [1] CRAN (R 3.6.2)
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)
#>  testthat      2.3.2      2020-03-02 [1] CRAN (R 3.6.3)
#>  tibble        2.1.3      2019-06-06 [1] CRAN (R 3.6.1)
#>  tidyselect    1.0.0      2020-01-27 [1] CRAN (R 3.6.2)
#>  units         0.6-5      2019-10-08 [1] CRAN (R 3.6.3)
#>  usethis       1.5.1      2019-07-04 [1] CRAN (R 3.6.2)
#>  vctrs         0.2.4      2020-03-10 [1] CRAN (R 3.6.3)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)
#>  xfun          0.12       2020-01-13 [1] CRAN (R 3.6.2)
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 3.6.2)
#> 
#> [1] C:/Users/Utente/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.3/library
@agila5 agila5 changed the title Warning in summary() of SpatialLinesNetwork objects Warning in summary() of SpatialLinesNetwork objects Apr 29, 2020
@Robinlovelace
Copy link
Member

Confirmed. I can reproduce this.

@Robinlovelace
Copy link
Member

Definitely should be fixed. Simple work-around demonstrated below FYI:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(stplanr)
st_crs(route_network_sf)
#> 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]]
st_crs(route_network_sf) = NA
sln <- SpatialLinesNetwork(route_network_sf)
st_crs(sln@sl) = 4326
summary(sln)
#> Weight attribute field: lengthIGRAPH 6b05630 U-W- 52 80 -- 
#> + attr: x (g/n), y (g/n), n (g/n), weight (e/n)
#>       All             geometry      length         
#>  Min.   :0   LINESTRING   :80   Min.   :0.0001547  
#>  1st Qu.:0   epsg:4326    : 0   1st Qu.:0.0012721  
#>  Median :0   +proj=long...: 0   Median :0.0024601  
#>  Mean   :0                      Mean   :0.0042530  
#>  3rd Qu.:0                      3rd Qu.:0.0046131  
#>  Max.   :0                      Max.   :0.0299576

Created on 2020-04-29 by the reprex package (v0.3.0)

@agila5
Copy link
Collaborator Author

agila5 commented Apr 29, 2020

Aaaaah, so it's just a problem of the route_network_sf 😅 Do you want to update it (i.e. overwrite the CRS attribute)?

@Robinlovelace
Copy link
Member

I'm not sure. I think there may still be an issue with the function. May well be worth updating the objects, also applies to the old sp objects.

@agila5
Copy link
Collaborator Author

agila5 commented Apr 29, 2020

I think that the summary function should be fine since it's simply a wrapper around sf:::summary.sfc and the "true" warning is there:

# packages
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(stplanr)

attributes(st_geometry(route_network_sf)) # warning
#> $class
#> [1] "sfc_LINESTRING" "sfc"           
#> 
#> $precision
#> [1] 0
#> 
#> $bbox
#>      xmin      ymin      xmax      ymax 
#> -1.550964 53.802478 -1.510987 53.830414 
#> 
#> $crs
#> Coordinate Reference System:
#> Warning in `$.crs`(x, "input"): CRS uses proj4string, which is deprecated.

#> Warning in `$.crs`(x, "input"): CRS uses proj4string, which is deprecated.
#>   User input: +proj=longlat +datum=WGS84 +no_defs
#> Warning in `$.crs`(x, "wkt"): CRS uses proj4string, which is deprecated.
#> Warning in `$.crs`(x, "wkt"): CRS uses proj4string, which is deprecated.
#>   wkt:
#> GEOGCS["WGS 84",
#>     DATUM["WGS_1984",
#>         SPHEROID["WGS 84",6378137,298.257223563,
#>             AUTHORITY["EPSG","7030"]],
#>         AUTHORITY["EPSG","6326"]],
#>     PRIMEM["Greenwich",0,
#>         AUTHORITY["EPSG","8901"]],
#>     UNIT["degree",0.0174532925199433,
#>         AUTHORITY["EPSG","9122"]],
#>     AUTHORITY["EPSG","4326"]]
#> 
#> $n_empty
#> [1] 0
sln <- SpatialLinesNetwork(route_network_sf)
summary(sln) 
#> Weight attribute field: lengthIGRAPH 3bccff9 U-W- 52 80 -- 
#> + attr: x (g/n), y (g/n), n (g/n), weight (e/n)
#> Warning in `$.crs`(attr(object, "crs"), "proj4string"): CRS uses proj4string,
#> which is deprecated.
#>       All             geometry      length       
#>  Min.   :0   LINESTRING   :80   Min.   :  13.44  
#>  1st Qu.:0   epsg:4326    : 0   1st Qu.: 114.49  
#>  Median :0   +proj=long...: 0   Median : 205.68  
#>  Mean   :0                      Mean   : 353.03  
#>  3rd Qu.:0                      3rd Qu.: 373.74  
#>  Max.   :0                      Max.   :2660.27

# "fix" the CRS stuff
st_crs(route_network_sf) <- 4326
attributes(st_geometry(route_network_sf))
#> $class
#> [1] "sfc_LINESTRING" "sfc"           
#> 
#> $precision
#> [1] 0
#> 
#> $bbox
#>      xmin      ymin      xmax      ymax 
#> -1.550964 53.802478 -1.510987 53.830414 
#> 
#> $crs
#> Coordinate Reference System:
#>   User input: EPSG:4326 
#>   wkt:
#> GEOGCS["WGS 84",
#>     DATUM["WGS_1984",
#>         SPHEROID["WGS 84",6378137,298.257223563,
#>             AUTHORITY["EPSG","7030"]],
#>         AUTHORITY["EPSG","6326"]],
#>     PRIMEM["Greenwich",0,
#>         AUTHORITY["EPSG","8901"]],
#>     UNIT["degree",0.0174532925199433,
#>         AUTHORITY["EPSG","9122"]],
#>     AUTHORITY["EPSG","4326"]]
#> 
#> $n_empty
#> [1] 0
sln <- SpatialLinesNetwork(route_network_sf)
summary(sln)
#> Weight attribute field: lengthIGRAPH 3bd7cdb U-W- 52 80 -- 
#> + attr: x (g/n), y (g/n), n (g/n), weight (e/n)
#>       All             geometry      length       
#>  Min.   :0   LINESTRING   :80   Min.   :  13.44  
#>  1st Qu.:0   epsg:4326    : 0   1st Qu.: 114.49  
#>  Median :0   +proj=long...: 0   Median : 205.68  
#>  Mean   :0                      Mean   : 353.03  
#>  3rd Qu.:0                      3rd Qu.: 373.74  
#>  Max.   :0                      Max.   :2660.27

Created on 2020-04-29 by the reprex package (v0.3.0)

Though, I have no idea of the consequences of this modification on the other stplanr examples.

@Robinlovelace
Copy link
Member

We can make that change no problem, we had to do similar things in the spData package. I will rename this issue accordingly.

@Robinlovelace Robinlovelace changed the title Warning in summary() of SpatialLinesNetwork objects Re-generate spatial objects to prevent warnings Apr 29, 2020
Robinlovelace added a commit that referenced this issue Aug 25, 2020
Robinlovelace added a commit that referenced this issue Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants