Read Parameters
The following code is the snippet to read parameters in WASDI.
Prerequisites
- To run this code you need:
A running Python 3.x Environment
A valid WASDI Account
A valid Config file
A valid params.json file
If this is not clear, you probably need to take a look at the Python Tutorial before.
Recipe
Note
Assume we have a params.json file (configured in config.json)
This is our sample params.json file.
{
"STRING_PARAM": "SAMPLE",
"INT_PARAM": 2,
"BBOX": {
"northEast": {
"lat": 20.1,
"lng": -71.4
},
"southWest": {
"lat": 17.9,
"lng": -74.9
}
},
"DATE": "2024-01-01"
}
This is the code used to read Parameters.
# Read the String Parameter
sStringParameter = wasdi.getParameter("STRING_PARAM")
# Read the String Parameter, with a Default value if the param is missing in the params.json file
sStringParameterWithDefault = wasdi.getParameter("STRING_PARAM", "My Default")
# Read the Area of Interest
oBbox = wasdi.getParameter("BBOX", None)
# Read the integer value without any default
iIntegerValue = wasdi.getParameter("INT_PARAM")
# Read the string-formatted Date
sDateString = wasdi.getParameter("DATE")
#This method return a Key-Value Dictionary with all your parameters
aoAllParametersDictionary = wasdi.getParametersDict()
What it does:
reads different parameters
reads the full parameters dictionary at once
Note
The developer can decide whatever is needed in the params.json file. If you decide to use the WASDI User Interface your parameters will be generated automatically by WASDI.
Note
With the WASDI User Interface you can use the renderAsStrings flag to ask WASDI to get all your parameters in String Format. In this case, you will be responsible to convert your data in your code.
Note
The Boundig Box Format used here is the same one used by the User Interface when renderAsStrings is missing or false. The Boundig Box fromat when renderAsStrings: true is “NORTH,WEST,SOUTH,EAST”.
Note
The Date is formatted by the User Interface as “YYYY-MM-DD”.