[R-sig-Geo] Error trying to stack two raster bricks with different extension and resolution

JC Arronte j_@rronte @end|ng |rom hotm@||@com
Sat Jul 4 20:54:42 CEST 2020


Dear Ákos,

It worked!!. Thank you very much for your help.

Best regards,

Juan Carlos

________________________________
De: R-sig-Geo <r-sig-geo-bounces using r-project.org> en nombre de Bede-Fazekas Ákos <bfalevlist using gmail.com>
Enviado: viernes, 3 de julio de 2020 19:37
Para: r-sig-geo using r-project.org <r-sig-geo using r-project.org>
Asunto: Re: [R-sig-Geo] Error trying to stack two raster bricks with different extension and resolution

Dear Juan Carlos,

maybe the simplest solution is
1) creating an empty raster at 3 km resolution and LAEA projection,
using the desired extent,
2) then reprojecting both rasters to the projection/resolution/extent of
this empty one using projectRaster(from, to)

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences

2020.07.03. 19:26 keltezéssel, JC Arronte írta:
> Hi All,
>
>
> I�m starting to work with the package raster and although I�ve been looking for solutions, I can�t find the way to solve my problem.
>
>
> I�ve two ncdf files downloaded from Copernicus with near-bottom sea temperature data. They correspond to two different periods of time (1998-2018 & 2019) and they have both different extent and resolution. The files can be downloaded from https://www.dropbox.com/sh/orr567sjdvxjycn/AAB2zEbo5hMwRhm0YEvXY5dma?dl=0
>
>
> I want to stack both files in one raster brick with a final resolution of 3km and a LAEA projection. I�ve tried several approaches but none has worked.
>
>
> Any help will be very appreciated! Thanks in advance.
>
>
> Juan Carlos
>
>
>
> This is the code I have been working with
> -----------------------------------------------------------------------
>
>
> library(ncdf4)
> library(raster)
> library(proj4)
>
> temp_9818 <-brick('temp_9818.nc')
> temp_19 <-brick('temp_2019.nc')
> LAEA <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
>
> temp_9818
> #class      : RasterBrick
> #dimensions : 61, 145, 8845, 252  (nrow, ncol, ncell, nlayers)
> #resolution : 0.08333333, 0.08333333  (x, y)
> #extent     : -11.04167, 1.041666, 40.95833, 46.04167  (xmin, xmax, ymin, ymax)
> #crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
>
> temp_19
> #class      : RasterBrick
> #dimensions : 181, 433, 78373, 12  (nrow, ncol, ncell, nlayers)
> #resolution : 0.02777778, 0.02777778  (x, y)
> #extent     : -11.01389, 1.013889, 40.98611, 46.01389  (xmin, xmax, ymin, ymax)
> #crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
>
> # Different extents
> extent(temp_9818)
> #xmin       : -11.04167
> #xmax       : 1.041666
> #ymin       : 40.95833
> #ymax       : 46.04167
>
> extent(temp_19)
> #xmin       : -11.01389
> #xmax       : 1.013889
> #ymin       : 40.98611
> #ymax       : 46.01389
>
> ##  Projecting 3km & LAEA ---
> temp_9818_project <-projectRaster(temp_9818, crs=LAEA, res=3000, method="bilinear")
> temp_19_project <-projectRaster(temp_19, crs=LAEA, res=3000, method="bilinear")
>
> extent(temp_9818_project)
> #xmin       : 2552554
> #xmax       : 3644554
> #ymin       : 2015246
> #ymax       : 2792246
>
> extent(temp_19_project)
> #xmin       : 2555581
> #xmax       : 3641581
> #ymin       : 2017655
> #ymax       : 2788655
>
>
> ##  Obviously, error!! ----
> temp_9819_final <- stack(temp_9818_project,temp_19_project)
> #Error in compareRaster(x) : different extent
>
> ## Defining new extension for cropping
> newextend <- extent(c(2395000, 3400000, 2281000, 2600000))
>
> temp_9818_project_crop <-crop(temp_9818_project, newextend)
> temp_19_project_crop <-crop(temp_19_project, newextend)
>
> temp_9819_final <- stack(temp_9818_project_crop, temp_19_project_crop) #Error again!!
> #Error in compareRaster(x) : different extent
>
> extent(temp_9818_project_crop)
> #xmin       : 2552554
> #xmax       : 3398554
> #ymin       : 2282246
> #ymax       : 2600246
>
> extent(temp_19_project_crop)
> #xmin       : 2555581
> #xmax       : 3398581
> #ymin       : 2281655
> #ymax       : 2599655
>
> [[elided Hotmail spam]]
>
> -------------------------------------------------------------
>
> ________________________________
> De: R-sig-Geo <r-sig-geo-bounces using r-project.org> en nombre de Tim Salabim <tim.appelhans using gmail.com>
> Enviado: s�bado, 20 de junio de 2020 18:32
> Para: Edzer Pebesma <edzer.pebesma using uni-muenster.de>
> Cc: r-sig-geo <r-sig-geo using r-project.org>
> Asunto: Re: [R-sig-Geo] Error when saving an sf (data) object to file as a shapefile
>
> And for anyone looking for arguments:
>
> http://switchfromshapefile.org/
>
>
> On Sat, Jun 20, 2020, 18:20 Edzer Pebesma <edzer.pebesma using uni-muenster.de>
> wrote:
>
>>
>> On 6/20/20 12:28 PM, Lom Navanyo wrote:
>>> Unknown field name `Act_Depthtwtr': updating a layer with improper field
>>> name(s)?
>> Shapefiles have funny restrictions as to the length and form of variable
>> names, you probably ran into that, as the message suggests.
>>
>> A general advice is to not use shapefiles for writing; there are better
>> alternatives, geopackage comes to mind. Shapefiles make life unnecessary
>> complicated, you've now run into two of the many problems they have. The
>> days of creating shapefiles are over. If someone asks you to create
>> shapfiles, explain them it is a bad idea.
>> --
>> Edzer Pebesma
>> Institute for Geoinformatics
>> Heisenbergstrasse 2, 48149 Muenster, Germany
>> Phone: +49 251 8333081
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>          [[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
>
>        [[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


        [[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

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list