Skip to content

Commit ccf8932

Browse files
author
Tahira Ullah
committed
union cascaded outside of loop
1 parent e454a8b commit ccf8932

File tree

6 files changed

+24
-89
lines changed

6 files changed

+24
-89
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ mapswipe_workers/config/configuration.json
120120
# don´t upload data dir
121121
data/
122122

123+
mapswipe-data/
124+
123125
# don't upload app config for project managers dashboard
124126
app.js
125127

mapswipe_workers/mapswipe_workers/definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
LOGGING_FILE_PATH = os.path.join(DATA_PATH, "mapswipe_workers.log")
1414

1515
# number of geometries for project geometries
16-
featureNumber = 2
16+
MAX_INPUT_GEOMETRIES = 2
1717

1818
LOGGING_CONFIG = {
1919
"version": 1,

mapswipe_workers/mapswipe_workers/project_types/tile_map_service_grid/project.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
import os
33

44
from mapswipe_workers.project_types.base.project import BaseProject
5-
from mapswipe_workers.definitions import DATA_PATH, CustomError, logger, featureNumber
5+
from mapswipe_workers.definitions import (
6+
DATA_PATH,
7+
CustomError,
8+
logger,
9+
MAX_INPUT_GEOMETRIES,
10+
)
611
from mapswipe_workers.project_types.tile_map_service_grid.group import Group
712
from mapswipe_workers.utils import tile_grouping_functions as grouping_functions
813
from mapswipe_workers.project_types.base.tile_server import BaseTileServer
@@ -59,14 +64,16 @@ def validate_geometries(self):
5964
raise CustomError(f"Empty file. ")
6065

6166
# check if more than 1 geometry is provided
62-
elif layer.GetFeatureCount() > featureNumber:
67+
elif layer.GetFeatureCount() > MAX_INPUT_GEOMETRIES:
6368
logger.warning(
6469
f"{self.projectId}"
6570
f" - validate geometry - "
66-
f"Input file contains more than {featureNumber} geometries. "
67-
f"Make sure to provide less than {featureNumber} geometries."
71+
f"Input file contains more than {MAX_INPUT_GEOMETRIES} geometries. "
72+
f"Make sure to provide less than {MAX_INPUT_GEOMETRIES} geometries."
73+
)
74+
raise CustomError(
75+
f"Input file contains more than {MAX_INPUT_GEOMETRIES} geometries. "
6876
)
69-
raise CustomError(f"Input file contains more than 10 geometries. ")
7077

7178
project_area = 0
7279
geometry_collection = ogr.Geometry(ogr.wkbMultiPolygon)
@@ -76,13 +83,10 @@ def validate_geometries(self):
7683
geom_name = feat_geom.GetGeometryName()
7784
# add geometry to geometry collection
7885
if geom_name == "MULTIPOLYGON":
79-
for multi in feat_geom:
80-
geometry_collection.AddGeometry(multi)
81-
dissolved_geometry = geometry_collection.UnionCascaded()
82-
wkt_geometry_collection = dissolved_geometry.ExportToWkt()
86+
for singlepart_polygon in feat_geom:
87+
geometry_collection.AddGeometry(singlepart_polygon)
8388
if geom_name == "POLYGON":
8489
geometry_collection.AddGeometry(feat_geom)
85-
wkt_geometry_collection = geometry_collection.ExportToWkt()
8690
if not feat_geom.IsValid():
8791
logger.warning(
8892
f"{self.projectId}"
@@ -144,6 +148,9 @@ def validate_geometries(self):
144148
f"{self.projectId}" f" - validate geometry - " f"input geometry is correct."
145149
)
146150

151+
dissolved_geometry = geometry_collection.UnionCascaded()
152+
wkt_geometry_collection = dissolved_geometry.ExportToWkt()
153+
147154
return wkt_geometry_collection
148155

149156
def create_groups(self):

mapswipe_workers/mapswipe_workers/utils/tile_grouping_functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ def extent_to_groups(infile, zoom, groupSize):
400400
# TODO: add this line once properly working
401401
groups_dict, overlaps_total = adjust_overlapping_groups(raw_groups_dict, zoom)
402402

403+
if overlaps_total == 0:
404+
groups_dict = groups_dict
405+
403406
return groups_dict
404407

405408

mapswipe_workers/tests/unittests/test_groups_overlap.py

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,84 +18,6 @@ def test_project_geometries_intersection(self):
1818
groups_with_overlaps, "groups_with_overlaps.geojson"
1919
)
2020

21-
# remove groups within other groups
22-
groups_with_overlaps_2 = t.remove_groups_within_other_groups(
23-
groups_with_overlaps, zoom
24-
)
25-
t.vertical_groups_as_geojson(
26-
groups_with_overlaps, "groups_with_overlaps2.geojson"
27-
)
28-
29-
# TODO: remove once implemented in real function
30-
groups, overlaps_total = t.adjust_overlapping_groups(
31-
groups_with_overlaps_2, zoom
32-
)
33-
t.vertical_groups_as_geojson(groups, "groups.geojson")
34-
35-
groups_2, overlaps_total_2 = t.adjust_overlapping_groups(groups, zoom)
36-
t.vertical_groups_as_geojson(groups_2, "groups_2.geojson")
37-
38-
# we expect 117 groups
39-
self.assertEqual(len(groups_2), 117)
40-
41-
'''
42-
def test_project_geometries_within(self):
43-
zoom = 18
44-
project_extent_file = os.path.join(
45-
self.test_dir, "fixtures/completeness/project_geometries_within.geojson"
46-
)
47-
48-
groups_with_overlaps = t.extent_to_groups(project_extent_file, zoom, 100)
49-
t.vertical_groups_as_geojson(
50-
groups_with_overlaps, "groups_with_overlaps.geojson"
51-
)
52-
53-
# remove groups within other groups
54-
groups_with_overlaps_2 = t.remove_groups_within_other_groups(
55-
groups_with_overlaps, zoom
56-
)
57-
t.vertical_groups_as_geojson(
58-
groups_with_overlaps, "groups_with_overlaps2.geojson"
59-
)
60-
61-
# TODO: remove once implemented in real function
62-
groups, overlaps_total = t.adjust_overlapping_groups(
63-
groups_with_overlaps_2, zoom
64-
)
65-
t.vertical_groups_as_geojson(groups, "groups.geojson")
66-
67-
groups_2, overlaps_total_2 = t.adjust_overlapping_groups(groups, zoom)
68-
t.vertical_groups_as_geojson(groups_2, "groups_2.geojson")
69-
70-
groups_3, overlaps_total_3 = t.adjust_overlapping_groups(groups_2, zoom)
71-
t.vertical_groups_as_geojson(groups_3, "groups_3.geojson")
72-
73-
# we expect 64 groups
74-
self.assertEqual(len(groups_3), 64)
75-
76-
"""
77-
def test_project_geometries_very_small_and_close(self):
78-
project_extent_file = os.path.join(
79-
self.test_dir,
80-
"fixtures/completeness/project_geometries_very_small_and_close.geojson"
81-
)
82-
83-
groups_with_overlaps = t.extent_to_groups(project_extent_file, 18, 100)
84-
t.vertical_groups_as_geojson(
85-
groups_with_overlaps, "groups_with_overlaps.geojson"
86-
)
87-
88-
groups = t.adjust_overlapping_groups(groups_with_overlaps)
89-
90-
# save files for visual inspection in qgis
91-
t.vertical_groups_as_geojson(groups, "groups.geojson")
92-
93-
# TODO: add correct assertion, what is the expected output?
94-
# we expect 64 groups
95-
#self.assertEqual(len(groups), 64)
96-
"""
97-
'''
98-
9921

10022
if __name__ == "__main__":
10123
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE projects ALTER COLUMN geom SET DATA TYPE geometry;

0 commit comments

Comments
 (0)