geobox 2.2.1__py3-none-any.whl → 2.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
geobox/aio/feature.py CHANGED
@@ -29,7 +29,11 @@ class AsyncFeature(AsyncBase):
29
29
  super().__init__(api=layer.api)
30
30
  self.layer = layer
31
31
  self._srid = srid
32
- self.data = data or {}
32
+ self.data = data or {
33
+ "type": "Feature",
34
+ "geometry": {},
35
+ "properties": {}
36
+ }
33
37
  self.original_geometry = self.data.get('geometry')
34
38
  self.endpoint = urljoin(layer.endpoint, f'features/{self.data.get("id")}/') if self.data.get('id') else None
35
39
 
@@ -215,11 +219,8 @@ class AsyncFeature(AsyncBase):
215
219
 
216
220
  try:
217
221
  if self.id:
218
- if self.srid != self.BASE_SRID:
219
- self = self.transform(self.BASE_SRID)
220
- self.data['geometry'] = self.original_geometry
221
222
  await self.update(self.data)
222
- self.coordinates = data['geometry']['coordinates']
223
+
223
224
  except AttributeError:
224
225
  if self.srid != self.BASE_SRID:
225
226
  self = self.transform(self.BASE_SRID)
@@ -273,17 +274,28 @@ class AsyncFeature(AsyncBase):
273
274
  ... }
274
275
  >>> await feature.update(geojson)
275
276
  """
276
- return await super()._update(self.endpoint, geojson, clean=False)
277
+ self.data = geojson
278
+ data = self.data.copy()
279
+ srid = self.srid
280
+
281
+ if self.srid != self.BASE_SRID:
282
+ self = self.transform(self.BASE_SRID)
283
+
284
+ await super()._update(self.endpoint, self.data, clean=False)
285
+ self.data['geometry'] = data['geometry']
286
+ self._srid = srid
287
+ return self.data
277
288
 
278
289
 
279
290
  @classmethod
280
- async def create_feature(cls, layer: 'VectorLayer', geojson: Dict) -> 'AsyncFeature':
291
+ async def create_feature(cls, layer: 'VectorLayer', geojson: Dict, srid: int = 3857) -> 'AsyncFeature':
281
292
  """
282
293
  [async] Create a new feature in the vector layer.
283
294
 
284
295
  Args:
285
296
  layer (VectorLayer): The vector layer to create the feature in
286
297
  geojson (Dict): The GeoJSON data for the feature
298
+ srid (int, optional): the feature srid. default: 3857
287
299
 
288
300
  Returns:
289
301
  AsyncFeature: The created feature instance
@@ -299,8 +311,19 @@ class AsyncFeature(AsyncBase):
299
311
  ... }
300
312
  >>> feature = await Feature.create_feature(layer, geojson)
301
313
  """
314
+ feature = AsyncFeature(layer, srid=srid, data=geojson)
315
+ data = feature.data.copy()
316
+ srid = feature.srid
317
+
318
+ if feature.srid != feature.BASE_SRID:
319
+ feature = feature.transform(feature.BASE_SRID)
320
+
302
321
  endpoint = urljoin(layer.endpoint, 'features/')
303
- return await cls._create(layer.api, endpoint, geojson, factory_func=lambda api, item: AsyncFeature(layer, data=item))
322
+
323
+ feature = await cls._create(layer.api, endpoint, feature.data, factory_func=lambda api, item: AsyncFeature(layer, data=item))
324
+ feature.data['geometry'] = data['geometry']
325
+ feature._srid = srid
326
+ return feature
304
327
 
305
328
 
306
329
  @classmethod
@@ -360,10 +383,7 @@ class AsyncFeature(AsyncBase):
360
383
  "Install it with: pip install geobox[geometry]"
361
384
  )
362
385
 
363
- if not self.data:
364
- return None
365
-
366
- elif not self.data.get('geometry'):
386
+ if not self.data.get('geometry'):
367
387
  raise ValueError("Geometry is not present in the feature data")
368
388
 
369
389
  elif not isinstance(self.data['geometry'], dict):
geobox/aio/task.py CHANGED
@@ -2,6 +2,7 @@ import time
2
2
  import asyncio
3
3
  from urllib.parse import urljoin
4
4
  from typing import Optional, Dict, List, Optional, Union, TYPE_CHECKING
5
+ import logging
5
6
 
6
7
  from .base import AsyncBase
7
8
  from ..enums import TaskStatus
@@ -16,6 +17,8 @@ if TYPE_CHECKING:
16
17
  from ..api import GeoboxClient
17
18
  from ..task import Task
18
19
 
20
+ logger = logging.getLogger(__name__)
21
+
19
22
 
20
23
  class AsyncTask(AsyncBase):
21
24
 
@@ -233,7 +236,7 @@ class AsyncTask(AsyncBase):
233
236
  return await self._wait(timeout, interval, progress_bar)
234
237
  except Exception as e:
235
238
  last_exception = e
236
- print(f"[Retry {attempt}/{retry}] Task wait failed: {e}")
239
+ logger.warning(f"[Retry {attempt}/{retry}] Task wait failed: {e}")
237
240
  time.sleep(interval)
238
241
  raise last_exception
239
242
 
geobox/aio/vectorlayer.py CHANGED
@@ -755,12 +755,13 @@ class AsyncVectorLayer(AsyncBase):
755
755
  return feature
756
756
 
757
757
 
758
- async def create_feature(self, geojson: Dict)-> 'AsyncFeature':
758
+ async def create_feature(self, geojson: Dict, srid: int = AsyncFeature.BASE_SRID)-> 'AsyncFeature':
759
759
  """
760
760
  [async] Create a new feature in the layer.
761
761
 
762
762
  Args:
763
763
  geojson (Dict): The feature data including properties and geometry.
764
+ srid (int, optional): the feature srid. default: 3857
764
765
 
765
766
  Returns:
766
767
  Feature: The newly created feature instance.
@@ -780,7 +781,7 @@ class AsyncVectorLayer(AsyncBase):
780
781
  ... }
781
782
  >>> feature = await layer.create_feature(geojson=geojson)
782
783
  """
783
- return await AsyncFeature.create_feature(self, geojson)
784
+ return await AsyncFeature.create_feature(self, geojson, srid=srid)
784
785
 
785
786
 
786
787
  async def delete_features(self,
geobox/feature.py CHANGED
@@ -34,7 +34,7 @@ class Feature(Base):
34
34
  ... "type": "Feature",
35
35
  ... "geometry": {
36
36
  ... "type": "Point",
37
- ... "coordinates": [58.4, 23.6]
37
+ ... "coordinates": [10.0, 10.0]
38
38
  ... },
39
39
  ... "properties": {
40
40
  ... "name": "Test feature"
@@ -46,7 +46,11 @@ class Feature(Base):
46
46
  super().__init__(api=layer.api)
47
47
  self.layer = layer
48
48
  self._srid = srid
49
- self.data = data or {}
49
+ self.data = data or {
50
+ "type": "Feature",
51
+ "geometry": {},
52
+ "properties": {}
53
+ }
50
54
  self.original_geometry = self.data.get('geometry')
51
55
  self.endpoint = urljoin(layer.endpoint, f'features/{self.data.get("id")}/') if self.data.get('id') else None
52
56
 
@@ -232,11 +236,8 @@ class Feature(Base):
232
236
 
233
237
  try:
234
238
  if self.id:
235
- if self.srid != self.BASE_SRID:
236
- self = self.transform(self.BASE_SRID)
237
- self.data['geometry'] = self.original_geometry
238
239
  self.update(self.data)
239
- self.coordinates = data['geometry']['coordinates']
240
+
240
241
  except AttributeError:
241
242
  if self.srid != self.BASE_SRID:
242
243
  self = self.transform(self.BASE_SRID)
@@ -291,17 +292,28 @@ class Feature(Base):
291
292
  ... }
292
293
  >>> feature.update(geojson)
293
294
  """
294
- return super()._update(self.endpoint, geojson, clean=False)
295
+ self.data = geojson
296
+ data = self.data.copy()
297
+ srid = self.srid
298
+
299
+ if self.srid != self.BASE_SRID:
300
+ self = self.transform(self.BASE_SRID)
301
+
302
+ super()._update(self.endpoint, self.data, clean=False)
303
+ self.data['geometry'] = data['geometry']
304
+ self._srid = srid
305
+ return self.data
295
306
 
296
307
 
297
308
  @classmethod
298
- def create_feature(cls, layer: 'VectorLayer', geojson: Dict) -> 'Feature':
309
+ def create_feature(cls, layer: 'VectorLayer', geojson: Dict, srid: int = 3857) -> 'Feature':
299
310
  """
300
311
  Create a new feature in the vector layer.
301
312
 
302
313
  Args:
303
314
  layer (VectorLayer): The vector layer to create the feature in
304
315
  geojson (Dict): The GeoJSON data for the feature
316
+ srid (int, optional): the feature srid. default: 3857
305
317
 
306
318
  Returns:
307
319
  Feature: The created feature instance
@@ -318,8 +330,19 @@ class Feature(Base):
318
330
  ... }
319
331
  >>> feature = Feature.create_feature(layer, geojson)
320
332
  """
333
+ feature = Feature(layer, srid=srid, data=geojson)
334
+ data = feature.data.copy()
335
+ srid = feature.srid
336
+
337
+ if feature.srid != feature.BASE_SRID:
338
+ feature = feature.transform(feature.BASE_SRID)
339
+
321
340
  endpoint = urljoin(layer.endpoint, 'features/')
322
- return cls._create(layer.api, endpoint, geojson, factory_func=lambda api, item: Feature(layer, data=item))
341
+
342
+ feature = cls._create(layer.api, endpoint, feature.data, factory_func=lambda api, item: Feature(layer, data=item))
343
+ feature.data['geometry'] = data['geometry']
344
+ feature._srid = srid
345
+ return feature
323
346
 
324
347
 
325
348
  @classmethod
@@ -380,10 +403,8 @@ class Feature(Base):
380
403
  "Install it with: pip install geobox[geometry]"
381
404
  )
382
405
 
383
- if not self.data:
384
- return None
385
406
 
386
- elif not self.data.get('geometry'):
407
+ if not self.data.get('geometry'):
387
408
  raise ValueError("Geometry is not present in the feature data")
388
409
 
389
410
  elif not isinstance(self.data['geometry'], dict):
geobox/task.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from urllib.parse import urljoin, urlencode
2
2
  from typing import Optional, Dict, List, Optional, Union, TYPE_CHECKING
3
3
  import time
4
+ import logging
4
5
 
5
6
  from .base import Base
6
7
  from .enums import TaskStatus
@@ -15,6 +16,8 @@ if TYPE_CHECKING:
15
16
  from .aio import AsyncGeoboxClient
16
17
  from .aio.task import AsyncTask
17
18
 
19
+ logger = logging.getLogger(__name__)
20
+
18
21
 
19
22
  class Task(Base):
20
23
 
@@ -230,7 +233,7 @@ class Task(Base):
230
233
  return self._wait(timeout, interval, progress_bar)
231
234
  except Exception as e:
232
235
  last_exception = e
233
- print(f"[Retry {attempt}/{retry}] Task wait failed: {e}")
236
+ logger.warning(f"[Retry {attempt}/{retry}] Task wait failed: {e}")
234
237
  time.sleep(interval)
235
238
  raise last_exception
236
239
 
geobox/vectorlayer.py CHANGED
@@ -756,12 +756,13 @@ class VectorLayer(Base):
756
756
  return feature
757
757
 
758
758
 
759
- def create_feature(self, geojson: Dict)-> 'Feature':
759
+ def create_feature(self, geojson: Dict, srid: int = Feature.BASE_SRID)-> 'Feature':
760
760
  """
761
761
  Create a new feature in the layer.
762
762
 
763
763
  Args:
764
764
  geojson (Dict): The feature data including properties and geometry.
765
+ srid (int, optional): the feature srid. default: 3857
765
766
 
766
767
  Returns:
767
768
  Feature: The newly created feature instance.
@@ -781,7 +782,7 @@ class VectorLayer(Base):
781
782
  ... }
782
783
  >>> feature = layer.create_feature(geojson=geojson)
783
784
  """
784
- return Feature.create_feature(self, geojson)
785
+ return Feature.create_feature(self, geojson, srid=srid)
785
786
 
786
787
 
787
788
  def delete_features(self, q: str = None, bbox: str = None, bbox_srid: int = None, feature_ids: List[int] = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geobox
3
- Version: 2.2.1
3
+ Version: 2.2.3
4
4
  Summary: SDK for Geobox's APIs
5
5
  Author-email: Hamid Heydari <heydari.h62@gmail.com>
6
6
  License: MIT
@@ -7,7 +7,7 @@ geobox/basemap.py,sha256=BSDb7mJm-Pmm5GRqvsHxKiqBNL_wfzy_GVv1qqTVFLc,5746
7
7
  geobox/dashboard.py,sha256=Gkt66_WqJEco2olFfZ7W8ux3IhhbbudVqfLlB3t8MCs,13039
8
8
  geobox/enums.py,sha256=jA5KwOdTMkFhXEBgcP-8bgi0cFyD1NFN4QpLelow0HA,8044
9
9
  geobox/exception.py,sha256=jvpnv0M2Ck1FpxHTL_aKYWxGvLnCQ3d9vOrMIktjw1U,1507
10
- geobox/feature.py,sha256=63AaEUkCnT9kbiEIh7LUqnuy2Op0qUPN_oQik0tjfFY,19924
10
+ geobox/feature.py,sha256=YP-wCSxEin93ji6Hq72LG7j1VjGC0Jk05g06IOW_W8I,20455
11
11
  geobox/field.py,sha256=_5CS3kj3P-BKCbtAUd7dtkPBnN0D0H1ZKPlKx8DValw,11188
12
12
  geobox/file.py,sha256=cPj3cYjK85BqWIROfA-c1B-yw6d7Gu5ZzyCmFqAJSVY,20191
13
13
  geobox/layout.py,sha256=qnmFYFeVK-_mMjbzPJHAh9DcoMAdz-tzLDoHMpHST-Q,12608
@@ -22,14 +22,14 @@ geobox/raster_analysis.py,sha256=yoWA5_-GixyAJMpo8cHmZcYrEYUvwo2395BwrGlUBaA,349
22
22
  geobox/route.py,sha256=cKZTTHBHM8woWbhHIpCvrRX_doJcTkGktouee0z7oG0,2723
23
23
  geobox/scene.py,sha256=NEeXfOJGj8o7zIMZQjgLGf0FSzba-UMd3P-7KfkGwTs,12621
24
24
  geobox/settings.py,sha256=rYxBdiDUtQTuca5e12j6jyQYafW7gDUeb1U9ES-sk64,6999
25
- geobox/task.py,sha256=Fn2YqyWd9DeZVR92SJO4OQzmz1PfEegA7_VyJ1jgyws,14870
25
+ geobox/task.py,sha256=X78BA90F4Q1yfMdxNYBKXWfwk5O3m_p6clhEiJPEiHA,14935
26
26
  geobox/tile3d.py,sha256=mMRwwpWmHoCyR4UFKrRnM-xLPacmLrPASYhphP0W8u8,12351
27
27
  geobox/tileset.py,sha256=p6fmOyAunwfWKhmjSgWGc060jM2MVfrnQGC_qoE_AIw,25006
28
28
  geobox/usage.py,sha256=nnFq95fB4jdR8Uo0T09izejrrv14jpqoqbvQ8nixajg,9185
29
29
  geobox/user.py,sha256=1tbIfBRko56kHk3BKp3-Jjqm61xlqcmKZq6aKqbxNAY,17953
30
30
  geobox/utils.py,sha256=JmlRqDVIo0vBikzH1XakRrCrEIfLA7_eTJnBWBvGhJI,2243
31
31
  geobox/vector_tool.py,sha256=q6bKhuUI6Zy6DVJU7s5OnooGlfdCRa1EPHnaLXfjeZo,86273
32
- geobox/vectorlayer.py,sha256=OaCWg8n1dvlzNIJ_c98WFU2BEGQBRW_AJxJt4bNxz_8,58593
32
+ geobox/vectorlayer.py,sha256=QYa_-eBk9WdMYUdGeC8MaqsYm1P6tk5J2tgejrzgv_g,58701
33
33
  geobox/version.py,sha256=KcPCSe9vD6rc11qaTVO8UxYwXRX-0r0tQVaF-CJPfB0,10797
34
34
  geobox/view.py,sha256=DJL1wdccZC_ZR6V5hYDYDFZCC9lqle4wheaIOxOa__I,43266
35
35
  geobox/workflow.py,sha256=SWq4y6J4-6GwYn8uKWTAdYj0rX6romF_s20C0Cth8d0,12931
@@ -40,7 +40,7 @@ geobox/aio/attachment.py,sha256=4IzC8Vnt_LJHSzhfhyMtGqrv1AHibkLWO-mOCCtRyO8,1336
40
40
  geobox/aio/base.py,sha256=H9CB-5Gas3c1Xp14nW-PS-syoGNBpyRLN2iujlSxWLU,9455
41
41
  geobox/aio/basemap.py,sha256=7NeEihNGjVZgc6TRfM2w_3RuAGNXRRpEFItmMlR4e4A,6092
42
42
  geobox/aio/dashboard.py,sha256=L91YkVHtcb9QMozoIBOjiobskDM1NfxasVcTZs6hV3U,13843
43
- geobox/aio/feature.py,sha256=6YYZvKXccJ2chnhsyhOIrSCn3aaGEiVgvHRgslKEJ9Y,20012
43
+ geobox/aio/feature.py,sha256=BouLyHGqpHsxMkSEs5EEPwzyzDdkzqnxlWZ7td1b-tY,20523
44
44
  geobox/aio/field.py,sha256=KTN6P1edmPj7NlLEyUHx2BW6dY0TLPdHjCefB6_4L5g,11512
45
45
  geobox/aio/file.py,sha256=RaygwYB4fkmxQyIG__NZZCdnXc7olOY2UC9qGQ3UhkQ,21217
46
46
  geobox/aio/layout.py,sha256=IasLEPVq5U_9VbTPPo-JqxKL4rPxWrVFoHbRdQZk9iY,13471
@@ -55,18 +55,18 @@ geobox/aio/raster_analysis.py,sha256=aSU_E8TXrex2x9w3S4WCWGTu0q81qOBN0rXo5uG5IgM
55
55
  geobox/aio/route.py,sha256=dkKsK4ZjL7XikgoZ3lJfkr2UXwrmxct4Qt2DzZg0upE,2860
56
56
  geobox/aio/scene.py,sha256=28R3cig3HZPPEhcOlb6_WQ210hxPIYgVg14ae8tnCPg,13402
57
57
  geobox/aio/settings.py,sha256=w3QcncZ2OposVHQeQKYOTowj-zFAWuEHN-2ZMzKOe14,7009
58
- geobox/aio/task.py,sha256=aE1OjhZOAl_xAy3OVhXan-wxWc1-wVEbyJ7UeFQF_2c,15868
58
+ geobox/aio/task.py,sha256=ghw_1RU7QkGI2XEwQhz2WRZ6DWqdmwa0yTFx-CBeOAE,15933
59
59
  geobox/aio/tile3d.py,sha256=bN7IqmNzIfW0ofZUh49FjnakV2tuPUQnQgiA83zqrmE,13266
60
60
  geobox/aio/tileset.py,sha256=t2pcC2NmS1uVrpJqci9XUuSKEuq4v05fW2AS5QBTK3w,27639
61
61
  geobox/aio/usage.py,sha256=_I153m0uza7ZooMdHInBVmTt14SCu1qmvvmr80zmVLM,9506
62
62
  geobox/aio/user.py,sha256=-7DJW-mi6_wrJFIfL3oto7YqNoLTg7fLAZEFn9yiAhQ,19056
63
63
  geobox/aio/vector_tool.py,sha256=_6sFu7WllK82M7E6zl0Tteb7at05OsgMnWUEDlD41sk,92886
64
- geobox/aio/vectorlayer.py,sha256=flA3MQFD1Qm6TohftcTXfDQ5VGZztHr1K3zhZZ0x2og,59313
64
+ geobox/aio/vectorlayer.py,sha256=d7BAPjp1MsFWhrgDh3gJ8LBAIA_2-vCGCT0ji9-e1O4,59426
65
65
  geobox/aio/version.py,sha256=Yt7tKUqHS8rKfTPAm77yAaDajFn0ZEo0UWhA5DN7_uM,11422
66
66
  geobox/aio/view.py,sha256=CMULdkierGeIvRWdyfqy6FO_9_fgQeSAA1-xdcrl9Uw,45146
67
67
  geobox/aio/workflow.py,sha256=UwOVMDRjJIiveXbYB8rGO02s5A7fn2BhEvQXkWMSApU,13707
68
- geobox-2.2.1.dist-info/licenses/LICENSE,sha256=AvFB7W94sJYKLDhBxLRshL3upexCOG8HQY_1JibB96w,1063
69
- geobox-2.2.1.dist-info/METADATA,sha256=_XDz9bfQYs0hAhFYWLxfCsemT183cW5YBPVPcZ_wbZo,3082
70
- geobox-2.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
- geobox-2.2.1.dist-info/top_level.txt,sha256=ppXH8Bu2mlB-pLQ6lsoWEm2Gr6wZx1uzkhetsYA5ins,7
72
- geobox-2.2.1.dist-info/RECORD,,
68
+ geobox-2.2.3.dist-info/licenses/LICENSE,sha256=AvFB7W94sJYKLDhBxLRshL3upexCOG8HQY_1JibB96w,1063
69
+ geobox-2.2.3.dist-info/METADATA,sha256=rhrWYWX5FpB_3a3LdlHJd-X_tiWw3CZcy25EJdgysJU,3082
70
+ geobox-2.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
+ geobox-2.2.3.dist-info/top_level.txt,sha256=ppXH8Bu2mlB-pLQ6lsoWEm2Gr6wZx1uzkhetsYA5ins,7
72
+ geobox-2.2.3.dist-info/RECORD,,
File without changes