The green shape is a 3D polygon. Consider calculating its perimeter and area in 2D or 3D.
The calculation itself is easy. Just use a LengthCalculator and an AreaCalculator.
Parameter Settings
Transformer | Parameter Name | Choice for 2D | Choice for 3D |
---|---|---|---|
LengthCalculator | Length Dimension | 2 | 3 |
AreaCaluculator | Type | Plane Area | Sloped Area |
Now, assume that there is a requirement that either 2D or 3D has to be determined through a user parameter at run-time.
It's easy to create two published parameters linked to the two transformer parameters separately, but the user will have to always be careful of their consistency. Ideally, it's better that the two parameter values can be specified simultaneously through setting just one published parameter. In other words, the two parameter values should be synchronized.
If value choices of the two transformer parameters were same, you could link both of them to the same user parameter. However, as shown in the table, those are different in fact.
In such a case, I would create a published parameter and a private scripted parameter so that value of the private parameter would be determined depending on value of the published parameter.
For example:
Published Parameter
Type: Choice
Name: DIM
Configuration: 2%3
Private Parameter
Type: Scripted (Python) or Scripted (Tcl)
Name: AREA_TYPE
-----
# Parameter Value (Python Script) Example
return 'Plane Area' if FME_MacroValues['DIM'] == '2' else 'Sloped Area'
-----
# Parameter Value (Tcl Script) Example
if {$FME_MacroValues(DIM) == 2} {set t "Plane Area"} else {set t "Sloped Area"}
return $t
-----
This Tcl script is also available.
-----
array set a {2 "Plane Area" 3 "Sloped Area"}
return $a($FME_MacroValues(DIM))
-----
Other than the LengthCalculator and AreaCalculator, there are several transformers which have a parameter choosing 2D or 3D. Parameter names and value choices are various.
Transformer | Parameter Name | Choice for 2D | Choice for 3D |
---|---|---|---|
MeasureGenerator | Length Dimension | 2 | 3 |
Snipper | Measurement Mode | 2D | 3D |
GeometryValidator (Duplicate Consecutive Points) | Check Z Values | No | Yes |
=====
At first, I expected that I could do that with "Choice with Alias" parameter, rather than script.
-----
Type: Choice with Alias
Name: AREA_TYPE
Configuration: 2,Plane<space>Area%3,Sloped<space>Area
Default Value: $(DIM)
-----
But unfortunately value of this parameter became the same value as $(DIM), i.e. 2 or 3.
Why not?
No comments:
Post a Comment