[R-sig-Geo] 3 Questions on CRS change

Pietro Andre Telatin Paschoalino p|etro_te|@to @end|ng |rom hotm@||@com
Tue Jun 15 20:37:07 CEST 2021


1-  I tried to compare the CRS OGC with my raster (stack) and I couldn't:

My raster data are CRU DATA TS 4.04 (EAST ANGLIA)

 rgdal::compare_CRS(CRS("OGC:CRS84"), slot(rasbrick, "crs"))
 Error in CRS("OGC:CRS84") :
 PROJ4 argument-value pairs must begin with +: OGC:CRS84

 I also tried it like this:

 rgdal::compare_CRS(CRS("+OGC:CRS84"), slot(rasbrick, "crs"))
 Error in showSRID(uprojargs, format = "PROJ", multiline = "NO") :
 Can't parse PROJ.4-style parameter string
 +OGC:CRS84

 could you answer me where am I wrong?

When I compare a shapefile with my raster (stack) the function runs normally.

2- using:

cat(wkt(shapebefore), "\n")

cat(wkt(rasbrick), "\n")

I saw that the order of the axis were different, but after the transformation they were the same.

Any problem making shapeafter<- spTransform(shapebefore, crs(rasbrick))

when are the axis different before the transformation?

Ex:

 cat(wkt(shapebefore), "\n")
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["latitude",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["longitude",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]

> cat(wkt(rasbrick), "\n")
GEOGCRS["unknown",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ID["EPSG",6326]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433],
        ID["EPSG",8901]],
    CS[ellipsoidal,2],
        AXIS["longitude",east,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]],
        AXIS["latitude",north,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]]]

The order of the axis (and other parameters) of my new shape (shapeafter) is the same as the raster (rasbrick) after transformation.

3 -  when I use:

centroids = gCentroid(shapebefore, byid=TRUE)

and

centroids = gCentroid(shapeafter, byid=TRUE)

why are the coordinates x and y values equal (and the values are exactly the same)?

(It seems to me that both are longitude=x and latitude=y) but since the order is switched in cat(wkt(), shouldn't it be latitude=x and longitude=y in the shapebefore?

if I use proj4string()
both my shapebefore and my shapeafter are like:

"+proj=longlat +datum=WGS84 +no_defs"

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] spdep_1.1-5    sf_0.9-5       spData_0.3.8   maptools_1.0-1 xlsx_0.6.3     rgeos_0.5-3    raster_3.3-13
[8] rgdal_1.5-10   sp_1.4-2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         compiler_3.6.2     pillar_1.4.4       LearnBayes_2.15.1  class_7.3-15
 [6] tools_3.6.2        boot_1.3-23        nlme_3.1-142       lifecycle_0.2.0    tibble_3.0.1
[11] lattice_0.20-41    pkgconfig_2.0.3    rlang_0.4.7        Matrix_1.2-18      DBI_1.1.0
[16] rstudioapi_0.11    expm_0.999-5       coda_0.19-3        rJava_0.9-12       e1071_1.7-3
[21] dplyr_1.0.0        gtools_3.8.2       generics_0.0.2     xlsxjars_0.6.1     vctrs_0.3.1
[26] classInt_0.4-3     grid_3.6.2         tidyselect_1.1.0   glue_1.4.1         spDataLarge_0.4.1
[31] R6_2.4.1           foreign_0.8-72     gdata_2.18.0       deldir_0.1-28      purrr_0.3.4
[36] magrittr_1.5       gmodels_2.18.1     splines_3.6.2      MASS_7.3-51.4      codetools_0.2-16
[41] ellipsis_0.3.1     units_0.6-7        KernSmooth_2.23-16 crayon_1.3.4

Thanks.

Pietro Andre Telatin Paschoalino
Doutorando em Ci�ncias Econ�micas da Universidade Estadual de Maring� - PCE.

________________________________
De: Roger Bivand <Roger.Bivand using nhh.no>
Enviado: ter�a-feira, 15 de junho de 2021 15:18
Para: Pietro Andre Telatin Paschoalino <Pietro_telato using hotmail.com>
Assunto: Re: Doubt in function compare_CRS

Please do not email me directly. For use questions, please subscribe to
R-sig-geo

https://stat.ethz.ch/mailman/listinfo/R-SIG-Geo

and post there. Your problem cannot be reproduced by me (I do not know
what your raster is) - when you post provide a minimal self-contained
example. Do also provide the output of sessionInfo(), as you may not be
using updated packages.

Roger Bivand


On Tue, 15 Jun 2021, Pietro Andre Telatin Paschoalino wrote:

> Hello Bivand,
>
> How you create the function compare_CRS and it has already exemplified
> several issues for me. I would like to know if you can help me with a
> simple issue
>
> I tried to compare the CRS OGC with my raster (stack) and I couldn't:
>
> rgdal::compare_CRS(CRS("OGC:CRS84"), slot(rasbrick, "crs"))
> Error in CRS("OGC:CRS84") :
> PROJ4 argument-value pairs must begin with +: OGC:CRS84
>
> I also tried it like this:
>
> rgdal::compare_CRS(CRS("+OGC:CRS84"), slot(rasbrick, "crs"))
> Error in showSRID(uprojargs, format = "PROJ", multiline = "NO") :
> Can't parse PROJ.4-style parameter string
> +OGC:CRS84
>
> could you answer me where am I wrong?
>
> When I compare a shapefile with my raster (stack) the function runs normally, for example:
>
> compare_CRS(slot(shape1, "proj4string"), slot(rasbrick, "crs"))
>                      strict                   equivalent equivalent_except_axis_order
>                       FALSE                         TRUE                         TRUE
>
> Thank you.
>
> Pietro Andre Telatin Paschoalino
> Doutorando em Ci�ncias Econ�micas da Universidade Estadual de Maring� - PCE.
>
> [https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>    Virus-free. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>

--
Roger Bivand
Emeritus Professor
Department of Economics, Norwegian School of Economics,
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway.
e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list