Hello.
I have an R project composed of a number of files. The part of the project I added today is causing much troubles and I can't figure out why.
I am loadingsome raster files with elevation data from volcanoes in Galapagos.
The files are loaded in the Global Environment, but when I try to visualize them I get the same error. (If I try to visualize them in QGIS, they work just fine).
Below is the reprex() containing the code I am using to load only one of the raster files.
My guess is that there is something weird with the range of values in my raster, but it seemed to me this issue appeared in other cases and is kind of a weird one to solve, and that is why I am posting here.
Any help would be appreciated. Thanks
x <- c("anytime",
"chron", "colorspace", "corrplot",
"data.table", "dismo",
"ggmap", "ggplot2", "ggridges", "GISTools", "grid",
"hydroTSM", "hms",
"lattice", "leaflet", "lubridate",
"maptools",
"plyr", "dplyr",
"raster", "RColorBrewer", "readxl", "rgdal", "rgeos", "Rmisc", "RMySQL",
"sf", "sp", "spatstat",
"tcltk", "tmap", "tibble", "tidyr", "tidyverse",
"units",
"vegan", "viridis")
lapply(x, require, character.only = T)
ecu_dem1 = raster("~/Dropbox/iguanas/Conolophus/map/dem/Galap50_0017.ASC")
crs(ecu_dem1) <- CRS('+init=EPSG:4326')
ecu_dem1
#> class : RasterLayer
#> dimensions : 800, 800, 640000 (nrow, ncol, ncell)
#> resolution : 50, 50 (x, y)
#> extent : 640000, 680000, 9960000, 1e+07 (xmin, xmax, ymin, ymax)
#> crs : +init=EPSG:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
#> source : /Users/giuliano/Dropbox/iguanas/Conolophus/map/dem/Galap50_0017.asc
#> names : Galap50_0017
#> values : -2147483648, 2147483647 (min, max)
tm_shape(ecu_dem1) +
tm_raster()
#> Warning in sf::st_is_longlat(shp2): bounding box has potentially an invalid
#> value range for longlat data
#> Warning in sf::st_is_longlat(shp): bounding box has potentially an invalid value
#> range for longlat data
#> Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto), : Viewport has zero dimension(s)
Created on 2020-06-30 by the reprex package (v0.3.0)
Hi @GiulianoColosimo, the crs(ecu_dem1) <- CRS('+init=EPSG:4326') line of code is the source of your problems.
EPSG of 4326 represents WGS84 - a geographic coordinate reference system. This CRS has units in degrees (from -180 to 180, and from -90 to 90). Your object, on the other hand, has extent with values such as 640000 or 680000. It suggests some projected CRS...
Thanks @Nowosad,
That makes perfect sense. I will check more in detail what is going on and post back once I found a solution.
Thanks again.
Most helpful comment
Hi @GiulianoColosimo, the
crs(ecu_dem1) <- CRS('+init=EPSG:4326')line of code is the source of your problems.EPSG of 4326 represents WGS84 - a geographic coordinate reference system. This CRS has units in degrees (from -180 to 180, and from -90 to 90). Your object, on the other hand, has extent with values such as 640000 or 680000. It suggests some projected CRS...