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

wk_crs_projjson(sf::st_crs(...)) test failure #212

Open
kyleam opened this issue Dec 14, 2023 · 3 comments · May be fixed by #214
Open

wk_crs_projjson(sf::st_crs(...)) test failure #212

kyleam opened this issue Dec 14, 2023 · 3 comments · May be fixed by #214

Comments

@kyleam
Copy link

kyleam commented Dec 14, 2023

On an Ubuntu 20.04-based system, I've hit into a wk test failure:

Error (test-pkg-sf.R:31:3): wk_crs_projjson() works for sf crs objects
Error in `expect_match(wk_crs_projjson(sf::st_crs(4326)), "GeographicCRS")`: is.character(act$val) is not TRUE
Backtrace:
    ▆
 1. └─testthat::expect_match(wk_crs_projjson(sf::st_crs(4326)), "GeographicCRS") at test-pkg-sf.R:31:3
 2.   └─base::stopifnot(is.character(act$val))

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 1655 ]

I verified that I can trigger the same error with a Docker image based on rstudio/r-base:4.3.1-focal.

Dockerfile
FROM rstudio/r-base:4.3.1-focal
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get install -y --no-install-recommends eatmydata && \
    eatmydata apt-get install -y --no-install-recommends locales && \
    echo 'en_US.UTF-8 UTF-8' >>/etc/locale.gen && locale-gen && \
    eatmydata apt-get install -y --no-install-recommends \
      git \
      libgdal-dev \
      libgeos-dev \
      libproj-dev \
      libudunits2-dev \
      sqlite3 \
      && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ARG COMMIT=24be4ac61913cba6a51eb30f1c740aed01e0222c
RUN git clone https://github.com/paleolimbot/wk.git && \
    git -C wk checkout "$COMMIT"
ARG CRAN=https://packagemanager.posit.co/cran/__linux__/focal/2023-12-14
RUN printf 'options(repos = c("CRAN"= "%s"))\n' "$CRAN" >/opt/R/4.3.1/lib/R/etc/Rprofile.site
RUN Rscript -e 'install.packages("remotes")' && \
    Rscript -e 'remotes::install_deps("wk", dependencies = TRUE, upgrade = "always")' && \
    rm -rf /tmp/R*
CMD ["Rscript", "-e", "testthat::test_local('/wk')"]

Here's what I see if I execute the R relevant code from that assertion:

> sf::st_crs(4326)
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]]

> wk::wk_crs_projjson(sf::st_crs(4326))
<CHARSXP: NA>

System library versions:

# apt-cache policy libproj-dev libgdal-dev libgeos-dev
libproj-dev:
  Installed: 6.3.1-1
  Candidate: 6.3.1-1
  Version table:
 *** 6.3.1-1 500
        500 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages
        100 /var/lib/dpkg/status
libgdal-dev:
  Installed: 3.0.4+dfsg-1build3
  Candidate: 3.0.4+dfsg-1build3
  Version table:
 *** 3.0.4+dfsg-1build3 500
        500 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages
        100 /var/lib/dpkg/status
libgeos-dev:
  Installed: 3.8.0-1build1
  Candidate: 3.8.0-1build1
  Version table:
 *** 3.8.0-1build1 500
        500 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages
        100 /var/lib/dpkg/status

Any idea what might be triggering the failure?

Thanks in advance

@anthonynorth
Copy link
Contributor

anthonynorth commented Dec 18, 2023

I think the problem here is GDAL < 3.1.0 and crs$ProjJson = NA. We can patch this with a 1-liner, but unsure if the fix belongs here of in sf though?

wk/R/pkg-sf.R

Line 141 in 030fcce

if (is.null(json)) {

if (is.null(json) || is.na(json[1])) {

A CRS object from the 2004 Docker environment:

sf:::crs_parameters(sf::st_crs(4326))
#> $SemiMajor
#> 6378137 [m]
#> 
#> $SemiMinor
#> 6356752 [m]
#> 
#> $InvFlattening
#> [1] 298.2572
#> 
#> $IsGeographic
#> [1] TRUE
#> 
#> $units_gdal
#> [1] "degree"
#> 
#> $IsVertical
#> [1] FALSE
#> 
#> $WktPretty
#> [1] "GEOGCS[\"WGS 84\",\n    DATUM[\"WGS_1984\",\n        SPHEROID[\"WGS 84\",6378137,298.257223563]],\n    PRIMEM[\"Greenwich\",0],\n    UNIT[\"degree\",0.0174532925199433,\n        AUTHORITY[\"EPSG\",\"9122\"]],\n    AXIS[\"Latitude\",NORTH],\n    AXIS[\"Longitude\",EAST],\n    AUTHORITY[\"EPSG\",\"4326\"]]"
#> 
#> $Wkt
#> [1] "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]"
#> 
#> $Name
#> [1] "WGS 84"
#> 
#> $proj4string
#> [1] "+proj=longlat +datum=WGS84 +no_defs"
#> 
#> $epsg
#> [1] 4326
#> 
#> $yx
#> [1] TRUE
#> 
#> $ProjJson
#> <CHARSXP: NA>
#> 
#> $WKT1_ESRI
#> [1] "GEOGCS[\"GCS_WGS_1984\",\n    DATUM[\"D_WGS_1984\",\n        SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],\n    PRIMEM[\"Greenwich\",0.0],\n    UNIT[\"Degree\",0.0174532925199433]]"
#> 
#> $srid
#> [1] "EPSG:4326"
#> 
#> $axes
#>                 name orientation
#> 1  Geodetic latitude           1
#> 2 Geodetic longitude           3
#> 
#> attr(,"class")
#> [1] "crs_parameters"
attributes(sf::st_crs(4326))
#> $names
#> [1] "input" "wkt"  
#> 
#> $class
#> [1] "crs"
unclass(sf::st_crs(4326))
#> $input
#> [1] "EPSG:4326"
#> 
#> $wkt
#> [1] "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]]"

Created on 2023-12-18 with reprex v2.0.2

@anthonynorth
Copy link
Contributor

@anthonynorth anthonynorth linked a pull request Dec 18, 2023 that will close this issue
@kyleam
Copy link
Author

kyleam commented Dec 18, 2023

@anthonynorth Thanks for the details and for working on a fix!

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

Successfully merging a pull request may close this issue.

2 participants