mapview
mapview copied to clipboard
mapview only show part map for a spatial grid or raster layer
Suposing I have a SpatialPixelsDataFrame or raster object grid with a latlon projection, using the below code, I get only part of the map (a rectangle region smaller than the extent of the grid), is there a parameter controlling the extent ? Thanks. mapview::mapview(grid,layer.name="DEM")
using the example code below, I get only a small rectangle region:
library(mapview)
library(raster)
pal = mapviewPalette("mapviewTopoColors")
kili_data <- system.file("extdata", "kiliNDVI.tif", package = "mapview")
kiliNDVI <- raster::stack(kili_data)
mapview(kiliNDVI[[1]], col.regions = pal(100), at = seq(-0.2, 1, 0.2), legend = TRUE)
sessionInfo() R version 4.0.2 (2020-06-22) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] graphics grDevices utils datasets grid
[6] stats methods base
other attached packages:
[1] spData_0.3.8 sf_0.9-4
[3] mapview_2.10.0 gdalUtilities_1.1.0
[5] rgdal_1.5-12 gstat_2.0-6
[7] maptools_1.0-1 tibble_3.0.1
[9] purrr_0.3.4 dplyr_1.0.0
[11] plyr_1.8.6 magrittr_1.5
[13] raster_3.3-7 sp_1.4-2
[15] scales_1.1.1 ggthemes_4.2.0
[17] ggplot2_3.3.2 reshape2_1.4.4
[19] maps_3.3.0 my_4.0.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 svglite_1.2.3
[3] lattice_0.20-41 FNN_1.1.3
[5] png_0.1-7 class_7.3-17
[7] leaflet.providers_1.9.0 zoo_1.8-8
[9] digest_0.6.25 R6_2.4.1
[11] leafpop_0.0.6 stats4_4.0.2
[13] e1071_1.7-3 pillar_1.4.4
[15] gdtools_0.2.2 rlang_0.4.6
[17] uuid_0.1-4 rstudioapi_0.11
[19] webshot_0.5.2 stringr_1.4.0
[21] foreign_0.8-80 htmlwidgets_1.5.1
[23] munsell_0.5.0 compiler_4.0.2
[25] systemfonts_0.2.3 pkgconfig_2.0.3
[27] base64enc_0.1-3 htmltools_0.5.0
[29] tidyselect_1.1.0 intervals_0.15.2
[31] codetools_0.2-16 spacetime_1.2-3
[33] crayon_1.3.4 withr_2.2.0
[35] jsonlite_1.7.0 satellite_1.0.2
[37] gtable_0.3.0 lifecycle_0.2.0
[39] DBI_1.1.0 units_0.6-7
[41] KernSmooth_2.23-17 stringi_1.4.6
[43] farver_2.0.3 leaflet_2.0.3
[45] brew_1.0-6 ellipsis_0.3.1
[47] xts_0.12-0 generics_0.0.2
[49] vctrs_0.3.1 RColorBrewer_1.1-2
[51] tools_4.0.2 leafem_0.1.6
[53] glue_1.4.1 crosstalk_1.1.0.1
[55] yaml_2.2.1 colorspace_1.4-1
[57] classInt_0.4-3
I don't think I follow. This is what I get:
library(mapview)
library(raster)
#> Loading required package: sp
pal = mapviewPalette("mapviewTopoColors")
kili_data <- system.file("extdata", "kiliNDVI.tif", package = "mapview")
kiliNDVI <- raster::stack(kili_data)
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum unknown in Proj4 definition
mapview(kiliNDVI[[1]], col.regions = pal(100), at = seq(-0.2, 1, 0.2), legend = TRUE)
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in Proj4 definition
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137
#> +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
#> +wktext +no_defs +type=crs
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum World Geodetic System 1984 in Proj4 definition
Created on 2021-09-19 by the reprex package (v2.0.0)
@tim-salabim Thanks for your response. So it is strange that I wonder it is related to my R environment (packages), but I do not know how to debug it. With the same code, I get a narrow rectangle region like a line. See below:
.
Ok, a few options:
- try updating R and the relevant packages
- open the map in the browser instead of RStudio (I assume you're using RStudio)
- in the browser open the console (press F12 or Ctrl+Shift+i) to open the browser console and post a screenshot here of the error messages shown there.