55 from typing_extensions import Literal
66
77from pydantic import BaseModel , validator , Field
8+ import numpy as np
89
910from .classification import LBV1Checklist , LBV1Classifications , LBV1Radio , LBV1Text , LBV1Dropdown
1011from .feature import LBV1Feature
@@ -46,14 +47,25 @@ def validate_subclasses(cls, value, field):
4647 return value
4748
4849
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 ]]]
5264
5365
5466class LBV1TIPoint (LBV1ObjectBase ):
5567 object_type : Literal ['point' ] = Field (..., alias = 'type' )
56- geometry : _Coordinates
68+ geometry : TIPointCoordinate
5769
5870 def to_common (self ) -> Point :
5971 lng , lat = self .geometry .coordinates
@@ -62,7 +74,7 @@ def to_common(self) -> Point:
6274
6375class LBV1TILine (LBV1ObjectBase ):
6476 object_type : Literal ['polyline' ] = Field (..., alias = 'type' )
65- geometry : _Coordinates
77+ geometry : TILineCoordinate
6678
6779 def to_common (self ) -> Line :
6880 return Line (points = [
@@ -72,7 +84,7 @@ def to_common(self) -> Line:
7284
7385class LBV1TIPolygon (LBV1ObjectBase ):
7486 object_type : Literal ['polygon' ] = Field (..., alias = 'type' )
75- geometry : _Coordinates
87+ geometry : TIPolygonCoordinate
7688
7789 def to_common (self ) -> Polygon :
7890 for coord_list in self .geometry .coordinates :
@@ -82,12 +94,17 @@ def to_common(self) -> Polygon:
8294
8395class LBV1TIRectangle (LBV1ObjectBase ):
8496 object_type : Literal ['rectangle' ] = Field (..., alias = 'type' )
85- geometry : _Coordinates
97+ geometry : TIRectangleoordinate
8698
8799 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+
91108 return Rectangle (start = Point (x = start [0 ], y = start [1 ]),
92109 end = Point (x = end [0 ], y = end [1 ]))
93110
0 commit comments