-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbox_to_orion.py
73 lines (60 loc) · 3.83 KB
/
mapbox_to_orion.py
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
73
import requests
import json
import uuid
from shapely.geometry import LineString, Polygon
import orion_add_vineyard # create_vineyard_entity (assuming this exists)
import orion_add_block # create_block_entity (assuming this exists)
import orion_add_vinerow # create_vine_row_entity (assuming this exists)
import orion_add_point_feature # create_point_feature_entity (not used here)
import orion_add_line_feature # create_line_feature_entity (not used here)
import orion_add_polygon_feature # create_polygon_feature_entity (not used here)
def mapbox_to_orion(vineyard_id, geojson_data):
print("def mapbox_to_orion")
json_data = json.loads(geojson_data)["features"]
# Collect linestring features
linestring_features = []
row_user_defined_id = 1
for feature in json_data:
if feature["geometry"]["type"] == "LineString":
#print("feature[geometry][type] == LineString")
linestring_features.append(feature)
#print("linestring_features" + str(linestring_features))
for feature in json_data:
# Blocks
if feature["properties"]["type"] == "block":
block_user_defined_id = feature["properties"].get("blockName", "Unknown")
short_code = feature["properties"].get("shortCode", "Unknown")
variety = feature["properties"].get("variety", "Unknown")
vine_spacing = float(feature["properties"].get("vineSpacing", "Unknown"))
under_vine_width = float(feature["properties"].get("underVineWidth", "Unknown"))
anchor_post_distance = float(feature["properties"].get("anchorPostDistance", "Unknown"))
coordinates = feature["geometry"]["coordinates"]
print("Saved block " + str(block_user_defined_id) + " in vineyard " + str(vineyard_id))
orion_add_block.create_block_entity(str(uuid.uuid4()), str(vineyard_id), str(short_code), str(block_user_defined_id), 0, variety, anchor_post_distance, under_vine_width, vine_spacing, "2024-01-01T00:00:00Z", "2024-12-31T00:00:00Z", coordinates[0])
block_polygon = Polygon(coordinates[0])
#print("block_polygon " + str(block_polygon))
# Process linestrings against the block polygon
for linestring_feature in linestring_features:
#print("for linestring_feature in linestring_features")
row_coordinates = linestring_feature["geometry"]["coordinates"]
#print("row_coordinates " + str(row_coordinates))
row_linestring = LineString(row_coordinates)
#print("row_linestring " + str(list(row_linestring.coords)))
if block_polygon.intersection(row_linestring):
#print("if block_polygon.within(row_linestring)")
print("Saved vine row " + str(row_user_defined_id) + " in block " + str(block_user_defined_id) + " in vineyard " + str(vineyard_id))
# print(
# "vine_row_id: " + str(uuid.uuid4()) +
# " block_id: " + str(block_user_defined_id) +
# " vineyard_id: " + str(vineyard_id) +
# " user_defined_id: row_" + str(row_user_defined_id) +
# " orientation: " + str(0) +
# " category: vineyard" +
# " class_string: row" +
# " vine_spacing: " + vine_spacing +
# " under_vine_width: " + under_vine_width +
# " anchor_post_distance: " + anchor_post_distance +
# " row_coordinates: " + str(row_coordinates)
# )
orion_add_vinerow.create_vine_row_entity(str(uuid.uuid4()), str(block_user_defined_id), str(vineyard_id), "row_" + str(row_user_defined_id), 0, "vineyard", "row", vine_spacing, under_vine_width, anchor_post_distance, row_coordinates)
row_user_defined_id = row_user_defined_id + 1