[RS-ecology] RS-ecology Digest, Vol 7, Issue 1

Andrew Purdon andrew.purdon at zoology.up.ac.za
Thu Mar 24 08:52:18 CET 2016


Morning Henrike,

I had a similar problem, hope the script below helps.

## Required packages
require(raster)
require(snow)
require(RStoolbox)

## create a list of the metadata of the Landsat tiles you would like to merge
lsat_list <- list.files("C:/test", pattern="_MTL", full.names=FALSE)

merge_list <- list()

## Create a list of RasterStack objects from the list of metadata files
for(i in lsat_list){
  lsat_org    <- stackMeta(paste("C:/test/",i, sep=""))

  ## Set the values that are 0 to NA
  NAvalue(lsat_org)<-0

  merge_list  <- append(merge_list, lsat_org)
}


## Merge all the rasters together using mosaic
merge_list$tolerance <- 0.05
merge_list$fun<- "mean"
beginCluster() ## Used the 'snow' package to speed things up
merged<-do.call(mosaic, merge_list)
endCluster()

## Write raster
writeRaster(merged, "C:/test/filename", format = "GTiff", overwrite = TRUE)


Regards,
Andrew Purdon
andrew.purdon at zoology.up.ac.za
Conservation Ecology research Unit
Department of Zoology and Entomology
Office 3-22.3
University of Pretoria
Hatfield
Pretoria
0020






On Wed, March 23, 2016 17:06, rs-ecology-request at lists.uni-wuerzburg.de
wrote:
>
> Send RS-ecology mailing list submissions to
> 	rs-ecology at lists.uni-wuerzburg.de
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology
> or, via email, send a message with subject or body 'help' to
> 	rs-ecology-request at lists.uni-wuerzburg.de
>
> You can reach the person managing the list at
> 	rs-ecology-owner at lists.uni-wuerzburg.de
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of RS-ecology digest..."
>
>
> Today's Topics:
>
>    1. Problem with merging raster objects (Henrike StB)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 23 Mar 2016 15:26:32 +0100
> From: Henrike StB <henrikestb at gmail.com>
> To: rs-ecology at lists.uni-wuerzburg.de
> Subject: [RS-ecology] Problem with merging raster objects
> Message-ID:
> 	<CAO1AbmQGUhj3EhX7m1ctDvMDqNs+tSU7jv+vPY_=NqPZ9HYw2Q at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Dear all,
>
> I'm having trouble merging Landsat scenes using the "merge" function in
> the
> raster package. No warnings are raised, but the merged scene looks as if
> overlap=FALSE - basically as though someone had taken a bunch of polaroids
> and placed them so they overlapped (if that does not make sense, please
> see
> attachment).
> I'd like to get rid of the white "frames" around the individual scenes
> before further processing. Does anyone happen to know what the problem
> with
> my code might be, or has anyone had similar problems?
>
> Thank you in advance for any hints you might be able to give!
>
> My code looks as follows:
>
> # I load adjacent scenes as multi-layer objects:
>
> scene1 <- stack(...) # multi-layer raster object; contains all 7 bands of
> the first scene
> scene2 <- stack(...)
> ....
> scene10<- stack(...)
>
> # Then I try merging these raster objects using a for-loop:
>
> all_scenes <-as.list(print(c(scene1, scene2, ..., scene10)))
>
> for(i in 1:length(all_scenes))
> {
>   if (i == 1) {
>     merged_scenes <- all_scenes[[i]][[1:7]]
>   }
> else if (i > 1) {
>     merged_scenes <- merge(merged_scenes, all_scenes[[i]][[1:7]],
> tolerance
> = 0.05, overlap=TRUE)
>   }
> }
>
> writeRaster(merged_scenes, "filename", format = "GTiff", overwrite = TRUE)
>
>
> Best wishes,
> Henrike
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20160323/a8347751/attachment.html>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: Failed scene merge.PNG
> Type: image/png
> Size: 56926 bytes
> Desc: not available
> URL:
> <http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20160323/a8347751/attachment.png>
>
> ------------------------------
>
> _______________________________________________
> RS-ecology mailing list
> RS-ecology at lists.uni-wuerzburg.de
> https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology
>
>
> End of RS-ecology Digest, Vol 7, Issue 1
> ****************************************
>



---------------------------------------------------------------------
This message and attachments are subject to a disclaimer. Please refer to http://www.it.up.ac.za/documentation/governance/disclaimer/ for full details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule onderhewig. Volledige besonderhede is by http://www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.


More information about the RS-ecology mailing list