R raster package split image into multiples

后端 未结 6 1760
闹比i
闹比i 2021-02-03 14:18

I have an image as below. It is 2579*2388 pixels. Lets assume that it\'s bottom left corner is at 0,0. From that image I want to create multiple images as follows and save them

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-03 14:45

    I think what you need is to create a function for your processing part (let's call it "fnc") and a table that lists the number of tiles that you have made (let's call it "tile.tbl") and also let's assume that your geobig data called "obj"

        obj=GDALinfo("/pathtodata.tif")
        tile.tbl <- getSpatialTiles(obj, block.x= your size of interest, return.SpatialPolygons=FALSE)        
    

    and then parallelize it using snowfall package. Here is an example:

        library(snowfall)
        sfInit(parallel=TRUE, cpus=parallel::detectCores())
        sfExport("tile.tbl", "fnc")
        sfLibrary(rgdal)
        sfLibrary(raster)
        out.lst <- sfClusterApplyLB(1:nrow(tile.tbl), function(x){ fnc(x, tile.tbl) })
        sfStop()
    

    For a detailed explanation please see HERE

提交回复
热议问题