Converting Vector Data to Raster

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

This article focuses on the process of converting vector data into raster data—a common practice in the field of GIS. We will delve into why this conversion is often necessary, the step-by-step process using FME, and key considerations to bear in mind. Whether you're new to GIS or looking to refine your skills, this guide provides the essential information to help you navigate vector to raster conversion seamlessly. There are many ways FME can be used to convert vector data (points, lines, areas) into raster data. This example focuses on three transformers; the ImageRasterizer, the NumericRasterizer and the VectorOnRasterOverlayer.
 

Step-By-Step Instructions

Part 1: ImageRasterizer

In this scenario, we want to create a raster image of Stanley Park to show the roads and that it is mostly surrounded by water. To do this, we will use the ImageRasterizer transformer. The ImageRasterizer takes 2D vector geometry and converts it to a single raster.
In some cases, multiple ImageRasterizers may be used if different rasterization parameters are required. For example, anti-aliasing is good for contours, but not very good for rectangular tile boundaries - it's the case where we should use two rasterizers for a contour file with a frame. When more than one ImageRasterizer is used, a RasterMosaicker is also required to bring all the rasters into one.

 

1. Open Template Workspace

In FME Workbench, open the ImageRasterizer-Begin.fmwt workspace template. This template has already prepared the data for us, it is reading in a road network AutoCAD DWG, a parks MapInfo TAB file, and a neighborhoods Google KML file. Using this data, a shoreline has been created, and all the data has been clipped to show only Stanley Park. We will need to add color and add the ImageRasterizer.

image.png

 

2. Color Features

Before we rasterize the data, let’s give it some color. Add a FeatureColorSetter transformer to the canvas and connect it to the Passed output port on the SpatialFilter transformer; this will be the color for the roads. In the parameters, change the Color Scheme to Fixed, then set both the Pen Color and the Fill Color to the same color, for example, use black (0,0,0).

image.png

 

Add another FeatureColorSetter to the canvas; this time connect it to the Passed output port on the Tester transformer; this will be the color of Stanley Park. In the parameters, change the Color Scheme to Fixed, then set both the Pen Color and the Fill Color to the same color, for this example, use an emerald green color (0.333333,0.666667,0).
 
Finally, add one more FeatureColorSetter to the canvas, and connect it to the Outside output port on the Clipper transformer. This FeatureColorSetter will color the shoreline. In the parameters, change the Color Scheme to Fixed, then set both the Pen Color and the Fill Color to the same color, for this example, use an ocean blue color (0.333333,0.666667,1).

 

3. Rasterize Image

Now that we’ve colored the features, we can rasterize them. Add an ImageRasterizer transformer to the canvas and connect it to all three of the FeatureColorSetter transformers. In the parameters, set the value for both the Number of Columns (cells) and Number of Rows (cells) to 1000. This value indicates how many cells (or pixels) we want across our new raster image. The smaller the number, the more pixelated the image, the higher the number, the more detailed the image. We will leave the rest of the parameters as the defaults.

image.png

 

4. Run Translation

Add an Inspector transformer and connect it to the Raster output port on the ImageRasterizer, then run the translation. In Visual Preview, your data might have come out in the correct order with roads on top, then the park, then the shoreline or it might not have. We should set the order of our features so that they come out the same way every time.

 

5. Set Order of Features

To set the order of the features, we will create a new attribute called Order with a different value set to each feature, then sort the features in descending order, and then finally set the Input Ordered option in the ImageRasterizer.
Add an AttributeCreator transformer between the FeatureColorSetter that colors the roads and the ImageRasterizer. In the parameters, create a New Attribute called Order and set the Attribute Value to 1. Add a second AttributeCreator between the FeatureColorSetter for the park and the ImageRasterizer. Create a New Attribute called Order and set the Attribute Value to 2. Finally, add a third AttributeCreator for the shoreline, and then create the New Attribute called Order and set the Attribute Value to 3.
Now we will need to sort these attributes, add a Sorter transformer to the canvas and connect all three AttributeCreators to it and then connect the Sorted output port to the ImageRasterizer. In the parameters, set the Attribute to Order, then for Alpha/Num set it to Numeric and the Order to Descending.

image.png

 

6. Re-run Translation

Re-run the translation, this time in Visual Preview, the features should be in the correct order no matter how many times you run this translation.

 

Part 2: NumericRasterizer

The NumericRasterizer transformer rasterized 2D vector geometry just like the ImageRasterizer except that it takes Z values (elevation) into consideration to fill in the background value. In this scenario, we will be taking vector contour lines and creating a raster similar to a Digital Elevation Model (DEM). Although the raster will look like a DEM, it is not a true DEM, to learn how to create an interpolated DEM, see the Creating Rasters and DEMs from Point Clouds article.

 

1. Open FME Workbench

In a blank workspace, add a Shapefile reader to the canvas. For the dataset, browse to the Contours.zip file, which contains all of the contour Shapefiles for the city of Vancouver. FME can read in zip files, so you don’t need to extract it before reading it. Change the Workflow Options to Single Merged Feature Type and click OK to add the reader.

image.png

 

2. Force 3D

The data has a Z value associated with each contour line, but we want to ensure each vertice within the line has a Z value. To do this, we will use a 3DForcer transformer. Add a 3DForcer to the canvas and connect it to the <All> reader  feature type. In the parameters, set the Elevation to Elevation.

 

3. Create Numeric Raster

Now that each vertice has a Z value, we can create the numeric raster. Add a NumericRasterizer transformer to the canvas and connect it to the Output port on the 3DForcer. In the parameters, set the Size Specification to RowsColumns and then set both the Number of Columns (cells) and Number of Rows (cells) to 100. This number depends on your data and might require some trial and error to get it to look the way you want it. Larger numbers will have more holes with no data.

image.png

 

4. Run and Inspect Translation

Finally, add an Inspector transformer to the Raster output port on the NumericRasterizer and then run the translation. In Visual Preview, you will see a black and white image, and if you click on an individual cell, it will have a Z value. Experiment with changing the Number of Columns (cells) and Number of Rows (cells) to see different outputs.

image.png

 

Part 3: VectorOnRasterOverlayer

This last example uses a VectorOnRasterOverlayer transformer to overlay vector data on a raster. In this scenario, we want to create a map that shows road closures for an upcoming parade. We have a vector line dataset that contains the closed roads, and a raster orthophoto of the area of interest.

 

1. Open the Template File

To begin, open the VectorOnRasterOverlayer-Begin.fmwt workspace template file in FME Workbench. This workspace already has the GeoTIFF orthophoto and the RoadClosure Shapefile. The RoadClosure Shapefile is a vector line, which has been colored red using the FeatureColorSetter. It also contains many road lines, one for each block, so they have been combined into one line per StreetName using the LineCombiner transformer. Finally, the road line is too thin, so it has been buffered to create a thicker line using the Bufferer transformer. Labels have also been created for each of the closed roads using the Labeller transformer.

 

2. Overlay Vector on Raster

Add a VectorOnRasterOverlayer transformer to the canvas, connect the Vector input port to both the Buffered output port on the Bufferer and the Label output port on the Labeller. Then connect the Raster input port to the GeoTIFF. The default parameters are ok.

image.png

 

3. Run the translation

Add an Inspector to the Raster output port on the VectorOnRasterOverlayer and then run the translation. Inspecting the data in Visual Preview, you will see the Road Closure line has been rasterized, but the labels are missing. This is because the labels are not a vector or a raster feature, we will have to fix that.


 

4. Vectorize labels

To vectorize the labels, we will need to use a TextStroker transformer. Add a TextStroker transformer to the canvas and connect it between the Labeller and the VectorOnRasterOverlayer. In the parameters set the Stroked Geometry Type to Polygon Features and then set the Font Name to Franklin Gothic Demi and set the size to 28. Click Ok. Re-run the translation and inspect the output.

image.png

 

image.png

 

Data Attribution

The data used here originates from 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.