It’s Groovy Week: Free scripts for hale»studio

It's Groovy Week: Free scripts for hale»studio

Tutorials Groovy hale»studio Tutorial

When you try to do something in hale»studio that isn’t possible with the out-of-the-box functionality, it offers several ways of creating that functionality yourself. The most accessible of these is to add your own transformation functions using Groovy scripting. There are several points where Groovy functions can be added:

  • Type Transformation Functions
  • Property Transformation Functions
  • Custom Functions
  • Post-processing scripts (only through the CLI)

Groovy is superset of Java, i.e. any valid Java program is also a valid Groovy program. What it makes much easier than Java is the creation of data structures – no boilerplate constructors and initialisation and the like. Here are some key resources for learning Groovy:

Often, you will be looking for some recipes and snippets to get started, and that is exactly what we will provide during this week: We will publish one Groovy Snippet per day. Each of my colleagues has selected their favourite script and will share it with all of you ?.

Please note that this article assumes you have working knowledge of hale studio and know the terminology.

The Groovy Logo, by Zorak1103, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=13358930

Monday's Script: Build Polygons from Lines (Thorsten)

This script is my personal favorite. While relatively complex, it shows a lot of useful approaches how to work with geometries in a Groovy script.

This function was built for creating waterbody Polygons from LineString shore segments. It is executed in the context of a Merge type cell as a Greedy Groovy Script function. It takes a MultiLineString geometry with unsorted individual LineStrings and builds one to many polygons in a MultiPolygon from that input.

This is the script:

You can download this script here and import it in hale studio as a Groovy snippet by going to File -> Import -> Groovy Snippet. Please note that it uses some protected functions, so you need to "Lift Groovy Restrictions" to execute the script. It furthermore assumes a certain geometry attribute name (the_geom) that you might have to change.

Happy transforming!