Hot answers tagged

22

I had the same issue some months ago. Use gdal_merge to generate a new file from the 3 independent rasters. In OSGeo4W command line you can do this: gdal_merge.bat -separate -of GTiff -o output.tif input1.tif input2.tif input3.tif In QGIS you can do the same with a GUI in the raster plugin "merge" tool.


11

You could try "Raster -> Miscellaneous -> Merge" which is a front-end for GDAL's merge_raster.py. It's part of GdalTools plugin that you may have to enable from the "Plugins -> Manage plugins..." dialogue.


11

Here is an example of creating a stacked image, using the ee.ImageCollection.iterate() method. I also included code to define to define an example region and image collection, so that it is a working example. // Define a sample Region-of-Interest var roi = ee.Geometry.Polygon( [[[-109.1, 37.0], [-109.1, 36.9], [-108.9, 36.9], ...


9

You need to use the Composite Bands ArcGIS Geoprocessing tool. According to the ArcGIS Help, This tool can also create a raster dataset containing subset of the original raster dataset bands. This is useful if you need to create a new raster dataset with a specific band combination and order.


7

I have found on stack overflow a more generic way with the raster package using stackApply(). #get the date from the names of the layers and extract the month indices <- format(as.Date(names(ndvi.stack), format = "X%Y.%m.%d"), format = "%m") indices <- as.numeric(indices) #sum layers MonthNDVI<- stackApply(ndvi.stack, indices, fun = mean) names(...


6

I also needed to know how to rename bands in an open source environment so spent a whole day looking for answers. There is no way to name bands in QGIS while merging. But it can be done after the file is created, by editing their .aux.xml file. It works for both .tif and .img files, as far as I've researched. The solution is to include after each <...


5

So I am able to get all the layers in a single layer, a "composite" by using the MultiProvider provider in the class and just passing it the layers I want in the composite as the arguments. It results in a single JSON file that contains all of my layers. This is the layer I added in the cfg "composite": { "allowed origin":"*", ...


5

Just use a for loop with a little trick to iterate. First, as always is recommended, a reproducible example: library(raster) data('lsat',package='RStoolbox') names(lsat)[1:4] <- c('blue','green','red','NIR') images <- list() for(i in 1:27){ images[[i]] <- lsat[[1:4]] } images <- stack(images) images ## class : RasterStack ## ...


5

If you read a TIFF with raster like you have in your loop you'll only get one layer read: > r = raster("./GcrfPicture.tif") > r class : RasterLayer band : 1 (of 4 bands) dimensions : 720, 960, 691200 (nrow, ncol, ncell) resolution : 1, 1 (x, y) The 1 (of 4 bands) is telling you that the source had four bands but its only read one....


4

First, you are using R. R Studio is just an IDE for R so in the future please make this an R question. I will warn you that working with HDF files in R is a pain. In theory GDAL supports HDF5 so one could use readGDAL in the rgdal package. Depending on the source of the data readGDAL has a high fail rate making it less than reliable. Historically, there ...


4

Geoprocessing was moved to processing toolbar in QGIS 2.16, as you can see below:


4

In Windows (run OSGeo4W shell): Scaling: for %i in (*.tif) DO gdal_translate -scale -2000 10000 -0.2 1 %i outputs\%i You might find recalculating instead better: for %i in (*.tif) DO gdal_calc.bat -A %i --outfile=outputs\%i --calc="A*0.0001" --NoDataValue=0 In Ubuntu looping through files is slightly different: for i in *.tif; do gdal_calc -A $i ......


4

You can manage multi-extent-problem resampling your data before mask() function. This work for aligned and non-aligned pixels (for non-aligned, choose wisely method argument). Also, you can use extendto align boundaries of your data. I'd made an reproducible example for recreate our problem: library(raster) a <- raster(xmn=-100, xmx=100, ymn=-90, ymx=90,...


4

The most accurate solution to create monthly composites from these 16-day best value images would be to take into consideration the accompanying 'composite_day_of_the_year' scientific data set (see also MOD13A1 V006 product description). For a rather straightforward solution, please have a look at temporalComposite from MODIS and, in particular, the example ...


4

You can use mget() to search for objects given a character vector. predictors<-stack(mget(unique(as.character(bestpredictors$var))))


3

Your question is a good example of why site guidelines request that you provide an example of what you have already tried and ideally, some example data. There are many aspects of your question that leave one speculating. For example, I am not clear as to what you mean by "one from a SpatialPolygonsDataFrame". Is your land-use raster data rasterized from ...


3

I think I've found the answer. Convert to data frame and use count in the plyr package; y <- extract(s,c(1:ncell(s))) ydf <- as.data.frame(y) head(ydf) count(ydf, vars = c("layer.1","layer.2","layer.3","layer.4"))


3

You can control the number of plots per graphic device using the mfrow and mfcol arguments in par(). par(mfrow=c(3,4)) for(i in 1:12) {plot(runif(100),runif(100)*0.05)}


3

I had the troubles myself and couldn't find a solution. To export and import rasters between ENVI and R and keep the band names seems impossible (cf. this related question). A workaround is to copy the band_names from the .hdr file and rename the band names from the imported rasterstack. band names = {a,b,c} copied from file.hdr image <- stack("file....


3

You can use projectRaster() to resample to a new resolution (also extent and CRS): r2resampled <- projectRaster(r2,r1,method = 'ngb') r3resampled <- projectRaster(r3,r1,method = 'bilinear') The first one is categorical, so it's necessary to use nearest neighbor as method (ngb). The second one is numeric, so you can use bilinear (bilinear) or nearest ...


2

For Ubuntu users, just change .bat for .py and quote the files with respective path Go to the Terminal and write: gdal_merge.py -separate -of GTiff -o "path/output.tif" "path/input1.tif" "path/input2.tif" "path/input3.tif"


2

Here are some hints. It is difficult to answer without knowing more about your data. Please show us the result of: raster(raster_data[1]) You pass arguments to the raster function that are ignored when you create an object from file. You do not need to use crop on this layer. Certainly not before you project the data to lon/lat. You never need ...


2

You were right, the r.series manual page was a bit lousy. I have hopefully improved it now. Comments certainly welcome. Concerning quantiles, if you want a single, i.e. a global map value, then check r.quantile or r.univar Example: Calculation of multiple elevation quantiles, results are printed and not stored as a new map: g.region rast=elevation -p r....


2

If you choose rasterVis::levelplot, the layout argument will help you. Details about this argument can be found in the help page of lattice::xyplot: ‘layout’ is a numeric vector of length 2 or 3 giving the number of columns, rows, and pages (optional) in a multipanel display. library(raster) library(rasterVis) r <- raster() ll <- list() for (i in ...


2

You could use the gimms package to download (downloadGimms) and rasterize (rasterizeGimms) half-monthly NDVI3g layers for a 10-year period (see ?downloadGimms) and subsequently run calc(..., fun = mean, na.rm = TRUE) to deduce the decadal-scale average NDVI. The dataset comes in a spatial resolution of 1/12 degree (approx. 8 km), which is quite close to ...


2

If you have NA values that indicates that for a given raster they may not have a value at that particular location. There is a very thorough answer here on the topic You may want to ensure that you have cropped and masked your rasters before doing any future analysis. In R, you can change the NA values to a value to visualize where these NA values are and ...


2

See the example below: library("gapfill") library("raster") ## create raster data for demo ## extent: x=10, y=10, month=3, years=2 data <- array(runif(600), c(10,10,6)) data[c(1,5,54,76,150,450,556)] <- NA input_stack <- stack(brick(data)) plot(input_stack) ## create array and predict missing values with gapfill() tmp <- array(input_stack, dim=...


2

For unifying dimensions and resolutions of rasters, resample() function from Raster package works well for me: library(raster) r1 <- raster("Animal.tif") r2 <- raster("LandTrans.tif") r3 <- raster("TempJan.tif") r1 <- resample(r1,r3) r2 <- resample(r2,r3,method='ngb') rs <- stack(r1,r2,r3) plot(rs)


2

Note that the new, better way to do this is with imageCollection.toBands().


Only top voted, non community-wiki answers of a minimum length are eligible