Pilot NoiseModelling with scripts

In this tutorial, we describe the different ways to pilot NoiseModelling thanks to scripts. To do so, we will use a dedicated packaging of NoiseModelling, called NoiseModelling_4.0.0_without_gui, in which the GUI has been removed (no more Geoserver and WPS Builder).

  1. Go to the NoiseModelling latest release page
  2. Download and unzip the NoiseModelling_4.0.0_without_gui file

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

  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 \ and the drive name.

Requirements

Warning

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

1. Simple command line

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

1
2
3
cd /home/user/NoiseModelling_4.0.0_without_gui/

./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/ground_type.shp

./bin/wps_scripts instruction allows to launch the wps_scripts.sh or wps_scripts.bat (depending on if you are on Linux / Mac or Windows) file, which is located in the bin/ directory.

Warning

Adapt /home/user/ address with your own situation

2. Bash script

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#! /bin/bash

# Run the get started turorial
# https://noisemodelling.readthedocs.io/en/latest/Get_Started_Tutorial.html

# Step 4: Upload files to database
# create (or load existing) database and load a shape file into the database
./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/ground_type.shp
./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/buildings.shp
./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/receivers.shp
./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/ROADS2.shp
./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/dem.geojson


# Step 5: Run Calculation
./bin/wps_scripts -w ./ -s noisemodelling/wps/NoiseModelling/Noise_level_from_traffic.groovy -tableBuilding BUILDINGS -tableRoads ROADS2 -tableReceivers RECEIVERS -tableDEM DEM -tableGroundAbs GROUND_TYPE

# Step 6: Export (& see) the results
./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Export_Table.groovy -exportPath LDAY_GEOM.shp -tableToExport LDAY_GEOM

3. Groovy script

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * NoiseModelling is an open-source tool designed to produce environmental noise maps 
 * on very large urban areas. It can be used as a Java library or be controlled through 
 * a user friendly web interface.
 *
 * This version is developed by the DECIDE team from the Lab-STICC (CNRS) and by the 
 * Mixt Research Unit in Environmental Acoustics (Université Gustave Eiffel).
 * <http://noise-planet.org/noisemodelling.html>
 *
 * NoiseModelling is distributed under GPL 3 license. You can read a copy of this 
 * License in the file LICENCE provided with this software.
 *
 * Contact: contact@noise-planet.org
 */

/**
 * @Author Pierre Aumond, Université Gustave Eiffel
 * @Author Nicolas Fortin, Université Gustave Eiffel
 */

import org.h2gis.api.ProgressVisitor
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.sql.Connection

title = 'Tutorial script'
description = 'Long description of tutorial script'

inputs = []

outputs = [result: [name: 'Result output string', title: 'Result output string', description: 'This type of result does not allow the blocks to be linked together.', type: String.class]]


def runScript(connection, scriptFile, arguments) {
    Logger logger = LoggerFactory.getLogger("script")
    GroovyShell shell = new GroovyShell()
    Script scriptInstance = shell.parse(new File(scriptFile))
    Object result = scriptInstance.invokeMethod("exec", [connection, arguments])
    if(result != null) {
        logger.info(result.toString())
    }
}

def exec(Connection connection, input) {

  // Step 4: Upload files to database
  runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
        ["pathFile":"resources/org/noise_planet/noisemodelling/wps/ground_type.shp"])

  runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
        ["pathFile":"resources/org/noise_planet/noisemodelling/wps/buildings.shp"])

  runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
        ["pathFile":"resources/org/noise_planet/noisemodelling/wps/receivers.shp"])

  runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
        ["pathFile":"resources/org/noise_planet/noisemodelling/wps/ROADS2.shp"])

  runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
        ["pathFile":"resources/org/noise_planet/noisemodelling/wps/dem.geojson"])

  // Step 5: Run Calculation
  runScript(connection, "noisemodelling/wps/NoiseModelling/Noise_level_from_traffic.groovy",
        ["tableBuilding":"BUILDINGS", "tableRoads":"ROADS2", "tableReceivers":"RECEIVERS",
         "tableDEM":"DEM", "tableGroundAbs":"GROUND_TYPE"])

  // Step 6: Export (& see) the results
  runScript(connection, "noisemodelling/wps/Import_and_Export/Export_Table.groovy",
        ["exportPath":"LDAY_GEOM.shp", "tableToExport":"LDAY_GEOM"])
}

You can find this script online here