Think 2021: New tools have the developer ecosystem and IBM building together Learn more

Build a water quality dashboard with GeoJSON and Node-RED

This tutorial is part of the 2021 Call for Code Global Challenge.

The example Node-RED flows and dashboards can help you build a water quality dashboard using GeoJSON. After completing this tutorial, you will be ready to modify these example flows and dashboards to create your own map and data visualization solution.

The Node-RED flows in this tutorial demonstrate how to display US Geological Survey (USGS) watershed maps on a Node-RED dashboard. Several examples describe how to query the watershed area maps of Ridgewood, NJ and Atlanta, GA using the USGS Hydro Network-Linked Data Index, and then plot the water basins and rivers on a Node-RED dashboard.

The USGS NLDI API returns a GeoJSON set of latitude / longitude coordinates and features that can be plotted using the node-red-contrib-web-worldmap node. To generate your own map, visit http://geojson.io which allows you to quickly generate a geojson file.

Water sustainability requires protecting the groundwater and sub-surface aquifer from dangerous / toxic pollutants. Aquagenuity helps everyday people monitor water quality in their community. The Aquagenuity Developer API provides water quality reports for many USA ZipCodes.

The following figure shows the Atlanta watershed dashboard created from Example 2:

Node-RED Atlanta Watershed dashboard

Learning objectives

In this tutorial, you will:

  • Install Node-RED and the prerequisites required to build the dashboards
  • Learn about GeoJSON
  • Learn how to query the US Geological Survey Watershed API
  • Integrate water quality reports into an application
  • Build a dashboard that displays GeoJSON area maps and pins

Prerequisites

Estimated time

Completing this tutorial should take about 30 minutes.

Steps

Learn about GeoJSON

GeoJSON is a format for encoding a variety of geographic data structures. It is based on the JSON format. GeoJSON supports the following geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon. Geometric objects with additional properties are Feature objects. Sets of features are contained by FeatureCollection objects.

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [58,24]
  },
  "properties": {
    "name": "Elbonia"
  }
}

The GeoJSON format can define a polygon which will render an area map of a town, county, or state, for example. Amongst its many uses, it can define the topographical boundary of a watershed.

Learn how to query the USGS Watershed API

The USGS NLDI API returns a GeoJSON set of latitude / longitude coordinates and features that can be plotted on a map. You can search for a river near you. The drainage basin is an area of land where surface water runs off and converges into streams, rivers, lakes, and oceans. Using the GeoJSON information to observe where water sources are located, and what contaminants might be upstream, can lead to better water management and quality.

The NLDI API is provided by the Open Water Data Initiative and is being developed as an open source project.

Here is an example which calls the USGS NLDI API to retrieve a GeoJSON object for the watershed basin for the Hohokus Brook upstream of Ridgewood, NJ.

curl https://labs.waterdata.usgs.gov/api/nldi/linked-data/nwissite/USGS-01391000/basin

If you were to plot the GeoJSON on a map with some fill properties, the map draws an area boundary.

Hohokus Brook watershed

Query the Aquagenuity GetWaterScore API

The Aquagenuity GetWaterScore API provides water quality reports for many USA ZipCodes. Sign up for a free Aquagenuity Developer API key. Select the free plan and create an account. You will receive an email welcoming you to the Aquagenuity Developer Access Program. The email will contain your username and password credentials.

Review the GetWaterScore api documentation to learn how to query water quality reports.

# Example Zipcode value of (07450)

curl --header "Content-Type: application/json" \
--request POST \
--data '{"auth":{"username":"XXXXXXXXX","password":"XXXXXXXXXX"},"zipcode":"07450"}' \
https://aquagenuity.com/GetWaterScore

The GetWaterScore API replies with a json object and array of contaminants in the water for that Zip Code. It also includes the EPA toxin limits and health risks of the toxins. Note the units of the returned values. If you have any questions about the API, contact Aquagenuity.

For this tutorial, the chemical toxins found in the water are displayed in a Node-RED table. If the toxins exceed the EPA limits, the table highlights the chemical in red and, when selected, will popup an informational dialog about the health risks of that toxin. USGS also publishes Water Quality Data

Example flows from the Node-RED Water Sustainability Dashboard

The example flows are provided in the flows folder of the Node-RED-Water-Sustainability-Dashboard project. The node-red-contrib-web-worldmap node supports GeoJSON and renders the maps with the GeoJSON features and properties. Learn more about building Node-RED dashboards with map features by reviewing the additional node-red-contrib-web-worldmap documentation. The dashboard includes several colored map legend switches to show or hide the watershed details.

Example 1: Build a flow that displays the Ridgewood NJ watershed on a map

This flow queries the USGS NLDI API and plots the GeoJSON set of latitude / longitude coordinates for the Saddle River and Hohokus Brook water basin and river navigation.

Node-RED flow that displays the Ridgewood NJ watershed on a map

Example 2: Build a flow that displays the Atlanta GA watershed on a map

This flow queries the USGS NLDI API and plots the GeoJSON set of latitude / longitude coordinates for many water basins and rivers that comprise the Atlanta, GA watershed.

Node-RED flow that displays the Atlanta GA watershed on a map

Summary and next steps

Many APIs return GeoJSON formatted area maps, features, and points that are easy to render using modern mapping services. These maps can be useful to present data visualizations to users, consumers, and decision makers. By incorporating maps into your projects, you can convey complex data using geospatial visualizations that allow a user to zoom into details.