Jan commited on
Commit
1ccaab4
·
1 Parent(s): 6b881ab

first version of small place id and geometry retrieval

Browse files
data_processing/get_smallAreaInfo.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ # Define the file path
5
+ file_path = os.path.join('given_data', 'smasvaedi_2021.json')
6
+
7
+ # Load the JSON data
8
+ with open(file_path, 'r', encoding='utf-8') as file:
9
+ data = json.load(file)
10
+
11
+ def get_smallAreas():
12
+ '''
13
+ Returns a list of tuples where each tuple (id, geometry) contains
14
+ the smsv ID and the corresponding geometry (coordinates) for
15
+ features in Höfuðborgarsvæði.
16
+ '''
17
+ # Extract smsv IDs and geometries for Höfuðborgarsvæði
18
+ hofudborgarsvaedi_areas = []
19
+
20
+ for feature in data['features']:
21
+ if feature['properties'].get('nuts3_label') == "Höfuðborgarsvæði":
22
+ smsv = feature['properties'].get('smsv')
23
+ raw_geometry = feature['geometry']
24
+ if smsv and raw_geometry:
25
+ # Extract coordinates and convert to list of tuples
26
+ processed_geometry = []
27
+ for polygon in raw_geometry['coordinates']:
28
+ # for ring in polygon: # Each "ring" of the MultiPolygon
29
+ # processed_geometry.append([(x, y) for x, y in ring])
30
+ processed_geometry = [(x, y) for x, y in polygon[0]]
31
+
32
+ hofudborgarsvaedi_areas.append((smsv, processed_geometry))
33
+
34
+ # Check for duplicate IDs
35
+ ids = [area[0] for area in hofudborgarsvaedi_areas]
36
+ unique_ids = set(ids)
37
+ if len(unique_ids) < len(ids):
38
+ duplicates = [smsv for smsv in ids if ids.count(smsv) > 1]
39
+ raise ValueError(f"Duplicates found! Duplicate IDs: {set(duplicates)}")
40
+
41
+ return hofudborgarsvaedi_areas