Raster Clipping

Ali Mokheamer
Ali Mokheamer
  • Updated

FME Version

Introduction

Rasters are often large datasets. One way to reduce file sizes is to clip a raster to only an area of interest. This can be accomplished by using the Clipper transformer and a polygon feature. In this example, we will clip an orthophoto of Vancouver and extract only the part containing parks using a park's polygon shapefile.
 

Step-by-Step Instructions

In this step-by-step tutorial, you will learn how to add an Alpha8 band to an orthophoto image file using the RasterBandAdder transformer. Then, you will clip the orthophoto image file using a polygon feature with the Clipper transformer.

 

1. Read in MrSID File

Start FME Workbench, and in a blank workspace, add an Extensis MrSID Reader. Browse to the "BCVAN15_W17.sid" dataset. This orthophoto shows an area in Vancouver, BC, with two different parks within the 800 by 500-meter square area: Caribou Park and Carleton Park.

mrsid-reader.png

 

2. Add in Alpha Band

Clipping the raster will create a bounding box around the polygon, which will color the NoData black. To remove the NoData area, we can make it transparent. To do this, we will add an Alpha8 band. Add a RasterBandAdder transformer to the canvas and connect it to the MrSID reader feature type. Double-click on the RasterBandAdder transformer, and in its parameters, set the Interpretation Type parameter to "Alpha8" and the Cell Value parameter to "255". This will create an Alpha8 band with a default value of 255, which is entirely opaque. Now, wherever our raster is, it will be opaque but transparent wherever there is a NoData value.

mrsid-dataset-in-preview.png

rasterbandadder-transformer.png

mrsid-with-alpha-band-preview.png

 

3. Read in Parks Polygons

Now that the raster has been read with an Alpha8 band added, we need to read in the park's polygons to have something to clip the raster with. Add an Esri Shapefile Reader and set the Dataset parameter to the "parks_polygons.shp" dataset.
shapefile-reader.png

shapefile-on-map.png

 

4. Clip the Raster to the Polygons

Now that we have added the data we want to clip and the data we want to clip with, we can use the Clipper transformer. Add a Clipper transformer to the canvas and connect the Output port on the RasterBandAdder to the Candidate Input port on the Clipper transformer. Then, connect the Shapefile reader feature type to the Clipper Input port. Double-click on the RasterBandAdder transformer, and in its parameters, under the Raster Candidates parameter group, make sure that the Preserve Raster Extents parameter is set to "No". This will ensure that the raster is entirely clipped to the perimeter of the park's polygon and that each clipped output is a separate feature. Also, enable the Merge Attributes parameter and then set the Accumulation Mode parameter to "Merge Clipper". This will merge the park name and other attributes with the clipped raster's features.

clipper-parameters.png

clipped-raster-test.png

If you set the Clipper parameter Preserve Candidate Extents to "Yes", the rasters created will each be the same size as the original raster with the area around the clipped data set to "0". This option may be helpful when a clipped raster replaces a tile in some grid system or uses the same external geo-referencing file as the original.

 

5. Write Out to GeoTIFF

We will write out to GeoTIFF because it accepts Alpha bands, so the NoData band surrounding each clipped raster will remain transparent. Add a GeoTIFF Writer and set the Dataset parameter to a file path of your choice. Connect the Inside Output port on the Clipper to it. Double-click on the writer feature type, and in its parameters, set the Raster File Name parameter to the attribute "PARK_NAME" using the drop-down arrow to the right of it (i.e., Attribute Value > "PARK_NAME"). This will fanout the two parks into separate GeoTIFF files by their park name. Run the workspace.

geotiff-writer.png

geotiff-writer-parameters.png

output.png

 

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.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.