Spaces:
Sleeping
Sleeping
File size: 1,492 Bytes
1ccaab4 99932ef 1ccaab4 99932ef 1ccaab4 99932ef 1ccaab4 99932ef 9d4d6fa a37ec6c 99932ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import json
import os
# Define the file path
file_path = os.path.join('given_data', 'smasvaedi_2021.json')
# Load the JSON data
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
def get_smallAreas():
'''
Returns a list of dict of format {"id": smsv_id, "geometry": [(long, lat), ...]}
for all smsv in in Höfuðborgarsvæði.
'''
# Extract smsv IDs and geometries for Höfuðborgarsvæði
hofudborgarsvaedi_areas = []
for feature in data['features']:
if feature['properties'].get('nuts3_label') == "Höfuðborgarsvæði":
smsv = feature['properties'].get('smsv')
raw_geometry = feature['geometry']
if smsv and raw_geometry:
# Extract coordinates and convert to list of tuples
processed_geometry = []
for polygon in raw_geometry['coordinates']:
# for ring in polygon: # Each "ring" of the MultiPolygon
# processed_geometry.append([(x, y) for x, y in ring])
processed_geometry = [(x, y) for x, y in polygon[0]]
hofudborgarsvaedi_areas.append({"id": smsv, "geometry": processed_geometry})
ids = [area["id"] for area in hofudborgarsvaedi_areas]
if len(ids) != len(set(ids)):
duplicates = [smsv for smsv in ids if ids.count(smsv) > 1]
raise ValueError(f"Duplicate IDs found: {set(duplicates)}")
return hofudborgarsvaedi_areas
|