Error when working with irregular raster and grid
Closed this issue · 5 comments
I would like to calculate landscape metrics for an irregular raster (land cover/land use) for a country using an irregular 8km x 8km grid (the shape of the country) but I gol the following error:
entropia = sample_lsm(cob_s, gri_8,
level = "landscape", metric = "ent")
Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.list': only regular rasters can be converted to Raster* objects
How can I calculate landscape metrics for irregular shapes?
Manuel
@ManuelSpinola can you share you data with us?
@ManuelSpinola please upload it here or (if you cannot share it privately) email us.
Hi @ManuelSpinola it seems that something is wrong with your input data.
For example, Pixel Size is missing:
library(landscapemetrics)
library(stars)
## Loading required package: abind
## Loading required package: sf
## Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.2
library(sf)
gdal_utils("info", "lc.tif")
## Driver: GTiff/GeoTIFF
## Files: lc.tif
## Size is 502, 632
## Coordinate System is:
## PROJCRS["CR05 / CRTM05",
## BASEGEOGCRS["CR05",
## DATUM["Costa Rica 2005",
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",5365]],
## CONVERSION["Costa Rica TM 2005",
## METHOD["Transverse Mercator",
## ID["EPSG",9807]],
## PARAMETER["Latitude of natural origin",0,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8801]],
## PARAMETER["Longitude of natural origin",-84,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8802]],
## PARAMETER["Scale factor at natural origin",0.9999,
## SCALEUNIT["unity",1],
## ID["EPSG",8805]],
## PARAMETER["False easting",500000,
## LENGTHUNIT["metre",1],
## ID["EPSG",8806]],
## PARAMETER["False northing",0,
## LENGTHUNIT["metre",1],
## ID["EPSG",8807]]],
## CS[Cartesian,2],
## AXIS["northing (N)",north,
## ORDER[1],
## LENGTHUNIT["metre",1]],
## AXIS["easting (E)",east,
## ORDER[2],
## LENGTHUNIT["metre",1]],
## USAGE[
## SCOPE["unknown"],
## AREA["Costa Rica - onshore and offshore east of 86°30'W"],
## BBOX[2.21,-86.5,11.77,-81.43]],
## ID["EPSG",5367]]
## Data axis to CRS axis mapping: 2,1
## Origin = (nan,nan)
## Pixel Size = (nan,nan)
## Metadata:
## AREA_OR_POINT=Area
## Image Structure Metadata:
## INTERLEAVE=BAND
## Corner Coordinates:
## Upper Left ( nan, nan)
## Lower Left ( nan, nan)
## Upper Right ( nan, nan)
## Lower Right ( nan, nan)
## Center ( nan, nan)
## Band 1 Block=502x4 Type=Float32, ColorInterp=Gray
This file cannot be read using the raster package:
cob_s1 = raster::raster("lc.tif")
## Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file.
It can be read by stars, but it still causes some issues:
cob_s = read_stars("lc.tif")
cob_s2 = st_transform(cob_s, crs = 5367)
cob_s3 = st_warp(cob_s2, crs = 5367)
## Error in colrow_from_xy(pts, x, NA_outside = TRUE): colrow_from_xy not supported for curvilinear objects
Therefore, I do not have any direct solutions here... Maybe you can try to obtain a different version of this raster file? Or, if you think that the file is completely correct, maybe you could ask about it on the stars package issue tracker...