FME Version
Introduction
Setting a NoData value can make a black color transparent. We will use this technique to create a map that has a main raster map, with two inset maps overtop. To learn more about NoData in rasters, see Setting NoData and Adding Alpha Bands to Remove Black Borders.
Step-by-step Instructions
1. Read in JPEG
Open FME Workbench and start a blank workspace. Add a JPEG (Joint Photographic Experts Group) reader to the canvas and then browse to the mainMap.jpg dataset which is available for download from the Files section on this article. Click OK to add the reader. We are adding the main map first so that when we mosaic the rasters together later, it will be on the bottom.
If you view the mainMap.jpg in Visual Preview, you will see a black border surrounding a raster map.
2. Read in PNG
Next, add a PNG (Portable Network Graphics) reader to the canvas and browse to the insets.png dataset. Click OK to add the reader.
If you view the insets.png in Visual Preview, you will see two smaller images in opposite corners with the remaining area being black. We will need to remove this black area so we can see the mainMap below after we merge the rasters.
3. Select Raster Bands
Now we need to select which bands we want to keep, since the main map JPEG only has three bands, let’s remove one of the bands from the inset PNG, which has four. Add a RasterSelector transformer to the canvas and connect it to the PNG reader feature type. In the parameters, click on the ellipsis for Band and Palette List. Next, select the first three bands with the values 0 to 2, and set the Palettes to ALL for all three. Click OK twice.
4. Keep Selected Raster Bands
Next, we need to tell FME to keep these three bands that we selected with the RasterSelector. Add a RasterBandKeeper to the canvas and connect it to the RasterSelector. There are no parameters to set.
If we run the workspace to here, and then inspect both the output of the RasterSelector and the RasterBandKeeper, we can see that the total number of bands has been changed from 4 to 3.
5. Set No Data
With both the JPEG and the PNG with the same number of bands, we can now assign one of those bands to NoData. Add a RasterBandNodataSetter transformer to the canvas and connect it to the JPEG reader feature type. In the parameters, set the Nodata Value to 0, then click OK.
Duplicate the RasterBandNodataSetter and then connect it to the RasterBandKeeper.
If you view the RasterBandNoDataSetter_2 in Visual Preview, you will see that the black background has been removed.
6. Mosaic Rasters
Using the RasterMosaiker, we will merge the two rasters together. Add a RasterMosaicker to the canvas and connect it to both of the RasterBandNodataSetters. In the parameters, change the Attribute Accumulation Mode to Merge Attributes, then click OK.
7. Remove NoData
One final step before we can write out the data is to remove the NoData to recreate the black border around the entire map. Add a RasterBandNodataRemover to the canvas and connect it to the RasterMosaiker. There are no parameters to set for this transformer.
8. Write to GeoTIFF
The data is now ready to be written out, add a GeoTIFF (Geo-referenced Tagged Image File Format) writer to the canvas, then browse to a location to save the dataset. Finally, set the Raster File Definition to Automatic, then click OK.
In the Feature Type dialog, set the Raster File Name to BasemapAndInsets, then click OK.
Connect the BasemapAndInsets writer feature type to the RasterBandNodataRemover transformer.
9. Run Workspace and View Output
It is important to rerun the workspace from the beginning because any feature caches coming from the PNG may be triggered first which will result in the main basemap being over the inset maps. Click the drop-down next to Run and select Rerun Entire Workspace.
After the workspace has finished running, inspect the output using Visual Preview. The inset maps should be on top of the basemap with a black border surrounding the entire map.
Note: If the inset maps are below the basemap, ensure that you reran the entire workspace. Otherwise, confirm that the MainMap reader is listed first in the Navigator window. If it is not, you can drag it above the Insets reader. This will force the MainMap reader to run first.
Comments
0 comments
Please sign in to leave a comment.