Skip to content

Commit e1698ab

Browse files
committed
move a test to be near other related tests. natcap#1657
1 parent 0b35f58 commit e1698ab

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

tests/test_coastal_vulnerability.py

+42-42
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,48 @@ def test_aoi_invalid_geometry(self):
13581358
aoi_path, landmass_path, model_resolution, target_vector_path,
13591359
polygon_pickle, lines_pickle, lines_rtree)
13601360

1361+
def test_prepare_landmass_invalid_geometry(self):
1362+
"""CV: test handling invalid geometries in landmass vector."""
1363+
from natcap.invest import coastal_vulnerability
1364+
aoi_path = os.path.join(self.workspace_dir, 'aoi.geojson')
1365+
srs = osr.SpatialReference()
1366+
srs.ImportFromEPSG(26910) # UTM Zone 10N
1367+
wkt = srs.ExportToWkt()
1368+
1369+
aoi_geometries = [Polygon([
1370+
(-200, -200), (200, -200), (200, 200), (-200, 200), (-200, -200)])]
1371+
pygeoprocessing.shapely_geometry_to_vector(
1372+
aoi_geometries, aoi_path, wkt, 'GeoJSON')
1373+
1374+
landmass_vector_path = os.path.join(self.workspace_dir, 'vector.gpkg')
1375+
n_features = make_vector_of_invalid_geoms(landmass_vector_path)
1376+
1377+
target_polygon_pickle_path = os.path.join(
1378+
self.workspace_dir, 'polygon.pickle')
1379+
target_lines_pickle_path = os.path.join(
1380+
self.workspace_dir, 'lines.pickle')
1381+
target_rtree_path = os.path.join(self.workspace_dir, 'rtree.dat')
1382+
# Create rtree files to exercise the function's logic of removing
1383+
# pre-exisiting files
1384+
target_rtree_path_base = os.path.splitext(target_rtree_path)[0]
1385+
open(target_rtree_path, 'a').close()
1386+
open(target_rtree_path_base + '.idx', 'a').close()
1387+
1388+
model_resolution = 100
1389+
target_vector_path = os.path.join(
1390+
self.workspace_dir, 'temp-shore-pts.gpkg')
1391+
coastal_vulnerability.prepare_landmass_line_index_and_interpolate_shore_points(
1392+
aoi_path, landmass_vector_path, model_resolution,
1393+
target_vector_path, target_polygon_pickle_path,
1394+
target_lines_pickle_path, target_rtree_path)
1395+
1396+
with open(target_polygon_pickle_path, 'rb') as polygon_file:
1397+
shapely_geom = pickle.load(polygon_file)
1398+
1399+
# Expect 1 input geometry to be skipped, and the rest to be in
1400+
# shapely_geom_list.
1401+
self.assertTrue(len(shapely_geom.geoms) == n_features - 1)
1402+
13611403
def test_no_wwiii_coverage(self):
13621404
"""CV: test exception when shore points are outside max wwiii dist."""
13631405
from natcap.invest import coastal_vulnerability
@@ -1434,48 +1476,6 @@ def test_projected_wwiii_input(self):
14341476
layer = None
14351477
vector = None
14361478

1437-
def test_prepare_landmass_invalid_geometry(self):
1438-
"""CV: test handling invalid geometries in landmass vector."""
1439-
from natcap.invest import coastal_vulnerability
1440-
aoi_path = os.path.join(self.workspace_dir, 'aoi.geojson')
1441-
srs = osr.SpatialReference()
1442-
srs.ImportFromEPSG(26910) # UTM Zone 10N
1443-
wkt = srs.ExportToWkt()
1444-
1445-
aoi_geometries = [Polygon([
1446-
(-200, -200), (200, -200), (200, 200), (-200, 200), (-200, -200)])]
1447-
pygeoprocessing.shapely_geometry_to_vector(
1448-
aoi_geometries, aoi_path, wkt, 'GeoJSON')
1449-
1450-
landmass_vector_path = os.path.join(self.workspace_dir, 'vector.gpkg')
1451-
n_features = make_vector_of_invalid_geoms(landmass_vector_path)
1452-
1453-
target_polygon_pickle_path = os.path.join(
1454-
self.workspace_dir, 'polygon.pickle')
1455-
target_lines_pickle_path = os.path.join(
1456-
self.workspace_dir, 'lines.pickle')
1457-
target_rtree_path = os.path.join(self.workspace_dir, 'rtree.dat')
1458-
# Create rtree files to exercise the function's logic of removing
1459-
# pre-exisiting files
1460-
target_rtree_path_base = os.path.splitext(target_rtree_path)[0]
1461-
open(target_rtree_path, 'a').close()
1462-
open(target_rtree_path_base + '.idx', 'a').close()
1463-
1464-
model_resolution = 100
1465-
target_vector_path = os.path.join(
1466-
self.workspace_dir, 'temp-shore-pts.gpkg')
1467-
coastal_vulnerability.prepare_landmass_line_index_and_interpolate_shore_points(
1468-
aoi_path, landmass_vector_path, model_resolution,
1469-
target_vector_path, target_polygon_pickle_path,
1470-
target_lines_pickle_path, target_rtree_path)
1471-
1472-
with open(target_polygon_pickle_path, 'rb') as polygon_file:
1473-
shapely_geom = pickle.load(polygon_file)
1474-
1475-
# Expect 1 input geometry to be skipped, and the rest to be in
1476-
# shapely_geom_list.
1477-
self.assertTrue(len(shapely_geom.geoms) == n_features - 1)
1478-
14791479
def test_clip_project_already_projected_raster(self):
14801480
"""CV: test clip_and_project_raster on an already projected raster."""
14811481
from natcap.invest import coastal_vulnerability

0 commit comments

Comments
 (0)