span8
span4
span8
span4
Rasters are often large datasets. One way of reducing file sizes is by clipping the raster to only the 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, by using a parks polygon shapefile.
RasterClipping.fmwt(completed workspace template)
ClipperData.zip(contains MrSID orthophoto and parks_polygon shapefile)
1. Read in MrSID file
In a blank workspace, add aLizardTech MrSIDReader to the canvas. Browse to the BCVAN15_W17.sid file. This orthophoto is an area in Vancouver, BC that has two different parks within the 800 by 500-meter squared area. These parks are Caribou Park and Carleton Park.
Add a LizardTech MrSID Reader to read in the BCVAN15_W17.sid dataset
2. Add in Alpha Band
When we clip the raster, it will create a bounding box around the polygon, which will color the NoData black. To remove the black NoData area, we can make it transparent. To do this, we will add in the Alpha8 band. Connect aRasterBandAdder变压器MrSID功能类型。在帕拉meters, set the Interpretation Type to Alpha8, and set the Cell Value to 255. This will create an Alpha8 band with a default value of 255, with is completely opaque, so anywhere our raster is, it will be opaque, but wherever there is a NoData value, it will be transparent.
BCVAN15_W17.sid viewed in the Data Inspector before adding the Alpha8 band
RasterBandAdder parameters, set the Interpretation Type to Alpha8 and the Cell Value to 255
BCVAN15_W17.sid viewed in the Data Inspector after adding the Alpha8 band, notice that there is no change to the image appearance, just the properties.
3. Read in parks polygons
Now that the raster has been read in, we need to read in the parks polygons to have something to clip the raster with. Add aShapefileReader to the canvas, and browse to the parks_polygons.shp file.
Sample of the entire parks_polygons.shp, containing the parks of interest
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 theClippertransformer. Add the Clipper to the workspace, connect the Clippee Input port to the Output port on the RasterBandAdder, and then connect the Clipper Input port to the park_polygons feature type. In the parameters, under the Raster section, ensure Preserve Clippee Extent is set to No, this will ensure that the raster is clipped completely to the perimeter of the parks polygon and that each clipped output is a separate feature. Also, enable Merge Attributes, then set Accumulation Mode to Merge Clipper, this will merge the park name and other attributes with the clipped raster.
Clipper parameters, set Preserve Clippee Extents to No, and enable Merge Attributes
Output of the Clipper with the Alpha8 band added, the space surrounding the park is transparent
Output of the Clipper without the Alpha8 band, the park has a black border
Note:if you set the Clipper parameter Preserve Clippee Extent 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 useful when a clipped raster will replace a tile in some grid system or will use 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 that is surrounding each clipped raster will remain transparent. Add aGeoTIFFwriter to the canvas and connect it to the Inside Output port on the Clipper. In the GeoTIFF parameters, set the Raster File Name to the attribute PARK_NAME, this will fanout the two parks into separate GeoTIFF files by park name.
GeoTIFF Writer Feature Type parameters, set the Raster File Name to PARK_NAME
Output file names
Data Attribution
The data used here originates from open data made available by theCity of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
In the nextexercise, learn how to mosaic multiple adjacent rasters together to create one image.
© 2019 Safe Software Inc |Legal