-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintersect_satlas_enc.py
More file actions
74 lines (62 loc) · 2.9 KB
/
Copy pathintersect_satlas_enc.py
File metadata and controls
74 lines (62 loc) · 2.9 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import json
import math
from tqdm import tqdm
def coordinates_match(enc_coords, satlas_coords, decimal_places):
delta = 10 ** (-decimal_places)
return (abs(satlas_coords[0] - enc_coords[0]) < delta) and ((abs(satlas_coords[1] - enc_coords[1]) < delta))
directory_path = 'ENC_JSONS_UPDATED'
enc_objects = {}
satlas_object = {}
accepted_categories = {}
intersections = {}
# Get enc objects
for file_name in os.listdir(directory_path):
if (file_name).endswith('.geojson'):
file_path = os.path.join(directory_path, file_name)
# Open and Read GeoJson file
with open(file_path, 'r') as curr_enc:
curr_enc_data = json.load(curr_enc)
enc_obj_name = curr_enc_data["features"][0]["properties"]["finer_category"]
enc_objects[enc_obj_name] = curr_enc_data["features"]
# Get satlas objects
with open('satlas.geojson', 'r') as satlas_file:
curr_satlas_data = json.load(satlas_file)
final_features = []
for curr_feature in curr_satlas_data["features"]:
curr_feature_category = curr_feature["properties"]["category"]
if (curr_feature_category == "offshore_platform"):
final_features.append(curr_feature)
satlas_object["features"] = final_features
num_satlas_entries = len(satlas_object["features"])
total_matches = 0
for finer_category, category_list in enc_objects.items():
num_enc_entries = len(category_list)
threshold = 0.01
decimals = 3
num_matches_needed = math.ceil(num_enc_entries * threshold)
num_matches = 0
curr_intersections = []
if (finer_category == 'oil derrick/rig' or finer_category == 'production platform' or
finer_category == 'observation/research platform' or finer_category == 'offshore_platform'):
for i in tqdm(range(num_enc_entries), desc=finer_category, unit="iteration"):
curr_enc_object = category_list[i]
curr_match = False
for j in range(num_satlas_entries - total_matches):
curr_satlas_object = satlas_object["features"][j]
match = coordinates_match(curr_enc_object["geometry"]["coordinates"],
curr_satlas_object["geometry"]["coordinates"], decimals)
if match:
curr_match = True
# appends enc object, not satlas object now, just getting coordinates for now.
curr_intersections.append(curr_enc_object["geometry"]["coordinates"])
satlas_object["features"].remove(curr_satlas_object)
break
if curr_match:
num_matches += 1
total_matches += 1
#if num_matches >= num_matches_needed:
accepted_categories[finer_category] = (num_matches_needed, num_matches, num_enc_entries)
intersections[finer_category] = curr_intersections
print("Done Matching!")
print(accepted_categories)