11from typing import Dict , Any , Optional , Union , Tuple
2+ from abc import ABC , abstractmethod
23
34import geojson
45import numpy as np
56from shapely import geometry as geom
67from pydantic import BaseModel
78
89
9- class Geometry (BaseModel ):
10+ class Geometry (BaseModel , ABC ):
1011 """
11- Base class for geometry objects. Shouldn't be directly instantiated.
12+ Base class for geometry objects.
1213 """
1314 extra : Dict [str , Any ] = {}
1415
15- @property
16- def geometry (self ) -> geojson :
17- raise NotImplementedError ("Subclass must override this" )
18-
1916 @property
2017 def shapely (
2118 self
2219 ) -> Union [geom .Point , geom .LineString , geom .Polygon , geom .MultiPoint ,
2320 geom .MultiLineString , geom .MultiPolygon ]:
2421 return geom .shape (self .geometry )
2522
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-
3423 def get_or_create_canvas (self , height : Optional [int ], width : Optional [int ],
3524 canvas : Optional [np .ndarray ]) -> np .ndarray :
3625 if canvas is None :
@@ -39,3 +28,17 @@ def get_or_create_canvas(self, height: Optional[int], width: Optional[int],
3928 "Must either provide canvas or height and width" )
4029 canvas = np .zeros ((height , width , 3 ), dtype = np .uint8 )
4130 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