FME Version
Files
-
- 80 KB
- Download
Introduction
With FME Server and FME Desktop, we can use an area of interest polygon (e.g. a city boundary) to clip a set of user-specified layers that fall within it This is different than the more traditional approach of reading the entire set of layers and then clipping the features.
To perform this task, the FeatureReader transformer will be used. This transformer lets us use any format and actually allows for spatial filters to be applied to the user-specified layer.
As well, the FeatureReader allows you to write data dynamically into destination feature types for any table that it reads. This happens via a <Schema> port that provides the writer with the schema definition to use. This method is incredibly flexible as different data layers can be read into the workflow and then written out.
Step-by-step Instructions
1. Read the Boundary Dataset
This is the feature that will be used to filter our desired data spatially. All features that are found within this boundary will be read into the workflow.
Add a new Mapinfo Tab reader to the canvas.
Format: MapInfo TAB (MITAB)
Dataset: <FME Data>\Zoning\Zones.tab
2. Add a User Parameter for Zone Type
This option will allow flexibility for the end user by allowing them to select different boundaries based on the type of zone they choose (e.g. industrial vs. residential). In the Navigator, right click on the Published Parameters and select ‘Add Parameter’. Create a new ‘Choice‘ parameter and import the Zone Types from the MapInfo file.
a) Right click on Published Parameters in the Navigator and select 'Add'. Enter the following:
b) Click on the Configuration button and choose 'Import' on the following screen:
c) Read the Zones .Tab file and setup import mode:
Click 'Next'.
Click 'Import' to bring in the Categories.
Select 'OK' to save the parameter.
Extra Credit
Using a Web Mapping Tool: If your users are drawing the area of interest in some kind of web mapping tool, you could send the vertices of this polygon to a new published parameter, then create a polygon from these vertices using the Creator and a combination of transformers.
Using Where Clause: If your users are selecting the area of interest by adding a reader, you could publish a Where Clause for that reader (if applicable for the format) to provide the user flexibility. (in our example, Mapinfo does not have this functionality so we must create a parameter)
Both of these methods above can be combined in a single workspace, giving users either option.
3. Creating the Boundary Feature
Each zone category in the zones dataset is made up of multiple polygons. As we want to use a single zone as a boundary, we need a way to aggregate these features into an organized feature. To do this, we will use the Dissolver, Aggregator and Tester transformers.
a) Place the Dissolver on the canvas connected to the MITAB reader and set the following:
Group By: ZoneCategory
b) Add an Aggregator:
Group By: ZoneCategory
c) Add a Tester using our published parameter (TYPE):
Left value: ZoneCategory Operator: = Right Value: $(TYPE)
4. Read Data to be Filtered
At this stage, we will read the actual data layers that we are interested in and which will be written out via a writer. This is the data that we want to be filtered by the boundary polygon.
Add a FeatureReader to the Canvas and connect it to the Tester. Then set the following:
Format: PostGIS
Dataset: Embed Connection Parameters
PostGIS credentials:
Host | postgis.train.safe.com |
Port | 5432 |
Database | fmedata |
User | fmedata |
Password | fmedata |
Feature Types to Read: public.Parks ( type this text or use the ‘…’ button to search)
Spatial Filter: Contains
Output > Output Ports: Single Output Port
Output > Attribute and Geometry Handling > <Generic Port> > Attributes to Expose: fme_feature_type
Select 'Ok'.
Run the workspace and inspect the output. You should notice that only the park data that exists inside your selected boundary polygon remains. At this stage only Parks would be read into the workspace so we can improve the flexibility by giving the users a choice of layers.
5. Give the User a Choice of Layers to Read
To do this, a second published parameter needs to be created to allow users to select which layers (i.e., feature types) they want. In the FeatureReader, select the dropdown arrow next to ‘Feature Types’ and choose ‘User Parameter > Create User Parameter’, then select Fixed List to choose from layers stored in the database. Select: ‘public.Roads, public.Parks and public.AddressPoints’ and then choose 'OK' to create the parameter.
Extra Credit
You can also create the parameter as a text field. A text field allows options to be entered that didn't exist when the workspace was authored; they need to be manually input or passed in via another program such as a web application that uses FME Server. You will send the user's choices to this parameter as a space-delimited list. For example: “AddressPoints Parcels Neighborhoods”.
6. Write the Data in Dynamic Mode
Since the workspace is quite flexible in what it can read, the writer will need to be setup in dynamic mode to ensure that the data can be written out.
Add a Generic writer to the canvas and select ‘Autodesk Autocad DWG/DXF’ as the format to use in the parameters. When the workspace is run, you can change this to any format you’d like when prompted (powerful!).
Note: The workspace will work as is for file and folder based formats. For other formats such as cloud-based and databases, it is necessary to set additional writer parameters, to specify and connect to the desired destination.
The Generic format allows the user to have a choice of format. Then set the mode to Dynamic and Schema Source as “Schema from Schema Feature”.
In order to write out data in FME, the writer feature type needs to know the schema that it will use. In this case we need to use the data from the FeatureReader as our schema.
Note: To use fixed schema mode (not shown in this example) you will need to add a writer and destination feature types for any table the user may possibly read. Use the FeatureTypeFilter transformer to route the features to the appropriate destination feature type.
7. File - Prompt and Run to Test with Different Choices of Tables.
Now use the Prompt and Run option to execute the workspace. Try different Zone Types and Tablenames to generate different sets of output.
What is happening is that the FeatureReader transformer is triggered by the Initiator feature. In our case, this is the set of bounding polygons of Zone data. If we have 10 bounding polygons then the FeatureReader is executed 10 times. Performance is best if there are fewer Initiator features.
When the FeatureReader is initiated it connects to the format and reads the feature types specified in the TableNames parameter. The transformer allows for Spatial Filtering so using the "Contains" clause means that the features that are returned are contained by the Initiator polygons. Then the writer dynamically takes all the features and writes them to their respective layers based on the incoming layer name and schema. Any features that fell outside of our bounding box are not included.
Comments
0 comments
Please sign in to leave a comment.