SAGA-GIS examples from 2018-12 OGTA Training Course.

The example area of interest (AoI) here is Liberia, defined as: * lat_n +9 * lat_s -6 * lon_e -23 * lon_w -3

This is an example of how to use SAGA GIS via saga_cmd (bash cmd used via python subprocess) to process data. The .shp output(s) are then displayed using mapnik. Some alternative display options are enumerated here.

Project Dir Explaination

The expected directory structure here: (TODO: this might not be essential within these examples)

Data Sources:

  1. World Borders from thematicMapping.org
  2. World EEZ v10 Marine Regions from marineRegions.org:
    • Claus S., De Hauwere N., Vanhoorne B., Souza Dias F., Oset García P., Schepers L., Hernandez F., and Mees J. (Flanders Marine Institute) (2018). MarineRegions.org. Accessed at http://www.marineregions.org on 2018-12-04.
  3. Modis Aqua Chl Monthly Anomalies from GMIS

TODO: must download data first (or load from remote within python)

#!/usr/bin/env python
import subprocess
import os.path


class input_file(object):
    WORLD_EEZ_POLY = "DATA/BASEMAP/BORDERS/eez/eez_v10.shp"
    WORLD_EEZ_LINE = "DATA/BASEMAP/BORDERS/eez/eez_boundaries_v10.shp"

    LIBERIA_FRAME_POLY = "PRODUCTS/SAGA/VECTORS/frame_liberia_poly.shp"

    LIBERIA_FRAME_LINE = "PRODUCTS/SAGA/VECTORS/frame_liberia_line.shp"
    @staticmethod
    def list_all():
        return [
            getattr(input_file, a) for a in dir(input_file)
            if not a.startswith('_') and
            not callable(getattr(input_file, a))
        ]

# intermediate data:
LIBERIA_EEZ_LINE = "PRODUCTS/SAGA/VECTORS/liberia_eez.shp"

for infile in input_file.list_all():
    if(not os.path.isfile(infile)):
        raise ValueError("Missing Input file:\n\t{}".format(infile))

cmd = [
    'saga_cmd', 'shapes_lines', 'Line-Polygon Intersection',
    '-LINES', input_file.WORLD_EEZ_LINE,
    '-POLYGONS', input_file.LIBERIA_FRAME_POLY,
    '-INTERSECT', LIBERIA_EEZ_LINE
]
print("running bash command:\n\t{}".format(subprocess.list2cmdline(cmd)))
subprocess.check_output(cmd)

# TODO: how to plot?
# === 1 use mapnik_plot like:
# from assets.py.mapnik_plot import mapnik_plot
# mapnik_plot(LIBERIA_EEZ_LINE)
#
# === 2 use [gdal_rasterize](https://www.gdal.org/gdal_rasterize.html) bash cmd
# ```{bash} gdal_rasterize ...???... ```

TODO:

  1. compare EEZ & Longhurst Province Biodiversity “health” (as defined by @bbest’s indicies)
  2. play with saga-py
  3. use more of chl_a anom [@gmis](http://mcc.jrc.ec.europa.eu/emis/)
  4. can skip over saving intermediate products in python by using data in RAM (see here).