FME Version
Introduction
The RasterTiler transformer takes a raster and breaks it up into either a defined number of tiles or a defined size of tiles. This is separate from the WebMapTiler transformer, which would be used to tile data for web maps (i.e., Bing or Google Maps). In this example, we will take a digital elevation model of the North Shore Mountains just north of Vancouver, British Columbia, and divide it into 6 GeoTIFF raster tiles.
The data used in this step-by-step tutorial is available in the files section of this article (top right).
Step-by-Step Instructions
In this step-by-step tutorial, you will learn how to use the RasterTiler transformer to break up a raster into either a defined size or a number of tiles.
1. Read in the Digital Elevation Model (DEM)
Start FME Workbench and add a Canadian Digital Elevation Data (CDED) reader in a blank workspace. In the Dataset parameter, browse to the "NorthShoreMountains.dem" dataset. This file is a Digital Elevation Model (DEM) of the North Shore Mountains, just north of Vancouver, BC.
2. Inspect the Data
Run the translation and inspect the data in Visual Preview (if it does not show it automatically, select the View Source Data... icon on the reader feature type). This DEM has a longer x-axis than its y-axis, so it would be best tiled into more horizontal tiles than vertical tiles. So, we will tile it into three horizontal tiles and two vertical tiles to create six individual tiles.
3. Add the RasterTiler Transformer
To create these tiles, we will use the RasterTiler transformer. Add a RasterTiler to the canvas and connect the CDED reader feature type to it. Double-click on the RasterTiler transformer, and in its parameters, set the Define Tiles By parameter to "Number of Tiles". Then, for the Columns parameter, set it to "2", and for the Rows parameter, set it to "3". We want all tiles to be the same size, so change the Force Equal Sized Tiles parameter to "Yes". You can change the names of the Output Attributes Names parameters if you wish, but for this example, we will use the defaults. Click OK to close the parameters dialog. Run the workspace.
4. Create a More Descriptive File Name
If we were to write it to a GeoTIFF now, our naming convention would look like the following image, which isn't very descriptive.
To make the file name more descriptive, we can use the StringConcatenator transformer to concatenate the column and row names created by the RasterTiler transformer. Add a StringConcatenator transformer to the canvas and connect the RasterTiler Tiles Output port to it. Double-click the StringConcatenator transformer to open its parameters. In the parameters, change the New Attribute parameter to "RasterTileName". Then, for the StringParts parameter table, 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 this:
Row@Value(_tile_row)Col@Value(_tile_column)
5. Write to GeoTIFF
Now that the DEM is tiled and we have a descriptive name, we can write it to a GeoTIFF. Add a GeoTIFF (Geo-referenced Tagged Image File Format) writer and set the Attribute Definition parameter to Automatic, then click OK. When the feature type dialog appears, click OK; we will modify the parameters in a moment. Connect the output port on the StringConcatenator to the new GeoTIFF writer feature type. Now that it is connected to our translation, we can modify the raster file name. Double-click the writer feature type, and in its parameters, click the drop-down arrow to the right of the Raster File Name parameter. Select Open Text Editor. In Text Editor, set the value to this:
@Value(fme_basename)@Value(RasterTileName)
This will fanout the tiles by the name of the DEM, in this case, "NorthShoreMountains", and then append the row and column numbers we created at the end.
If you have issues viewing the final GeoTIFF files in Visual Preview, please ensure your background map is turned off.
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 numeric rasters need color interpretation to be viewed: the underlying data is perfectly correct. Color rasters would not exhibit the same differences because they would not require 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
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
Comments
0 comments
Please sign in to leave a comment.