Re: [R-sig-Geo] Comparing 2 rasterbricks using functions from TSdist package

2020-05-28 Thread Loïc Dutrieux
Hi Jackson, calc is meant to apply a function pixel wise on a single raster object. Its equivalent for multiple raster objects is overlay. Kind regards, Loïc On 05/28/2020 09:05 AM, Bede-Fazekas Ákos wrote: Dear Jackson, I think this is what you are searching for: new_s3 <- setValues(r,

Re: [R-sig-Geo] Error in applying calc to rasterbrick with NA vallues

2020-05-08 Thread Loïc Dutrieux
Hi Jackson, All the layers of the toy dataset you create in your example are identical. Is that intentional? Below I create a more heterogeneous dataset and introduce a few NAs. library(raster) library(trend) set.seed(12) r <- raster(nrow=10, ncol=10) s <- lapply(1:200, function(i)

Re: [R-sig-Geo] enable parallel analysis on pixels from rasterbrick

2020-05-06 Thread Loïc Dutrieux
Hi Jackson, The strategy is to make your function work for raster::calc, and parallelize it with raster's built in parallelization utils (see ?clusterR). Looping over pixels of a raster/matrix is nearly never the correct answer. stars::st_apply would probably also be a good option.

Re: [R-sig-Geo] windowed reading raster with stars

2020-04-25 Thread Loïc Dutrieux
Thanks Edzer, I confirm that it's working now. Kind regards, Loïc On 04/25/2020 07:05 PM, Edzer Pebesma wrote: See https://github.com/r-spatial/stars/issues/276 should be fixed now. Thanks! On 4/25/20 6:06 PM, Loïc Dutrieux wrote: Hi Edzer, Below an example that generates a raster

[R-sig-Geo] windowed reading raster with stars

2020-04-25 Thread Loïc Dutrieux
Hi everyone, I have a large geoTiff raster file that does not fit in memory (if I do read_stars(file_path) I get "Error: cannot allocate vector of size 12.7 Gb"). How can I read a spatial subset of that file. The example below works with a toy example but not with the actual large dataset.

Re: [R-sig-Geo] Error in reading shape file with readOGR()

2018-02-14 Thread Loïc Dutrieux
On 14/02/2018 04:11, Roger Bivand wrote: > On Tue, 13 Feb 2018, Adam Fera wrote: > >> Hello, Amos, >> >> I came across this posting because I had a similar problem using R for >> mapping within GNU Emacs Org Mode on GNU/Linux.  I work on a research >> team >> that uses a shared directory for

Re: [R-sig-Geo] [FORGED] circular spatial polygon

2017-09-12 Thread Loïc Dutrieux
This is also possible with rgeos library(sp) library(rgeos) x <- 673593.21 y <- 673593.21 sp0 <- SpatialPoints(coords = data.frame(x=x, y=y), proj4string = CRS('+proj=utm +zone=20 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs')) sp1 <- gBuffer(sp0, byid=TRUE, width =

Re: [R-sig-Geo] Aggregation to

2017-08-31 Thread Loïc Dutrieux
On 31/08/17 14:22, Miluji Sb wrote: I have a set of coordinates: temp <- dput(head(gcp,10)) structure(list(lon = c(-180, -180, -179, -179, -178, -178, -177, -176, -176, -175), lat = c(67, 68, 67, 68, 67, 68, 67, 66, 67, 66)), datalabel = "", time.stamp = "11 Aug 2017 16:10", .Names = c("lon",

Re: [R-sig-Geo] Slow writing of point features to SpatialLite-DB or Geopackage

2017-08-24 Thread Loïc Dutrieux
On 24/08/17 10:23, Roger Bivand wrote: On Thu, 24 Aug 2017, manuel.schnei...@agroscope.admin.ch wrote: Dear list I am searching alternatives to ESRI shapefiles for the storage of GPS data, i.e. tagged point features, and came across SpatialLite or Geopackage. Unfortunately writing to both

Re: [R-sig-Geo] Cannot correctly assign Data type of upper left cell in ascii grid with writeRaster

2017-05-17 Thread Loïc Dutrieux
writeRaster() defaults to Float 8, regardless of the data type of your input matrix. You can set it explicitly to write to integer by using the datatype= argument. writeRaster(r, "Test_writeRaster.asc",NAflag =-999,overwrite=T, datatype='INT2S') Cheers, Loïc On 17/05/2017 03:21, Michael Koehler

Re: [R-sig-Geo] Sentienl 2 gdal translate

2017-03-16 Thread Loïc Dutrieux
sk rik ozi rasterlite > mbtiles postgisraster arg > > I think the problem is the driver that is used to manage the jp2 file. > Any idea how can I include in the R code the --config GDAL_SKIP JP2ECW > option. > > Cheers, > M > >> El 15 mar 2017, a las 23:13, Loïc Dutrie

Re: [R-sig-Geo] Sentienl 2 gdal translate

2017-03-15 Thread Loïc Dutrieux
Hi, I tried your code with some S2 images I had lying around, and it works on my system. I modified it a bit to write the output layers to the same directory and not to my working directory. library(gdalUtils) library(raster) Image_Path<-'/path/to/images/' S2_JP2_List <- list.files(Image_Path,

Re: [R-sig-Geo] calculate selected area from stacked raster object

2017-02-23 Thread Loïc Dutrieux
Thanks for providing an example, see the suggestion inline On 22/02/2017 10:45, Francesc Montserrat wrote: > Dear List, > > As I have only recently started using R for spatial analysis, and I am > not a geographer or spatial data specialist by any means, I have a -what > I presume to be-

Re: [R-sig-Geo] Calculate anomalies on time-series rasters

2017-02-12 Thread Loïc Dutrieux
On 12/02/2017 03:14, Michael Sumner wrote: > I believe the "remote" package has functions for doing exactly this. > > HTH > > On Sun, Feb 12, 2017, 17:42 Thiago V. dos Santos via R-sig-Geo < > r-sig-geo@r-project.org> wrote: > >> Dear all, >> >> I have a netcdf file with monthly temperatures

Re: [R-sig-Geo] getData returns status 403

2017-01-30 Thread Loïc Dutrieux
Thanks for figuring it out Barry. I informed Robert about it. Cheers, Loïc On 30/01/2017 08:19, Barry Rowlingson wrote: > On Sun, Jan 29, 2017 at 7:26 PM, Loïc Dutrieux > <loic.dutri...@conabio.gob.mx> wrote: >> world <- getData(name = 'countries') > > The world count

[R-sig-Geo] getData returns status 403

2017-01-29 Thread Loïc Dutrieux
Hi, Were there any changes made to the ucdavis server, from which getData() gets its data? I'm trying to download a spatialpolygondataframe of the world, but it returns a status 403. Can anyone reproduce? Same thing happens when I try to run the url in the browser or with wget. Also, is r-forge

Re: [R-sig-Geo] Efficient way to process a time series of MODIS image

2017-01-19 Thread Loïc Dutrieux
Good question, it's rarely necessary, or a good idea, to convert rasters to dataframes/data.tables for analysis. For pixel wise operations use raster::calc() or simple raster arithmetics, which inherits from vector arithmetics. Cheers, Loïc On 19/01/2017 09:35, Zhang Tianyi wrote: > Dear all, >

Re: [R-sig-Geo] Elevation data

2017-01-13 Thread Loïc Dutrieux
On 13/01/2017 10:59, Miluji Sb wrote: > Thank you for your reply. This is what I did: > > ### > library(data.table) > library(raster) > library(rgdal) > library(foreign) > > elevation_world <- getData('worldclim', var='alt', res=2.5) > > # Aggregate Elevation to 1 degree >

Re: [R-sig-Geo] Downscaling a raster map

2016-11-28 Thread Loïc Dutrieux
On 28/11/2016 10:26, Francesco Carotenuto via R-sig-Geo wrote: > Hi everyone,I'm looking for a method to downscale a 250x250 km wide > resolution altitudemap of the past (about 3 million years ago) to a finer > resolution. I would the spatialstructure of the downscaled map to resemble > the

Re: [R-sig-Geo] Write sf object to spatialite database

2016-11-10 Thread Loïc Dutrieux
copy is_raster is_vector > 151 SQLite SQLite / Spatialite TRUE FALSE FALSE TRUE > > In that case, you may want to use st_write instead. > > On 10/11/16 15:47, Loïc Dutrieux wrote: >> Hi, >> >> Is it possible to write sf objects to spatialite databases

[R-sig-Geo] Write sf object to spatialite database

2016-11-10 Thread Loïc Dutrieux
Hi, Is it possible to write sf objects to spatialite databases? I tried to adapt the postgis example of the st_write_db function but I get the following error: Error in sqliteSendQuery(con, statement, bind.data) : error in statement: no such function: AddGeometryColumn Cheers, Loïc library(sf)

Re: [R-sig-Geo] Error when combining raster and foreach packages

2016-08-26 Thread Loïc Dutrieux
Hi Lukas, What does your function do? Can you use the built-in parallel functionalities of the raster package instead? See ?beginCluster Cheers, Loïc On 26/08/2016 12:23, Lukas Lehnert via R-sig-Geo wrote: Dear list members, I tried to process a large GeoTIFF file in a blockwise manner

Re: [R-sig-Geo] How to calculate seasonal means in raster time series?

2016-08-17 Thread Loïc Dutrieux
On 17/08/2016 02:51, Bacou, Melanie wrote: Maybe create a function that takes a date as input and returns a meteorological season, and pass this function to `zapply(by=fun)`. --Mel. On 8/16/2016 8:38 PM, Thiago V. dos Santos via R-sig-Geo wrote: Dear all, I am using the raster package to

Re: [R-sig-Geo] Aggregate data to lower resolution

2016-07-21 Thread Loïc Dutrieux
Hi Milu, The code you provided works perfectly on my computer. What doesn't work in your case? Do you get an error message? Cheers, Loïc On 21/07/2016 22:57, Miluji Sb wrote: Dear all, I have the following GDP data by latitude and longitude at 0.5 degree by 0.5 degree. temp <-

[R-sig-Geo] raster overlay: apply function on multiple RasterBrick

2016-07-20 Thread Loïc Dutrieux
Hi everyone, I'm struggling to apply a function on multiple RasterBrick with raster::overlay. In the dummy example below the idea is that the function takes two numeric vectors and returns the slope of the linear model. Therefore I would expect to have a RasterLayer in return with slope for

Re: [R-sig-Geo] Add +1 to current value of a cell in a raster in R

2016-07-11 Thread Loïc Dutrieux
This works fine for me: library(raster) r <- raster(ncol=5,nrow=5) r[] <- 0 vec <- c(1,1,1,3,4,5,6,7,8,8,8,9) a <- data.frame(table(vec)) a$vec <- as.numeric(a$vec) # Not very elegant coercion, there must be a better way r[a$vec] <- r[a$vec] + a$Freq[a$vec] Cheers, Loïc On 07/11/2016 02:58

Re: [R-sig-Geo] How to calculate climatology in rasterbricks

2016-06-04 Thread Loïc Dutrieux
.811 0.047 0.866 Cheers, -- Thiago V. dos Santos PhD student Land and Atmospheric Science University of Minnesota On Friday, June 3, 2016 4:25 AM, Loïc Dutrieux <loic.dutri...@wur.nl> wrote: This can also be done with zApply: library(zoo) sYM <- zApply(s, by = as.yearmon, sum)

Re: [R-sig-Geo] How to calculate climatology in rasterbricks

2016-06-03 Thread Loïc Dutrieux
This can also be done with zApply: library(zoo) sYM <- zApply(s, by = as.yearmon, sum) sM <- zApply(sYM, by = months, mean) Cheers, Loïc On 06/03/2016 02:02 AM, Vijay Lulla wrote: I think the following StackOverflow question has the answer:

Re: [R-sig-Geo] Run focal function on a multi-layer raster

2016-05-21 Thread Loïc Dutrieux
Hi Thiago, calc is not aware of neighbouring pixels in the x,y dimensions, so functions like focal cannot work. I found the function below in an old repos of mine. It still seems to work fine :) #' Focal for RasterBrick or RasterStack #' #' @param x RasterBrick/Stack or character pointing

Re: [R-sig-Geo] Warning when stacking, masking or cropping raster objects

2016-05-17 Thread Loïc Dutrieux
It's related to a change in R, not in raster. See "DEPRECATED AND DEFUNCT" related to R 3.3.0 in https://cran.r-project.org/src/base/NEWS Cheers, Loïc On 05/17/2016 06:20 AM, Thiago V. dos Santos via R-sig-Geo wrote: I also noticed those warnings after the last raster update. Here is one

Re: [R-sig-Geo] FW: proj4string error on data.frame generated from NCEP data

2016-04-08 Thread Loïc Dutrieux
-Original Message- From: Frede Aakmann Tøgersen Sent: 8. april 2016 08:01 To: 'Maggie CY Lau'; r-sig-geo@r-project.org Subject: RE: proj4string error on data.frame generated from NCEP data Hi Maggie Your error message says that there is some coordinates with latitudes above 90

Re: [R-sig-Geo] FW: proj4string error on data.frame generated from NCEP data

2016-04-08 Thread Loïc Dutrieux
On 04/08/2016 08:50 AM, Frede Aakmann Tøgersen wrote: Reposting again again without data. So fetch the data yourself :-( Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance & Modeling Technology & Service Solutions T +45 9730 5135 M +45 2547

Re: [R-sig-Geo] raster::zonal with more than 1 zonal layer

2016-03-03 Thread Loïc Dutrieux
it looks like unique combinations in the 3rd dimension is what unique() returns in the case of a multilayer raster object. Cheers, Loïc ds On Wed, Mar 02, 2016 at 3:24 AM "Loïc Dutrieux" <">"Loïc Dutrieux" > wrote: On 03/02/2016 01:48 AM, Dominik Schne

Re: [R-sig-Geo] raster::zonal with more than 1 zonal layer

2016-03-02 Thread Loïc Dutrieux
On 03/02/2016 01:48 AM, Dominik Schneider wrote: I'd like to summarise a raster using elevation and watershed. I was originally using extract() with a shape file and then each elevation band within each polygon but it's very slow. zonal() is much faster and I can rasterize my polygons to use

Re: [R-sig-Geo] raster package: Force read into memory

2016-03-01 Thread Loïc Dutrieux
Hi MArk, I believe you're looking for readAll() Cheers, Loïc On 03/01/2016 12:06 PM, Mark R Payne wrote: Hi, Once upon a time I remember there being functionality in the raster package to force it to read the contents of a raster object into memory (admittidly at your own risk). However, I

Re: [R-sig-Geo] Error running Mann-Kendall trend test on a raster stack

2016-02-27 Thread Loïc Dutrieux
Hi Thiago, A few calc tips inline that you can use together with Tim's suggestion. On 02/27/2016 07:47 AM, Tim Appelhans wrote: Dear Thiago, have a look at the gimms package, available on CRAN. The function of interest is significantTau().

Re: [R-sig-Geo] Multiplying a raster object

2016-02-24 Thread Loïc Dutrieux
On 02/23/2016 09:22 PM, Tadaishi Yatabe-Rodriguez wrote: Hi community, I have a raster object of a kernel density, where the linear unit is meter, and when I plot it it gives me very small density values (units per sq meter, I suppose). I figure that if I multiply it, say by a 1000, it will

Re: [R-sig-Geo] Population-weighted Centroids of Polygons in R

2016-02-21 Thread Loïc Dutrieux
Hi Sohrab, I don't think there is a method for weighted centroids specifically. What if you get the centroid coordinates of each "block" using gCentroid() and calculate a weighted average of the coordinates of every centroid? See an example below assuming your blocks are a

Re: [R-sig-Geo] Intersect shapefiles

2016-02-18 Thread Loïc Dutrieux
Hi, Have you tried gIntersection from the rgeos package. Given 3 SpatialPolygon* objects you can probably do something like: sp12 <- gIntersection(sp1, sp2) sp123 <- gIntersection(sp12, sp3) Cheers, Loïc On 02/18/2016 10:25 AM, John Wasige wrote: ​Dear all, I have three shapefiles that I

Re: [R-sig-Geo] Take mean of list of raster stacks

2015-12-02 Thread Loïc Dutrieux
Hi Thiago, Otherwise overlay wrapped in do.call seems to work. See example below: Cheers, Loïc library(raster) # Create multiple raterStacks s1 <- stack(system.file("external/rlogo.grd", package="raster")) s2 <- s1 * 2 s3 <- s1 * 3 s4 <- s1 * 4 # Create a unnamed list (not sure why it

Re: [R-sig-Geo] Take mean of list of raster stacks

2015-12-02 Thread Loïc Dutrieux
on arguments are passed, I think. I don't understand the S4 system that well. Basically, how would I use a list with names in do.call with raster::overlay? On Wed, Dec 2, 2015 at 11:26 AM, Loïc Dutrieux <loic.dutri...@wur.nl> wrote: Hi Thiago, Otherwise overlay wrapped in do.call

Re: [R-sig-Geo] How to calculate decadal average and percent change in raster stacks?

2015-12-01 Thread Loïc Dutrieux
Hi Thiago, This should work for aggregating to decades. library(raster) library(lubridate) # Create the date sequence idx <- seq(as.Date("2010/1/1"), as.Date("2099/12/31"), by = "year") # Create raster stack and apply the date r <- raster(ncol=360, nrow=180) s <- stack(lapply(1:length(idx),

Re: [R-sig-Geo] Match polygon and dataframe IDs after raster::extract

2015-11-19 Thread Loïc Dutrieux
, but SpatialPolygonsDataFrame() doesn't. (I made a mistake in my initial example, I want to create a SpatialPolygonsDataFrame, not a SpatialPointsDataFrame). Cheers, Loïc On 11/19/2015 03:08 PM, Edzer Pebesma wrote: On 19/11/15 14:37, Loïc Dutrieux wrote: Hi all, I'm trying to look at correlation between two

[R-sig-Geo] Match polygon and dataframe IDs after raster::extract

2015-11-19 Thread Loïc Dutrieux
Hi all, I'm trying to look at correlation between two raster layers, for different polygons. So I use raster::extract to get all the raster values for every polygon, do the calculation and feed the output back to a SpatialPolygonDataFrame. I got it working, but I have a doubt regarding the

Re: [R-sig-Geo] Programmatically convert raster stack in data frame based on polygon extraction

2015-10-29 Thread Loïc Dutrieux
Hi Thiago, extract() and some dataframe manipulation should do the trick. See comments in line. Cheers, Loïc On 10/29/2015 09:06 PM, Thiago V. dos Santos wrote: Hi all, I am trying to extract temperature values from a raster stack for about 400 municipalities in Brazil. My final goal is

Re: [R-sig-Geo] Monthly loop in raster stack with daily data

2015-10-29 Thread Loïc Dutrieux
Hi Thiago, I think zApply should get you there (for each stack independently). library(zoo) library(raster) #Create a rasterStack similar to my data - same dimensions and layer names r <- raster(ncol=360, nrow=180) s <- stack(lapply(1:730, function(x) setValues(r,

Re: [R-sig-Geo] Raster multi-band time series analysis

2015-10-26 Thread Loïc Dutrieux
Hi Victor, I don't have much experience with beginCluster; however, I have written a parallel version of raster::calc a little while ago that uses forking. https://github.com/dutri001/bfastSpatial/blob/master/R/mc.calc.R calc and overlay are analogue so that it shouldn't be too hard to extend

Re: [R-sig-Geo] Raster multi-band time series analysis

2015-10-23 Thread Loïc Dutrieux
Hi Victor, As far as I know there isn't anything yet for dealing with raster that have more than 3 dimensions in R. The raster package actually has a 4D class (raterQuad I think) though, but it does not have any methods yet, so it won't help you much, unless you want to develop the methods

Re: [R-sig-Geo] Spatialpolygonsdataframe

2015-08-18 Thread Loïc Dutrieux
Hi, Have a look at merge in the sp package. ?sp::merge Cheers, Loïc On 08/18/2015 04:12 AM, Metastate Metastate wrote: Hi all, I am starting to learn spatial analysis using R. Do anyone know if the attribute data in a spatialpolygonsdataframe can contain multiple observations within the same

Re: [R-sig-Geo] georeferencing image from scratch

2015-08-17 Thread Loïc Dutrieux
package. Cheers, Loïc Dutrieux On 08/17/2015 11:43 AM, Marcelo Kittlein wrote: Hi all I want to change a MSS landsat image which has bad georeferencing. I have a grid of points with correct georeferences and want to use them to reproject the image to a correct reference system. Is there some way

Re: [R-sig-Geo] measuring longitudes as if they were parallels?

2015-07-31 Thread Loïc Dutrieux
Hi John, Possibly what you're looking for is in the geosphere package (https://cran.r-project.org/web/packages/geosphere/geosphere.pdf). Cheers, Loïc On 07/31/2015 04:47 PM, john d wrote: Dear all, Here's another issue that I've been struggling with and I'd really appreciate any input. I

Re: [R-sig-Geo] Set output data type for projectRaster

2015-07-08 Thread Loïc Dutrieux
Hi Ned, dataType with capital T is the function to retrieve the data type of a raster object. When used as argument to set the type of a file being written, use datatype= (with lower case t). Cheers, Loïc On 07/08/2015 02:32 AM, Ned Horning wrote: Hi all - I am trying to project a raster

Re: [R-sig-Geo] Problem merging rasters after conversion and reprojection of .hdf file

2014-04-30 Thread Loïc Dutrieux
=+proj=longlat +datum=WGS84 +no_defs, dstfile=file.path(dir, 'mosaic_latlong.tif')) r - raster(file.path(dir, 'mosaic_latlong.tif')) plot(r) Hope this helps Best regards, -- Loïc Dutrieux Laboratory of Geo-Information Science and Remote Sensing Wageningen University The Netherlands On 14-04-30

Re: [R-sig-Geo] writeRaster issue

2014-04-23 Thread Loïc Dutrieux
Dear Guillermo, Yes, there are a few differences among platforms when it comes to rgdal. You may check that your gdal installation has the GTiff driver. ## library(rgdal) gdalDrivers() In most cases gdal will automatically configure with GTiff though. Best regards, -- Loïc Dutrieux