Ex4 - 3D data transformation

Introduction

The data used in this exercise is based on open data from the City of Vancouver, Canada.

This exercise asks you to assume the role of a city planner at the city of Vancouver.

A new property development is being planned within the city. The planning department has asked for a 3D visualization of the city elevation model, taking this new development into account.

The task is to read the current elevation model, apply the changes provided by the property developer, and create a three-dimensional output in Adobe PDF format.

Your manager has handed you this task, thinking that it will be very difficult. He doesn't know FME as well as you do!

Objectives

Create a 3D pdf with FME, with certain parameters based on a configuration file.

The config file will define the picture resolution and the topographic exaggeration scale.

Resulting PDF : https://s3.eu-central-1.amazonaws.com/training.insersa.ch/FME/geopython2019/results/SurfaceModel_hd.pdf [18 MD]

https://inser.gitbooks.io/fme-python-course/content/assets/hgrtimport.png

Workspace description

Contour lines are read and processed :https://inser.gitbooks.io/fme-python-course/content/assets/sgrthimport.pngHere we have two sets of contours lines (new and old). The ChangeDetector transformer will tell us which contours are new in this dataset, which are replacements, and which are the same as before.

Did you notice that the added contours do not have an elevation value set? This is a problem because we can't generate a proper 3D model without elevation! It must be that the labels in the source data are meant to denote the contour elevation (you can use the Data Inspector to open the data and confirm this is so).

Therefore the labels are read and the _NeighborFinder _transformer will transfer the label values onto the nearest contour.

Vancouver is a quite flat city, so why not exaggerate the Z scale a little by using the ExpressionEvaluator.

Having an elevation attribute is fine, but to actually create a 3D model we must convert this into a true Z value. This is done with a _3DForcer _transformer

Now we have 3D contours and we can create our surface model :

https://inser.gitbooks.io/fme-python-course/content/assets/tfshjimport.png

https://inser.gitbooks.io/fme-python-course/content/assets/rtjhgimport.png

And add the texture :

https://inser.gitbooks.io/fme-python-course/content/assets/sgdfgfimport.png

The AppearanceSetter is used to apply the raster as an "appearance" or texture onto the DEM surface. The Raster data is the Appearance and the TINSurface port is the Geometry.

The RasterResampler allows us to reduce the size of the pictures to a more manageable size.

We extrude the building footprints :

https://inser.gitbooks.io/fme-python-course/content/assets/%3csgfdhimport.png

And finally export it as a PDF :

https://inser.gitbooks.io/fme-python-course/content/assets/d%3cgdfimport.png

You can open the PDF in the output folder.

You may get this initial warning :

https://inser.gitbooks.io/fme-python-course/content/assets/sadfsfimport.png

Just click :

https://inser.gitbooks.io/fme-python-course/content/assets/asfsdfimport.png

and after click on

https://inser.gitbooks.io/fme-python-course/content/assets/oopimport.png

Exercise

This wokspace works fine as it is. But now you would like to send it to people that have never used FME before. Of course, you don't want them to open the workspace and break anything by accident. The solution is to create a external config file, in this case it will be an INI file.

You will add the following parameters to the config file :

  • "raster_size" which is a percentage of compression of the inital picture.You may have noticed that the output file is quite big (about 99 MB).
  • "vertical_scale" . If Vancouver seems a little flat, then why not exaggerate the Z scale a little to compensate!

1) Create the config file

In the FME project folder (C:\FME_data\Ex4 - 3D data transformation), create a txt file with notepad++ named "config.ini" with the following lines:


[picture]

raster_size =  20

[contours]

vertical_scale = 4

Use Nopepad++ to avoid any encoding issue.

2) Create the first scripted parameters

Can create a new parameter this way :

https://inser.gitbooks.io/fme-python-course/content/assets/asfdsimport.png

Select Scripted (python)

https://inser.gitbooks.io/fme-python-course/content/assets/dsagASSimport.png

And as a value enter the folowing code :


import ConfigParser

config = ConfigParser.RawConfigParser()

config.read('config.ini')

return config.get('picture', 'raster_size')

Close the two windows.

Now you can go to the RasterResampler transformer and open it up (just double click on it).

https://inser.gitbooks.io/fme-python-course/content/assets/fhnsgfimport.png

In the main window, link the percentage value to the new parameter

https://inser.gitbooks.io/fme-python-course/content/assets/fdgdfgimport.png

The parameter now defines the behaviour of this tranformer.

3) Add the second parameter

The second parameter is the vertical scale factor. We will define it in a slightly different way.

First, double click on the ExpressionEvaluator transformer.

In the Private Parameters panel, click on the

https://inser.gitbooks.io/fme-python-course/content/assets/dfhgfhgfimport.png

It will open up the same window as before.Select "Scripted (python)" as type, and name the parameter "vertical_scale". Add the following lines as value :


import ConfigParser

config = ConfigParser.RawConfigParser()

config.read('config.ini')

return config.get('contours', 'vertical_scale')

Back to the transformer window, replace the constant "4" with the new parameter as follows :

https://inser.gitbooks.io/fme-python-course/content/assets/sgifhgfhjmport.png

4) Run the workspace

Run the workspace and play around to see the effect of the parameters.

A scale factor of 20 will really exagerate the topography.

https://inser.gitbooks.io/fme-python-course/content/assets/dasgdfimport.png

Working with parameters is mainly useful when deploying one workspace in different environments (development env., test env. , User acceptance testing env. production env.). Paths and credentials can be easily adapted to the environment without changing the workspace.

Advanced task

It could be nice if you could add all the input paths as parameters. Furthermore, the output PDF file must be in a folder containing the date of the day.