Skip to content

Commit

Permalink
handle missing descriptiveGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardchalstrey1 committed Mar 18, 2022
1 parent 158a096 commit 3f281a5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions etl/filter_mastermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
def main(mastermap_path):
mm_paths = sorted(glob.glob(os.path.join(mastermap_path, "*.gml.csv")))
for mm_path in mm_paths:
print(mm_path)
filter_mastermap(mm_path)


Expand All @@ -28,8 +29,11 @@ def filter_mastermap(mm_path):
w = csv.DictWriter(output_fh, fieldnames=output_fieldnames)
w.writeheader()
for line in r:
if 'Building' in line['descriptiveGroup']:
w.writerow(line)
try:
if 'Building' in line['descriptiveGroup']:
w.writerow(line)
except TypeError: # when descriptiveGroup is missing, ignore this Polygon
pass


if __name__ == '__main__':
Expand Down
10 changes: 5 additions & 5 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ def test_filter_mastermap():
"""Test that MasterMap CSV can be correctly filtered to include only buildings."""
input_file = "tests/test_mastermap.gml.csv" # Test csv with one building and one non-building
output_file = input_file.replace('gml', 'filtered')
filter_mastermap(input_file) # creates test_mastermap.filtered.csv
filter_mastermap(input_file) # creates output_file
with open(output_file, newline='') as csvfile:
csv_array = list(csv.reader(csvfile))
assert len(csv_array) == 2 # assert that length is 2 because just one row after header


def test_filter_mastermap_missing_type():
def test_filter_mastermap_missing_descriptivegroup():
"""Test that MasterMap CSV can be correctly filtered when the polygon does not have a type specified."""
input_file = "tests/test_mastermap_missing_type.gml.csv" # Test csv with one building and one non-building
input_file = "tests/test_mastermap_missing_descriptivegroup.gml.csv" # Test csv with one building and one non-building
output_file = input_file.replace('gml', 'filtered')
filter_mastermap(input_file) # creates test_mastermap.filtered.csv
filter_mastermap(input_file) # creates output_file
with open(output_file, newline='') as csvfile:
csv_array = list(csv.reader(csvfile))
assert len(csv_array) == 2 # assert that length is 2 because just one row after header
assert len(csv_array) == 1 # assert that length is 1 because just header
1 change: 1 addition & 0 deletions tests/test_mastermap_missing_descriptivegroup.filtered.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WKT,fid,descriptiveGroup
File renamed without changes.

0 comments on commit 3f281a5

Please sign in to comment.