span8
span4
span8
span4
The RasterTiler transformer is used for taking a raster and breaking it up into either a defined number of tiles or into a defined size of tiles. This is not to be confused with theWebMapTilertransformer, which would be used for tilling data for web maps (ie Bing or Google Maps). In this example, we will be taking a digitial elevation model of the North Shore Mountains just north of Vancouver, British Columbia and dividing it into 6 GeoTIFF raster tiles.
RasterTiling.fmw(completed template workspace)
RasterData.zip(contains NorthShoreMountains.dem raster)
1. Read in the digital elevation model (DEM)
In a blank workspace, add aCanadian Digital Elevation Data (CDED)Reader to the canvas and browse to the NorthShoreMountains.dem. This file is a digital elevation model (DEM) of the North Shore Mountains, just north of Vancouver, BC.
2. Inspect the data
Add anInspectortransformer after the CDED Reader and run the translation. Looking at this DEM, it has a longer x-axis than a y-axis, so it would be best tiled into more horizontal tiles than vertical tiles. So we will tile it into 3 horizontal tiles and 2 vertical tiles, to create 6 individual tiles.
Inspecting the NorthShoreMountains.dem in the Data Inspector
3. Add a the RasterTiler transformer
To create these tiles we will use theRasterTilertransformer. Add a RasterTiler to the canvas and connect it to the CDED Reader. In the parameters change the Tile Size or Number of Tiles to Number of Tiles. Then for Number of Horizontal Tiles set it to 3, and for Number of Vertical Tiles set it to 2. We want all of the tiles to be the same size, so change Force Equal Sized Tiles to Yes. You can change the names of the Attributes if you wish, but for this example, we will just use the defaults.
RasterTiler parameters, set the Horizontal Tiles to 3 and the Vertical Tiles to 2
1 raster is inputted, 6 raster tiles outputted in a 3x2 grid
4. Create a more descriptive file name
如果我们现在写出GeoTIFF,我们的命名convention would look like the following image, which isn’t very descriptive.
File names without description of placement of tile
To make the file name more descriptive, we will useStringConcatenatortransformer to concatenate the column name and the row name that was created with the RasterTiler. Add a StringConcatenator to the canvas, and connect it to the Tiles Output port on the RasterTiler. In the parameters, change the New Attribute name to RasterTileName. Then for StringParts enter the following:
String Type | String Value |
Constant | Row |
Attribute Value | _tile_row |
Constant | Column |
Attribute Value | _tile_column |
The Concatenated Results should look like:
Row@Value(_tile_row)Col@Value(_tile_column)
StringConcatenator parameters to create a descriptive raster tile name.
5. Write to GeoTIFF
Now that the DEM is tiled and we have a descriptive name for it, we can write it out to GeoTIFF. Add aGeoTIFF (Geo-referenced Tagged Image File Format)Writer to the canvas, set the Attribute Definition to Automatic and when the Feature Type dialog appears, just click ok, we will modify the parameters in a moment. Connect the new GeoTIFF Feature Type writer to the Output port on the StringConcatenator. Now that it is connected to our translation, we can modify the Raster File Name. In the parameters, click the drop-down menu next to the Raster File Name and select Open Text Editor. In the Text Editor set the value to:
@Value(fme_basename)@Value(RasterTileName)
This will fanout the tiles by the name of the DEM, which in this case is NorthShoreMountains and then append the row number and column number at the end. If you are having issues viewing the final GeoTIFF files in the Data Inspector, ensure that your background map is turned off.
File names with descriptive raster tile name appended
Tiled output GeoTIFFS
NB:The differences in the color range in the above images are caused by the Viewer calculating a scale separately for each raster. This only occurs because these are numeric rasters which need color interpretation to be viewed: the underlying data is perfectly correct! Color rasters would not exhibit the same differences because they would not need special interpretation. If you wanted to visualize this data as a continuous surface you could add a RasterInterpretationCoercer to the workspace before the RasterTiler to coerce everything into Grey8 (as opposed to Int8) - however refining the display like this would render the data useless as a DEM.
Data Attribution
Thedataused here originates from open data made available by the Government of British Columbia. It contains information licensed under theOpen Government License - British Columbia.
In the nextexercise, learn how to clip rasters using polygon features as well as an introduction to removing black borders.
© 2020 Safe Software Inc |Legal