1
1
from typing import Dict , Any , Optional , Union , Tuple
2
+ from abc import ABC , abstractmethod
2
3
3
4
import geojson
4
5
import numpy as np
5
6
from shapely import geometry as geom
6
7
from pydantic import BaseModel
7
8
8
9
9
- class Geometry (BaseModel ):
10
+ class Geometry (BaseModel , ABC ):
10
11
"""
11
- Base class for geometry objects. Shouldn't be directly instantiated.
12
+ Base class for geometry objects.
12
13
"""
13
14
extra : Dict [str , Any ] = {}
14
15
15
- @property
16
- def geometry (self ) -> geojson :
17
- raise NotImplementedError ("Subclass must override this" )
18
-
19
16
@property
20
17
def shapely (
21
18
self
22
19
) -> Union [geom .Point , geom .LineString , geom .Polygon , geom .MultiPoint ,
23
20
geom .MultiLineString , geom .MultiPolygon ]:
24
21
return geom .shape (self .geometry )
25
22
26
- def raster (self ,
27
- height : Optional [int ] = None ,
28
- width : Optional [int ] = None ,
29
- canvas : Optional [np .ndarray ] = None ,
30
- color : Optional [Union [int , Tuple [int , int , int ]]] = None ,
31
- thickness : Optional [int ] = 1 ) -> np .ndarray :
32
- raise NotImplementedError ("Subclass must override this" )
33
-
34
23
def get_or_create_canvas (self , height : Optional [int ], width : Optional [int ],
35
24
canvas : Optional [np .ndarray ]) -> np .ndarray :
36
25
if canvas is None :
@@ -39,3 +28,17 @@ def get_or_create_canvas(self, height: Optional[int], width: Optional[int],
39
28
"Must either provide canvas or height and width" )
40
29
canvas = np .zeros ((height , width , 3 ), dtype = np .uint8 )
41
30
return canvas
31
+
32
+ @property
33
+ @abstractmethod
34
+ def geometry (self ) -> geojson :
35
+ pass
36
+
37
+ @abstractmethod
38
+ def raster (self ,
39
+ height : Optional [int ] = None ,
40
+ width : Optional [int ] = None ,
41
+ canvas : Optional [np .ndarray ] = None ,
42
+ color : Optional [Union [int , Tuple [int , int , int ]]] = None ,
43
+ thickness : Optional [int ] = 1 ) -> np .ndarray :
44
+ pass
0 commit comments