NoiseModelling client line interface (CLI)

In this tutorial, we describe the different method to pilot NoiseModelling thanks to scripts. To do so, we will use a separate command-line interface, called ScriptRunner, in which the GUI has been removed (no more WPS Builder).

From that point, NoiseModelling can be executed in 3 different manners:

  1. with simple command lines

  2. with Bash script

  3. with Groovy script

To illustrate, users are invited to reproduce the tutorial “Get Started - GUI” in command lines.

Note

This tutorial is mainly dedicated to advanced users.

Warning

The URL is here adapted to Linux or Mac users. Windows user may adapt the address by replacing / by \ in the folders paths.

Requirements

Warning

For all users (Linux , Mac and Windows), please make sure your Java environment is well configured. For more information, please read the page Requirements.

1. Simple command line

Using the terminal of your operating system

Below is an example of a bash instruction, executing the Noise_level_from_traffic.groovy WPS Script (located in the directory scripts/). This block has 5 arguments corresponding to the input table names (for buildings, roads, receivers, dem and ground type).

1cd /home/user/NoiseModelling/
2
3./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Import_File.groovy --pathFile resources/ground_type.shp

Warning

Adapt /home/user/NoiseModelling address with the real installation folder of NoiseModelling. Use the appropriate ./bin/ScriptRunner or ./bin/ScriptRunner.bat (depending on if you are on Linux / Mac or Windows) file, which is located in the bin/ directory.

2. Bash script

Below is an example of a sequence of simple .groovy scripts, using bash instructions and launching the steps described in the “Get Started - GUI”.

 1#! /bin/bash
 2
 3# Run the get started turorial
 4# https://noisemodelling.readthedocs.io/en/latest/Get_Started_Tutorial.html
 5
 6# Step 4: Upload files to database
 7# create (or load existing) database and load a shape file into the database
 8./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Import_File.groovy --pathFile resources/ground_type.shp
 9./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Import_File.groovy --pathFile resources/buildings.shp
10./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Import_File.groovy --pathFile resources/receivers.shp
11./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Import_File.groovy --pathFile resources/ROADS2.shp
12./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Import_File.groovy --pathFile resources/dem.geojson
13
14
15# Step 5: Run Calculation
16./bin/ScriptRunner -w ./ -s scripts/NoiseModelling/Noise_level_from_traffic.groovy --tableBuilding BUILDINGS --tableRoads ROADS2 --tableReceivers RECEIVERS --tableDEM DEM --tableGroundAbs GROUND_TYPE
17
18# Step 6: Export (& see) the results
19./bin/ScriptRunner -w ./ -s scripts/Import_and_Export/Export_Table.groovy --exportPath RECEIVERS_LEVEL.shp --tableToExport RECEIVERS_LEVEL

3. Groovy script

Below is an example of a complex .groovy script, launching the different steps described in the “Get Started - GUI”.

 1import org.h2gis.api.ProgressVisitor
 2import org.noise_planet.noisemodelling.scripts.Import_and_Export.Export_Table
 3import org.noise_planet.noisemodelling.scripts.Import_and_Export.Import_File
 4import org.noise_planet.noisemodelling.scripts.NoiseModelling.Noise_level_from_traffic
 5import org.slf4j.Logger
 6import org.slf4j.LoggerFactory
 7import java.sql.Connection
 8
 9title = 'Tutorial script'
10description = 'Long description of tutorial script'
11
12inputs = [:]
13
14outputs = [result: [name: 'Result output string', title: 'Result output string', description: 'Result table name. Can be used as input for another WPS process', type: String.class]]
15
16def exec(Connection connection, Map input, ProgressVisitor progress) {
17    Logger logger = LoggerFactory.getLogger("tutorial")
18    ProgressVisitor tutorialProgress = progress.subProcess(7)
19    // 7 steps in this task
20
21    // Upload files to database
22    new Import_File().exec(connection, ["pathFile": "resources/ground_type.shp"], tutorialProgress)
23
24    new Import_File().exec(connection, ["pathFile": "resources/buildings.shp"], tutorialProgress)
25
26    new Import_File().exec(connection, ["pathFile": "resources/receivers.shp"], tutorialProgress)
27
28    new Import_File().exec(connection, ["pathFile": "resources/ROADS2.shp"], tutorialProgress)
29
30    new Import_File().exec(connection, ["pathFile": "resources/dem.geojson"], tutorialProgress)
31
32    // Run Calculation
33    new Noise_level_from_traffic().exec(connection, ["tableBuilding": "BUILDINGS", "tableRoads": "ROADS2", "tableReceivers": "RECEIVERS",
34                                                     "tableDEM"     : "DEM", "tableGroundAbs": "GROUND_TYPE"], tutorialProgress)
35
36    // Export the results in a file
37    new Export_Table().exec(connection, ["exportPath": "RECEIVERS_LEVEL.shp", "tableToExport": "RECEIVERS_LEVEL"], tutorialProgress)
38
39    logger.info("Result have been exported to " + new File("RECEIVERS_LEVEL.shp").getAbsolutePath())
40}

You can find this script get_started_tutorial_complex.groovy on the installation folder of NoiseModelling

To run it use this bash command.

1./bin/ScriptRunner -w ./ -s get_started_tutorial_complex.groovy