[R-sig-Geo] Encoding of attributes in SpatVector (terra package)
Tim Elrick
@bo @end|ng |rom e|r|ck@de
Mon Jun 21 03:36:40 CEST 2021
Hi Ben,
Sorry, now as plain text...
Thanks for your response. I guess, that is a Windows encoding problem
then, as I get (below I also included how they differ):
###
identical(mtl.sf$NOM, mtl.spv$NOM)
[1] FALSE
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sf_1.0-0 terra_1.3-4 forcats_0.5.1 stringr_1.4.0
dplyr_1.0.7 purrr_0.3.4 readr_1.4.0
[8] tidyr_1.1.3 tibble_3.1.2 ggplot2_3.3.4 tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] tidyselect_1.1.1 haven_2.4.1 lattice_0.20-44
colorspace_2.0-1 vctrs_0.3.8 generics_0.1.0
[7] utf8_1.2.1 rlang_0.4.11 e1071_1.7-7
pillar_1.6.1 glue_1.4.2 withr_2.4.2
[13] DBI_1.1.1 sp_1.4-5 dbplyr_2.1.1
modelr_0.1.8 readxl_1.3.1 lifecycle_1.0.0
[19] munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0
rvest_1.0.0 raster_3.4-13 codetools_0.2-18
[25] labeling_0.4.2 class_7.3-19 fansi_0.5.0
broom_0.7.7 Rcpp_1.0.6 KernSmooth_2.23-20
[31] scales_1.1.1 backports_1.2.1 classInt_0.4-3
jsonlite_1.7.2 farver_2.1.0 fs_1.5.0
[37] digest_0.6.27 hms_1.1.0 stringi_1.6.2 grid_4.1.0
cli_2.5.0 tools_4.1.0
[43] magrittr_2.0.1 proxy_0.4-26 crayon_1.4.1
pkgconfig_2.0.3 ellipsis_0.3.2 xml2_1.3.2
[49] reprex_2.0.0 lubridate_1.7.10 assertthat_0.2.1 httr_1.4.2
rstudioapi_0.13 R6_2.5.0
[55] units_0.7-2 compiler_4.1.0
###
Here is the difference:
###
> tail(mtl.sf$NOM)
[1] "Montréal-Est" "Anjou"
"Pierrefonds-Roxboro" "Sainte-Anne-de-Bellevue"
[5] "Verdun" "Baie-d'Urfé"
> tail(mtl.spv$NOM)
[1] "Montréal-Est" "Anjou"
"Pierrefonds-Roxboro" "Sainte-Anne-de-Bellevue"
[5] "Verdun" "Baie-d'Urfé"
###
So, basically, vect() seems to have problems to interpret non-ASCII
characters in Windows.
Is there an easy way to fix that, e.g. by setting a parameter or is this
a bug for the Windows edition?
Thanks,
Tim
On 2021-06-15 18:32, Ben Tupper wrote:
Hi,
Alas, HTML mail gets mangled - try setting your email client to send
plan text.
I don't know what the NOM variable contents are supposed to look like,
but I find they are identical. Can you post to the list your evidence
that shows how they differ and what makes one right versus the other
wrong? Also, always add the output of sessionInfo() as shown below.
library(sf)
library(terra)
url <-
"https://data.montreal.ca/dataset/00bd85eb-23aa-4669-8f1b-ba9a000e3dd8/resource/e9b0f927-8f75-458c-8fda-b5da65cc8b73/download/limadmin.geojson"
mtl.sf <- read_sf(url)# convert sf object to SpatVector object
mtl.spv <- vect(mtl.sf)
identical(mtl.sf$NOM, mtl.spv$NOM)
# [1] TRUE
sessionInfo()
# R version 4.0.3 (2020-10-10)
# Platform: x86_64-apple-darwin17.0 (64-bit)
# Running under: macOS Big Sur 10.16
#
# Matrix products: default
# LAPACK:
/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
#
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
#
# other attached packages:
# [1] terra_1.2-10 sf_0.9-8 dplyr_1.0.5
#
# loaded via a namespace (and not attached):
# [1] Rcpp_1.0.6 rstudioapi_0.13 raster_3.4-5
magrittr_2.0.1 units_0.7-1 tidyselect_1.1.1
# [7] lattice_0.20-41 R6_2.5.0 rlang_0.4.11
fansi_0.4.2 blob_1.2.1 tools_4.0.3
# [13] grid_4.0.3 KernSmooth_2.23-17 utf8_1.2.1
cli_2.5.0 e1071_1.7-6 DBI_1.1.1
# [19] ellipsis_0.3.2 class_7.3-17 assertthat_0.2.1
tibble_3.1.1 lifecycle_1.0.0 crayon_1.4.1
# [25] purrr_0.3.4 codetools_0.2-16 vctrs_0.3.8
glue_1.4.2 sp_1.4-5 proxy_0.4-25
# [31] compiler_4.0.3 pillar_1.6.0 generics_0.1.0
classInt_0.4-3 pkgconfig_2.0.3
Cheers,
Ben
On Tue, Jun 15, 2021 at 11:57 AM Tim Elrick <abo using elrick.de> wrote:
>
> Hi all,
>
> Does anyone know how to change encoding for attributes in a SpatVector
> (terra package)?
>
> library(sf) library(terra)
> # importing a geojson file as sf object url <-
>
"https://data.montreal.ca/dataset/00bd85eb-23aa-4669-8f1b-ba9a000e3dd8/resource/e9b0f927-8f75-458c-8fda-b5da65cc8b73/download/limadmin.geojson"
> mtl.sf <- read_sf(url)# convert sf object to SpatVector object mtl.spv
> <- vect(mtl) # while mtl.sf$NOM # displays French letters correctly,
> mtl.spv$NOM # does not anymore Thanks, Tim
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list