CERA “Shapes” Up

Using the matplotlib library to create clean geometries for GIS compatible shapefiles

By: Carola Kaiser

The Coastal Emergency Risks Assessment (CERA) team provides guidance about storm surge and waves for the Northern Gulf and the Atlantic Coast through its online portal (http://coastalemergency.org). In addition to that, we are working towards the goal of providing all layers in the shapefile format compatible with GIS software. This feature will be available for the hurricane season 2015.

We use the Python Matplotlib library (http://matplotlib.org/) to convert the ADCIRC NetCDF format into contours which can then be used to generate shapefiles. While working on the algorithms, the CERA team has discovered some specifics which are essential to produce clean geometries. Clean geometries in GIS terminology do not include any self-intersections, overlapping, or duplicate features and ensure the hassle-free usability for GIS specialists and emergency managers.

The CERA team would like to thank Ian Thomas from the matplotlib developer team for helping us create useable and valuable contours and geometries.

Here are the specifics and bug fixes that we have addressed:

  1. Matplotlib ‘tricontourf’ expects a data array, but does not support masked arrays. If you pass a masked array, it will be ignored. The triangulation should only contain triangles with valid data at all three vertices. The solution is to either remove invalid triangles from your ‘element’ array before creating the triangulation, or set a mask on the triangulation once it has been created.
  1. The created contours will contain one or more polygon exteriors and zero or more interiors. They can be in any order (an exterior is not necessarily followed by its interiors). This has to be explicitly tested in your own script. The CERA code takes care of this issue.

We provide the CERA Matplotlib contouring script as Open Source on the CERA GitHub website https://github.com/CERA-GROUP/cera_contour.

If you have any questions, please contact:
Carola Kaiser, email: ckaiser@cct.lsu.edu

CERA: http://coastalemergency.org