5
5
from typing_extensions import Literal
6
6
7
7
from pydantic import BaseModel , validator , Field
8
+ import numpy as np
8
9
9
10
from .classification import LBV1Checklist , LBV1Classifications , LBV1Radio , LBV1Text , LBV1Dropdown
10
11
from .feature import LBV1Feature
@@ -46,14 +47,25 @@ def validate_subclasses(cls, value, field):
46
47
return value
47
48
48
49
49
- class _Coordinates (BaseModel ):
50
- """Union of the possible coordinate lists in tiled imagery exports"""
51
- coordinates : Union [List [float ], List [List [float ]], List [List [List [float ]]]]
50
+ class TIPointCoordinate (BaseModel ):
51
+ coordinates : List [float ]
52
+
53
+
54
+ class TILineCoordinate (BaseModel ):
55
+ coordinates : List [List [float ]]
56
+
57
+
58
+ class TIPolygonCoordinate (BaseModel ):
59
+ coordinates : List [List [List [float ]]]
60
+
61
+
62
+ class TIRectangleoordinate (BaseModel ):
63
+ coordinates : List [List [List [float ]]]
52
64
53
65
54
66
class LBV1TIPoint (LBV1ObjectBase ):
55
67
object_type : Literal ['point' ] = Field (..., alias = 'type' )
56
- geometry : _Coordinates
68
+ geometry : TIPointCoordinate
57
69
58
70
def to_common (self ) -> Point :
59
71
lng , lat = self .geometry .coordinates
@@ -62,7 +74,7 @@ def to_common(self) -> Point:
62
74
63
75
class LBV1TILine (LBV1ObjectBase ):
64
76
object_type : Literal ['polyline' ] = Field (..., alias = 'type' )
65
- geometry : _Coordinates
77
+ geometry : TILineCoordinate
66
78
67
79
def to_common (self ) -> Line :
68
80
return Line (points = [
@@ -72,7 +84,7 @@ def to_common(self) -> Line:
72
84
73
85
class LBV1TIPolygon (LBV1ObjectBase ):
74
86
object_type : Literal ['polygon' ] = Field (..., alias = 'type' )
75
- geometry : _Coordinates
87
+ geometry : TIPolygonCoordinate
76
88
77
89
def to_common (self ) -> Polygon :
78
90
for coord_list in self .geometry .coordinates :
@@ -82,12 +94,17 @@ def to_common(self) -> Polygon:
82
94
83
95
class LBV1TIRectangle (LBV1ObjectBase ):
84
96
object_type : Literal ['rectangle' ] = Field (..., alias = 'type' )
85
- geometry : _Coordinates
97
+ geometry : TIRectangleoordinate
86
98
87
99
def to_common (self ) -> Rectangle :
88
- coord_list = self .geometry .coordinates [0 ]
89
- start = coord_list [0 ]
90
- end = coord_list [2 ]
100
+ coord_list = np .array (self .geometry .coordinates [0 ])
101
+
102
+ min_x , max_x = np .min (coord_list [:, 0 ]), np .max (coord_list [:, 0 ])
103
+ min_y , max_y = np .min (coord_list [:, 1 ]), np .max (coord_list [:, 1 ])
104
+
105
+ start = [min_x , min_y ]
106
+ end = [max_x , max_y ]
107
+
91
108
return Rectangle (start = Point (x = start [0 ], y = start [1 ]),
92
109
end = Point (x = end [0 ], y = end [1 ]))
93
110
0 commit comments