News entry thumbnail
It's Groovy Week: Create complete networks with Nodes and Links
28.06.2018 by Thorsten Reitz, Simon Templer

It’s Thursday, or as we at wetransform (thanks to the influence of a certain Venezuelan on the team) call it, Juernes!

In this fourth installment of the Groovy Scripting week, we will tackle another non-trivial case: Building a complete network with nodes and links when your only input data was a bunch of spaghetti lines. This actually requires three scripts. It also shows in detail how to use priorities and other advanced features.

Like the previous posts, note that this article assumes you have working knowledge of hale studio and know the terminology.

In many projects, we did not receive a fully consistent set of Nodes and Links from customers to create a complete Network, or there were no Nodes available at all.

These three snippets extract the first and last Coordinates from each Link (LineString/Curve) and then set up the Node objects, and then create bidirectional references.

Collect Nodes and connected Segment IDs

This is a simple Groovy Retype function that uses the links as a source. The target does not matter, since no target objects are emitted. In this example, the segments are called vaarwegvakken, and the IDs of these segments are stored in the field vwk_id. This function needs to be executed first and should thus have the highest execution priority.

This is the full script:

You can download this script here.

This snippet is used in a Groovy Create function that has the Node type as a target. This function has to be executed second and needs to have the higher execution priority.

This script also shows how to create a geometry from a coordinate, using a specific coordinate Reference system.

You can download the script here.

In the final step, we add the references from the Links to the nodes created before, so that we have a fully navigable graph in the transport network. This script is inside a normal Groovy Function that has the domain ID of source as the source property and either the startNode or endNode property of the Link as the target property. The surrounding type transformation needs to have a normal execution priority so that it runs after the two other functions.

You can download this script here.

Happy transforming!