Skip to content

Commit

Permalink
feat: unstructured grid from specification file (#1524)
Browse files Browse the repository at this point in the history
* add from_gridspec method to UnstructuredGrid
* add freyberg USG example notebook
* update cross section plot example notebook with accepted line representations
* validate line representations in PlotCrossSection instead of GeoSpatialUtil
* fix flopy.utils.gridutil.get_lni docstring
  • Loading branch information
wpbonelli committed Dec 14, 2022
1 parent 476fc4a commit 013e7cd
Show file tree
Hide file tree
Showing 10 changed files with 1,457 additions and 588 deletions.
101 changes: 20 additions & 81 deletions autotest/test_geospatial_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ def test_polygon(polygon):
poly = Shape.from_geojson(polygon)
gi1 = poly.__geo_interface__

if not isinstance(poly, Polygon):
raise AssertionError()
assert isinstance(poly, Polygon)

gu = GeoSpatialUtil(poly)

Expand All @@ -172,8 +171,6 @@ def test_polygon(polygon):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "polygon").flopy_geometry
gi2 = t.__geo_interface__

Expand All @@ -183,8 +180,8 @@ def test_polygon(polygon):
# pyshp < 2.2.0 sorts coordinates in opposite direction
gi2["coordinates"] = (gi2["coordinates"][0][::-1],)
is_equal = gi1 == gi2
if not is_equal:
raise AssertionError("GeoSpatialUtil polygon conversion error")

assert is_equal, "GeoSpatialUtil polygon conversion error"


@requires_pkg("shapely", "geojson")
Expand All @@ -195,8 +192,7 @@ def test_polygon_with_hole(poly_w_hole):
poly = Shape.from_geojson(poly_w_hole)
gi1 = poly.__geo_interface__

if not isinstance(poly, Polygon):
raise AssertionError()
assert isinstance(poly, Polygon)

gu = GeoSpatialUtil(poly)

Expand All @@ -209,8 +205,6 @@ def test_polygon_with_hole(poly_w_hole):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "polygon").flopy_geometry
gi2 = t.__geo_interface__

Expand All @@ -221,17 +215,16 @@ def test_polygon_with_hole(poly_w_hole):
t = reversed(t)
gi2 = t.__geo_interface__
is_equal = gi1 == gi2
if not is_equal:
raise AssertionError("GeoSpatialUtil polygon conversion error")

assert is_equal, "GeoSpatialUtil polygon conversion error"


@requires_pkg("shapely", "geojson")
def test_multipolygon(multipolygon):
poly = Shape.from_geojson(multipolygon)
gi1 = poly.__geo_interface__

if not isinstance(poly, MultiPolygon):
raise AssertionError()
assert isinstance(poly, MultiPolygon)

gu = GeoSpatialUtil(poly)

Expand All @@ -244,8 +237,6 @@ def test_multipolygon(multipolygon):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "multipolygon").flopy_geometry
gi2 = t.__geo_interface__

Expand All @@ -256,19 +247,16 @@ def test_multipolygon(multipolygon):
t = reversed(t)
gi2 = t.__geo_interface__
is_equal = gi1 == gi2
if not is_equal:
raise AssertionError(
"GeoSpatialUtil multipolygon conversion error"
)

assert is_equal, "GeoSpatialUtil multipolygon conversion error"


@requires_pkg("shapely", "geojson")
def test_point(point):
pt = Shape.from_geojson(point)
gi1 = pt.__geo_interface__

if not isinstance(pt, Point):
raise AssertionError()
assert isinstance(pt, Point)

gu = GeoSpatialUtil(pt)

Expand All @@ -281,24 +269,18 @@ def test_point(point):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "point").flopy_geometry
gi2 = t.__geo_interface__

is_equal = gi1 == gi2

if not is_equal:
raise AssertionError("GeoSpatialUtil point conversion error")
assert gi1 == gi2, "GeoSpatialUtil point conversion error"


@requires_pkg("shapely", "geojson")
def test_multipoint(multipoint):
mpt = Shape.from_geojson(multipoint)
gi1 = mpt.__geo_interface__

if not isinstance(mpt, MultiPoint):
raise AssertionError()
assert isinstance(mpt, MultiPoint)

gu = GeoSpatialUtil(mpt)

Expand All @@ -311,24 +293,18 @@ def test_multipoint(multipoint):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "multipoint").flopy_geometry
gi2 = t.__geo_interface__

is_equal = gi1 == gi2

if not is_equal:
raise AssertionError("GeoSpatialUtil multipoint conversion error")
assert gi1 == gi2, "GeoSpatialUtil multipoint conversion error"


@requires_pkg("shapely", "geojson")
def test_linestring(linestring):
lstr = Shape.from_geojson(linestring)
gi1 = lstr.__geo_interface__

if not isinstance(lstr, LineString):
raise AssertionError()
assert isinstance(lstr, LineString)

gu = GeoSpatialUtil(lstr)

Expand All @@ -341,24 +317,18 @@ def test_linestring(linestring):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "linestring").flopy_geometry
gi2 = t.__geo_interface__

is_equal = gi1 == gi2

if not is_equal:
raise AssertionError("GeoSpatialUtil linestring conversion error")
assert gi1 == gi2, "GeoSpatialUtil linestring conversion error"


@requires_pkg("shapely", "geojson")
def test_multilinestring(multilinestring):
mlstr = Shape.from_geojson(multilinestring)
gi1 = mlstr.__geo_interface__

if not isinstance(mlstr, MultiLineString):
raise AssertionError()
assert isinstance(mlstr, MultiLineString)

gu = GeoSpatialUtil(mlstr)

Expand All @@ -371,17 +341,10 @@ def test_multilinestring(multilinestring):
geo_types = [shp, shply, points, geojson, fp_geo]

for geo in geo_types:
if geo is None: # if shapely or geojson is not installed
continue
t = GeoSpatialUtil(geo, "multilinestring").flopy_geometry
gi2 = t.__geo_interface__

is_equal = gi1 == gi2

if not is_equal:
raise AssertionError(
"GeoSpatialUtil multilinestring conversion error"
)
assert gi1 == gi2, "GeoSpatialUtil multilinestring conversion error"


@requires_pkg("shapely", "geojson")
Expand All @@ -405,9 +368,6 @@ def test_polygon_collection(polygon, poly_w_hole, multipolygon):

collections = [shp, shply, points, geojson, fp_geo]
for col in collections:
if col is None: # if geojson or shapely is not installed
continue

gc2 = GeoSpatialCollection(col, shapetype)

for ix, gi in enumerate(gc2):
Expand All @@ -420,10 +380,8 @@ def test_polygon_collection(polygon, poly_w_hole, multipolygon):
t = reversed(t)
gi2 = t.__geo_interface__
is_equal = gi2 == gi1[ix]
if not is_equal:
raise AssertionError(
"GeoSpatialCollection Polygon conversion error"
)

assert is_equal, "GeoSpatialCollection Polygon conversion error"


@requires_pkg("shapely", "geojson")
Expand All @@ -443,9 +401,6 @@ def test_point_collection(point, multipoint):

collections = [shp, shply, points, geojson, fp_geo]
for col in collections:
if col is None: # if geojson or shapely is not installed
continue

gc2 = GeoSpatialCollection(col, shapetype)
gi2 = [i.flopy_geometry.__geo_interface__ for i in gc2]

Expand Down Expand Up @@ -475,9 +430,6 @@ def test_linestring_collection(linestring, multilinestring):

collections = [shp, shply, points, geojson, fp_geo]
for col in collections:
if col is None: # if geojson or shapely is not installed
continue

gc2 = GeoSpatialCollection(col, shapetype)
gi2 = [i.flopy_geometry.__geo_interface__ for i in gc2]

Expand Down Expand Up @@ -523,9 +475,6 @@ def test_mixed_collection(

collections = [shp, shply, points, geojson, fp_geo]
for col in collections:
if col is None: # if geojson or shapely is not installed
continue

gc2 = GeoSpatialCollection(col, shapetype)

for ix, gi in enumerate(gc2):
Expand All @@ -539,14 +488,4 @@ def test_mixed_collection(
gi2 = t.__geo_interface__
is_equal = gi2 == gi1[ix]

if not is_equal:
raise AssertionError(
"GeoSpatialCollection conversion error"
)


@requires_pkg("shapely", "geojson")
def test_create_linestring_with_single_point_fails():
point = [0, 0]
with pytest.raises(ValueError):
GeoSpatialUtil(point, shapetype="linestring")
assert is_equal, "GeoSpatialCollection conversion error"
Loading

0 comments on commit 013e7cd

Please sign in to comment.