3
3
4
4
import abc
5
5
import warnings
6
- from typing import Any , Iterator , List , Literal , Optional , Protocol , Union
6
+ from typing import Any , Iterator , List , Literal , Optional , Union
7
7
8
8
from pydantic import BaseModel , Field , ValidationError , validator
9
9
from pydantic .error_wrappers import ErrorWrapper
@@ -72,19 +72,17 @@ def _polygons_wkt_coordinates(
72
72
)
73
73
74
74
75
- class _WktCallable (Protocol ):
76
- def __call__ (self , coordinates : Any , force_z : bool ) -> str :
77
- ...
78
-
79
-
80
75
class _GeometryBase (BaseModel , abc .ABC , GeoInterfaceMixin ):
81
76
"""Base class for geometry models"""
82
77
83
78
type : str
84
79
coordinates : Any
85
80
bbox : Optional [BBox ] = None
86
81
87
- __wkt_coordinates__ : _WktCallable
82
+ @abc .abstractmethod
83
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
84
+ """return WKT coordinates."""
85
+ ...
88
86
89
87
@property
90
88
@abc .abstractmethod
@@ -116,7 +114,9 @@ class Point(_GeometryBase):
116
114
type : Literal ["Point" ]
117
115
coordinates : Position
118
116
119
- __wkt_coordinates__ = staticmethod (_position_wkt_coordinates ) # type: ignore
117
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
118
+ """return WKT coordinates."""
119
+ return _position_wkt_coordinates (coordinates , force_z )
120
120
121
121
@property
122
122
def has_z (self ) -> bool :
@@ -130,7 +130,9 @@ class MultiPoint(_GeometryBase):
130
130
type : Literal ["MultiPoint" ]
131
131
coordinates : MultiPointCoords
132
132
133
- __wkt_coordinates__ = staticmethod (_position_list_wkt_coordinates ) # type: ignore
133
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
134
+ """return WKT coordinates."""
135
+ return _position_list_wkt_coordinates (coordinates , force_z )
134
136
135
137
@property
136
138
def has_z (self ) -> bool :
@@ -144,7 +146,9 @@ class LineString(_GeometryBase):
144
146
type : Literal ["LineString" ]
145
147
coordinates : LineStringCoords
146
148
147
- __wkt_coordinates__ = staticmethod (_position_list_wkt_coordinates ) # type: ignore
149
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
150
+ """return WKT coordinates."""
151
+ return _position_list_wkt_coordinates (coordinates , force_z )
148
152
149
153
@property
150
154
def has_z (self ) -> bool :
@@ -158,7 +162,9 @@ class MultiLineString(_GeometryBase):
158
162
type : Literal ["MultiLineString" ]
159
163
coordinates : MultiLineStringCoords
160
164
161
- __wkt_coordinates__ = staticmethod (_lines_wtk_coordinates ) # type: ignore
165
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
166
+ """return WKT coordinates."""
167
+ return _lines_wtk_coordinates (coordinates , force_z )
162
168
163
169
@property
164
170
def has_z (self ) -> bool :
@@ -172,7 +178,9 @@ class Polygon(_GeometryBase):
172
178
type : Literal ["Polygon" ]
173
179
coordinates : PolygonCoords
174
180
175
- __wkt_coordinates__ = staticmethod (_lines_wtk_coordinates ) # type: ignore
181
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
182
+ """return WKT coordinates."""
183
+ return _lines_wtk_coordinates (coordinates , force_z )
176
184
177
185
@validator ("coordinates" )
178
186
def check_closure (cls , coordinates : List ) -> List :
@@ -218,7 +226,9 @@ class MultiPolygon(_GeometryBase):
218
226
type : Literal ["MultiPolygon" ]
219
227
coordinates : MultiPolygonCoords
220
228
221
- __wkt_coordinates__ = staticmethod (_polygons_wkt_coordinates ) # type: ignore
229
+ def __wkt_coordinates__ (self , coordinates : Any , force_z : bool ) -> str :
230
+ """return WKT coordinates."""
231
+ return _polygons_wkt_coordinates (coordinates , force_z )
222
232
223
233
@property
224
234
def has_z (self ) -> bool :
0 commit comments