handle missing descriptiveGroup
This commit is contained in:
parent
158a09637b
commit
3f281a5e73
@ -14,6 +14,7 @@ csv.field_size_limit(sys.maxsize)
|
||||
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)
|
||||
|
||||
|
||||
@ -28,8 +29,11 @@ def filter_mastermap(mm_path):
|
||||
w = csv.DictWriter(output_fh, fieldnames=output_fieldnames)
|
||||
w.writeheader()
|
||||
for line in r:
|
||||
try:
|
||||
if 'Building' in line['descriptiveGroup']:
|
||||
w.writerow(line)
|
||||
except TypeError: # when descriptiveGroup is missing, ignore this Polygon
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -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
|
@ -0,0 +1 @@
|
||||
WKT,fid,descriptiveGroup
|
|
Can't render this file because it contains an unexpected character in line 2 and column 1359.
|
Loading…
Reference in New Issue
Block a user