Groovy Week 2020: Building a Bounding Box using a Collector

Groovy Week 2020: Building a Bounding Box using a Collector

Tutorials Groovy hale»studio Tutorial

In our third installment of the 2020 Groovy Week, we are going to cover a typical use case of hale»studio's Collector feature: building a bounding box covering the geometries of all source objects. For an introduction to the powerful Collector feature, make sure to check out our previous post on the subject. Like in the previous Groovy Week posts, note that this article assumes you have working knowledge of hale»studio and know the terminology.

Wednesday's Script: Building a Bounding Box using a Collector (Florian)

A typical use case for calculating a bounding box covering the geometries of all source objects is creating an alignment to the INSPIRE Species Distribution theme. Transforming to this theme typically comprises creating several SpeciesDistributionUnit instances and a single SpeciesDistributionDataset instance which references those units.

When creating the SpeciesDistributionDataset instance, one of the mandatory target attributes to fill is domainExtent which should contain the geographic extent of all contained SpeciesDistributionUnit instances. To achieve this, we will create a bounding box covering all SpeciesDistributionUnit geometries on the fly during the transformation using a Collector. While there exists the specialized function Compute Extent for calculating bounding boxes, using it would require a Merge over all source instances. Using a Collector is more efficient in this case.

hale»studio Groovy script mapping of a geometry property

Instead of using the Rename function to map the source geometry to the SpeciesDistributionUnit, use the following Groovy script:

To assign the calculated bounding to the domainExtent property of the SpeciesDistributionDataset type, use the script below:

Make sure to reduce the priority of the SpeciesDistributionDataset transformation to make sure that it is executed last, i.e. after all SpeciesDistributionUnits are created.

hale»studio Groovy script mapping of the extent property

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.

Happy transforming!