Groovy Week 2020: Mapping Attributes on the Type Level to Split a Feature

Groovy Week 2020: Mapping Attributes on the Type Level to Split a Feature

Tutorials Groovy hale»studio Tutorial

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.

Thursday's Script: Mapping Attributes on the Type Level to Split a Feature (Florian)

The normal approach to map values of source attributes to the target is to invoke an attribute transformation function like Rename, Classification or 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 Watercourse.

hale»studio simple mapping of a property

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:

Download

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:

Download

You can download the script snippets 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.

Happy transforming!