Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terra::ext not giving desirable results for raster object #1252

Closed
krishnakeshav opened this issue Aug 4, 2023 · 1 comment
Closed

terra::ext not giving desirable results for raster object #1252

krishnakeshav opened this issue Aug 4, 2023 · 1 comment

Comments

@krishnakeshav
Copy link

krishnakeshav commented Aug 4, 2023

results are terra::ext() in windows os seems incorrect.

> tf <- paste(tempfile(), ".tif", sep = "")
> utils::download.file("https://geohabnet.s3.us-east-2.amazonaws.com/util-rasters/map_grey_background.tif", destfile = tf, method = "auto")
trying URL 'https://geohabnet.s3.us-east-2.amazonaws.com/util-rasters/map_grey_background.tif'
Content type 'image/tiff' length 1091916 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

I am running the above code and using it's result to create raster object -
> terra::ext(terra::rast(tf))
Result in macOS -

SpatExtent : -180, 180, -60, 90 (xmin, xmax, ymin, ymax)

Result in windows -

SpatExtent : 1.2571897007951e+93, 3.54207331254988e+106, -3.98175728485226e+217, 3.87995991987763e+62 (xmin, xmax, ymin, ymax)

The bad result in windows is causing -

> terra::rast(tf)
> terra::crop("some_raster", terra::ext(-115, -75, 5, 32)

[crop] extents do not overlap

MacOS -

packageVersion("terra")
[1] ‘1.7.39’

Win -

> packageVersion("terra")
[1] ‘1.7.39’

I am running latest version of R studio in both OS.

@rhijmans
Copy link
Member

rhijmans commented Aug 23, 2023

That is a download error. On Windows you should use argument mode="wb"

url <- "https://geohabnet.s3.us-east-2.amazonaws.com/util-rasters/map_grey_background.tif"
tf <- file.path(tempdir(), basename(url))

utils::download.file(url, destfile = tf, mode = "wb")
#trying URL 'https://geohabnet.s3.us-east-2.amazonaws.com/util-rasters/map_grey_background.tif'
#Content type 'image/tiff' length 1091916 bytes (1.0 MB)
#downloaded 1.0 MB

rast(tf)
#class       : SpatRaster 
#dimensions  : 1800, 4320, 1  (nrow, ncol, nlyr)
#resolution  : 0.08333333, 0.08333333  (x, y)
#extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
#coord. ref. : lon/lat WGS 84 (EPSG:4326) 
#source      :  map_grey_background.tif 
#name        : map_grey_background 
#min value   :                              2 
#max value   :                              2 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants