How to create tiles from a raster dataset


Summary This article demonstrates the process of dividing a raster dataset into a set of smaller datasets with specified rows and columns.

Creating tiles from a raster dataset

See the following example code:
[Java]
static void createTilesFromRasterDataset(IRasterDataset rasterDataset, IWorkspace
    outputWorkspace, int tileWidth, int tileHeight)throws Exception{
    //Creates a set of raster datasets with specified rows and columns from the source dataset
    //rasterDataset: the source raster dataset
    //outputWorkspace: the output file raster workspace
    //tileWidth: the number of columns of each tile
    //tileHeight: the number of rows of each tile

    //Get source raster properties
    IRasterProps rasterProps = new IRasterPropsProxy
        (rasterDataset.createDefaultRaster());
    int width = rasterProps.getWidth();
    int height = rasterProps.getHeight();
    double xCell = rasterProps.meanCellSize().getX();
    double yCell = rasterProps.meanCellSize().getY();

    //Calcualte number of tiles and remaining pixels in both x and y dimensions
    int remX = width % tileWidth;
    int remY = height % tileHeight;
    int tileX = (int)(width / tileWidth);
    int tileY = (int)(height / tileHeight);

    IEnvelope dsExtent = rasterProps.getExtent();
    IEnvelope tileExtent = new Envelope();
    ISaveAs saveAs = null;
    int tempX;
    int tempY;

    //Create one raster with specified tile size
    for (int i = 0; i <= tileX; i++){
        if (i == tileX){
            tempX = remX;
        }
        else{
            tempX = tileWidth;
        }

        for (int j = 0; j <= tileY; j++){
            if (j == tileY){
                tempY = remY;
            }
            else{
                tempY = tileHeight;
            }

            rasterProps = new IRasterPropsProxy(rasterDataset.createDefaultRaster());

            //Recaculate the new extent
            tileExtent.setXMin(dsExtent.getXMin() + i * tileWidth * xCell);
            tileExtent.setXMax(tileExtent.getXMin() + tempX * xCell);
            tileExtent.setYMax(dsExtent.getYMax() - j * tileHeight * yCell);
            tileExtent.setYMin(tileExtent.getYMax() - tempY * yCell);

            rasterProps.setHeight(tempY);
            rasterProps.setWidth(tempX);
            rasterProps.setExtent(tileExtent);

            //Save the tile to the output workspace as IMG file, can be other writeable formats too
            saveAs = new ISaveAsProxy(rasterProps);
            saveAs.saveAs("tile_" + i + "_" + j + ".img", outputWorkspace, 
                "IMAGINE Image");
        }
    }
}


See Also:

How to access a raster dataset or raster catalog




Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime