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).
Go to the NoiseModelling latest release page
Download and unzip the NoiseModelling_4.0.0_without_gui file
From that point, NoiseModelling can be executed in 3 different maners:
with simple command lines
with Bash script
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).
1cd /home/user/NoiseModelling_4.0.0_without_gui/
2
3./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#! /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/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/ground_type.shp
9./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/buildings.shp
10./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/receivers.shp
11./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/ROADS2.shp
12./bin/wps_scripts -w ./ -s noisemodelling/wps/Import_and_Export/Import_File.groovy -pathFile resources/org/noise_planet/noisemodelling/wps/dem.geojson
13
14
15# Step 5: Run Calculation
16./bin/wps_scripts -w ./ -s noisemodelling/wps/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/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 * NoiseModelling is an open-source tool designed to produce environmental noise maps
3 * on very large urban areas. It can be used as a Java library or be controlled through
4 * a user friendly web interface.
5 *
6 * This version is developed by the DECIDE team from the Lab-STICC (CNRS) and by the
7 * Mixt Research Unit in Environmental Acoustics (Université Gustave Eiffel).
8 * <http://noise-planet.org/noisemodelling.html>
9 *
10 * NoiseModelling is distributed under GPL 3 license. You can read a copy of this
11 * License in the file LICENCE provided with this software.
12 *
13 * Contact: contact@noise-planet.org
14 */
15
16/**
17 * @Author Pierre Aumond, Université Gustave Eiffel
18 * @Author Nicolas Fortin, Université Gustave Eiffel
19 */
20
21import org.h2gis.api.ProgressVisitor
22import org.slf4j.Logger
23import org.slf4j.LoggerFactory
24import java.sql.Connection
25
26title = 'Tutorial script'
27description = 'Long description of tutorial script'
28
29inputs = []
30
31outputs = [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]]
32
33
34def runScript(connection, scriptFile, arguments) {
35 Logger logger = LoggerFactory.getLogger("script")
36 GroovyShell shell = new GroovyShell()
37 Script scriptInstance = shell.parse(new File(scriptFile))
38 Object result = scriptInstance.invokeMethod("exec", [connection, arguments])
39 if(result != null) {
40 logger.info(result.toString())
41 }
42}
43
44def exec(Connection connection, input) {
45
46 // Step 4: Upload files to database
47 runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
48 ["pathFile":"resources/org/noise_planet/noisemodelling/wps/ground_type.shp"])
49
50 runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
51 ["pathFile":"resources/org/noise_planet/noisemodelling/wps/buildings.shp"])
52
53 runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
54 ["pathFile":"resources/org/noise_planet/noisemodelling/wps/receivers.shp"])
55
56 runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
57 ["pathFile":"resources/org/noise_planet/noisemodelling/wps/ROADS2.shp"])
58
59 runScript(connection, "noisemodelling/wps/Import_and_Export/Import_File.groovy",
60 ["pathFile":"resources/org/noise_planet/noisemodelling/wps/dem.geojson"])
61
62 // Step 5: Run Calculation
63 runScript(connection, "noisemodelling/wps/NoiseModelling/Noise_level_from_traffic.groovy",
64 ["tableBuilding":"BUILDINGS", "tableRoads":"ROADS2", "tableReceivers":"RECEIVERS",
65 "tableDEM":"DEM", "tableGroundAbs":"GROUND_TYPE"])
66
67 // Step 6: Export (& see) the results
68 runScript(connection, "noisemodelling/wps/Import_and_Export/Export_Table.groovy",
69 ["exportPath":"LDAY_GEOM.shp", "tableToExport":"LDAY_GEOM"])
70}
You can find this script online here