Importing coast files

Coastline files need to be in a format from which we can construct a MultiPolygon object. This would be the most efficient way to perform intersections with the grid. If they’re already in some sort of a GIS format then that would be ideal. Some of the ASCII files we have within our team contain some polygons that are “not simple” and hence there is some code in this package that tries to rectify this

[1]:
%matplotlib inline
from cem_gridtools.cem_gridtools import Coast
import numpy as np
[2]:
# File resides in 'docs/source/examples'
fname = 'setas.cst'
# Initialise object
C = Coast(fname)
print("{} contains {} polygons".format(fname,C.get_num_polygons()))
setas.cst contains 603 polygons
[3]:
C.plot()
# Note: The erroneous Polygons try to use buffer(0) to rectify the issue
Polygon using indices (2279:2283) is invalid:Too few points in geometry component[145.299916 -42.180851]
Polygon using indices (16483:16487) is invalid:Too few points in geometry component[146.348145 -43.58688]
Polygon using indices (18964:18986) is invalid:Self-intersection[147.976090376623 -42.8566280649351]
Polygon using indices (18987:18991) is invalid:Self-intersection[148.045237 -42.653316]
Polygon using indices (76783:77384) is invalid:Self-intersection[146.347855 -43.58678]
Polygon using indices (77385:222908) is invalid:Self-intersection[145.543558333333 -42.3834755555556]
Polygon using indices (222909:223059) is invalid:Self-intersection[145.984111481604 -43.01193]
../_images/examples_import_coast_3_1.png
[4]:
# Each feature is a polygon
# eg.
polyFunc = C.get_polyons_as_generator()
p = next(polyFunc)
type(p)
[4]:
shapely.geometry.polygon.Polygon

Jupyter notebook can render this natively

[6]:
p
[6]:
../_images/examples_import_coast_6_0.svg
[ ]: