This is the second installment of our “Groovy week”. This time, we are going to look into a powerful feature in hale studio that is used by the Spatial Join function, but can also be accessed through scripting - the spatial index.
Like the previous post, note that this article assumes you have working knowledge of hale studio and know the terminology.
We used this script to build up references from boundaries to four levels of administrative units. In the original data, such references were not explicit, with the exception of international borders.
The script first identifies possible candidate
AdministrativeUnit polygon geometries through the index and then verifies that the boundary object indeed matches the boundary of the polygon. It then constructs references differently, depending on the level of the identified
AdministrativeUnit. As a result of this script, an
AdministrativeBoundary target object can have references to up to six
AdministrativeUnits - if it happens to be a boundary that separates 5th level, 4th level and 2nd level on both sides.
The execution context is in a Groovy Retype function.
This is the full 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 assumes a certain geometry attribute name (
the_geom) that you might have to change. The additional attributes accessed here, such as
ICC, will not be available in your source data.
We have thus included a simpler call to the spatial index as a second example: