In our fourth installment of the 2020 Groovy Week, we are going to take a look at how to map attributes in Groovy type transformation functions and how to use that to create multiple target objects for a single source object. Like in the previous Groovy Week posts, note that this article assumes you have working knowledge of hale studio and know the terminology.
The normal approach to map values of source attributes to the target is to invoke an attribute transformation function like
Groovy Script. These attribute-level functions let you create a target value based on the value(s) of the source attribute(s). Here is an example for a simple
Rename that maps the source
description attribute to the target attribute of the same name. The function is part of the
Retype of the source type
River to the target type
If we replace the type transformation function
Retype by a
Groovy Retype, we can achieve the same result as with the
Rename function by using the
_target instruction in the script:
A typical use case for this is if you need to split one feature into more than one target object with different target attribute values. Here is an example from an INSPIRE Hydrography alignment where one target instance is created for every source geometry:
You can download the script snippets here and here and import them in hale studio as a Groovy snippet by going to File -> Import -> Groovy Snippet. Please note that some scripts use protected functions, so you might need to “Lift Groovy Restrictions” to execute the script. Make sure you replace the placeholder attribute names with your own attribute names.