geobox 2.0.0__py3-none-any.whl → 2.1.0__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/api.py CHANGED
@@ -3,9 +3,11 @@ import asyncio
3
3
  import logging
4
4
  import os
5
5
  from urllib.parse import urljoin
6
- from typing import Dict, List, Union, Any
6
+ from typing import Dict, List, Optional, Union, Any
7
7
  from datetime import datetime
8
8
 
9
+ from geobox.enums import AnalysisDataType, AnalysisResampleMethod
10
+
9
11
  from ..api import GeoboxClient as SyncGeoboxClient
10
12
  from .vectorlayer import VectorLayer, LayerType
11
13
  from .feature import Feature
@@ -762,7 +764,7 @@ class AsyncGeoboxClient(SyncGeoboxClient):
762
764
  return await VectorLayerView.get_views_by_ids(self, ids, user_id, include_settings)
763
765
 
764
766
 
765
- async def get_view(self, uuid: str) -> 'VectorLayerView':
767
+ async def get_view(self, uuid: str, user_id: int = None) -> 'VectorLayerView':
766
768
  """
767
769
  [async] Get a specific vector layer view by its UUID.
768
770
 
@@ -778,7 +780,7 @@ class AsyncGeoboxClient(SyncGeoboxClient):
778
780
  >>> async with AsyncGeoboxClient() as client:
779
781
  >>> view = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
780
782
  """
781
- return await VectorLayerView.get_view(self, uuid)
783
+ return await VectorLayerView.get_view(self, uuid, user_id)
782
784
 
783
785
 
784
786
  async def get_view_by_name(self, name: str, user_id: int = None) -> Union['VectorLayerView', None]:
@@ -2637,4 +2639,101 @@ class AsyncGeoboxClient(SyncGeoboxClient):
2637
2639
  >>> async with AsyncGeoboxClient() as client:
2638
2640
  >>> await client.update_usage()
2639
2641
  """
2640
- return await Usage.update_usage(self, user_id=user_id)
2642
+ return await Usage.update_usage(self, user_id=user_id)
2643
+
2644
+
2645
+ async def raster_calculator(self,
2646
+ variables: str,
2647
+ expr: str,
2648
+ output_raster_name: str,
2649
+ match_raster_uuid: Optional[str] = None,
2650
+ resample: AnalysisResampleMethod = AnalysisResampleMethod.bilinear,
2651
+ out_dtype: AnalysisDataType = AnalysisDataType.float32,
2652
+ dst_nodata: int = -9999,
2653
+ user_id: Optional[int] = None) -> 'Task':
2654
+ """
2655
+ [async] Perform raster calculator operations on multiple raster datasets.
2656
+
2657
+ it allows you to perform mathematical operations on one or more raster datasets using NumPy expressions.
2658
+ Variables in the expression correspond to raster datasets specified in the variables dictionary.
2659
+
2660
+ Examples:
2661
+ NDVI calculation: variables='{"NIR": "raster_uuid_1", "RED": "raster_uuid_2"}', expr="(NIR-RED)/(NIR+RED)"
2662
+ Slope threshold: variables='{"SLOPE": "raster_uuid_1"}', expr="np.where(SLOPE>30,1,0)"
2663
+ Multi-band operations: variables='{"IMG": ["raster_uuid_1", 2]}', expr="IMG*2"
2664
+
2665
+ Args:
2666
+ variables (str): JSON string mapping variable names to raster specifications. Format: '{"NIR": "raster_uuid_1", "RED": "raster_uuid_2"}' or '{"IMG": ["raster_uuid_1", 2]}' for multi-band operations.
2667
+ expr (str): Mathematical expression using NumPy syntax. Use variable names from the variables dict, e.g., '(NIR-RED)/(NIR+RED)' or 'where(SLOPE>30,1,0)' or 'where((dist_to_highway < 1000) & (slope < 10), 1, 0)' .Supported functions: np, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, log, log10, sqrt, abs, floor, ceil, round, minimum, maximum, clip, where, isnan, isfinite, pi, e.
2668
+ output_raster_name (str): Name for the output raster dataset.
2669
+ match_raster_uuid (str, optional): Optional raster UUID to match the output grid and projection. If not provided, the first variable becomes the reference grid.
2670
+ resample (CropResample, optional): Resampling method: 'near', 'bilinear', 'cubic', 'lanczos', etc. default: CropResample.near
2671
+ out_dtype (AnalysisDataType, optional): Data type for the output raster (e.g., int16, float32). default: AnalysisDataType.float32
2672
+ dst_nodata (int, optional): NoData value for the output raster. default = -9999
2673
+ user_id (int, optional): specific user. priviledges required!
2674
+
2675
+ Returns:
2676
+ Task: task instance of the process
2677
+
2678
+ Example:
2679
+ >>> from geobox.aio import AsyncGeoboxClient
2680
+ >>> async with AsyncGeoboxClient() as client:
2681
+ >>> task = await client.raster_calculator(api=client, variables={"NIR": "raster_uuid_1", "RED": "raster_uuid_2"},
2682
+ ... expr='where(SLOPE>30,1,0)',
2683
+ ... output_raster_name='test')
2684
+ """
2685
+ from .analysis import Analysis
2686
+ return await Analysis.calculator(self,
2687
+ variables=variables,
2688
+ expr=expr,
2689
+ output_raster_name=output_raster_name,
2690
+ match_raster_uuid=match_raster_uuid,
2691
+ resample=resample,
2692
+ out_dtype=out_dtype,
2693
+ dst_nodata=dst_nodata,
2694
+ user_id=user_id)
2695
+
2696
+
2697
+ async def create_constant_raster(self,
2698
+ output_raster_name: str,
2699
+ extent: str,
2700
+ value : int,
2701
+ pixel_size: int = 10,
2702
+ dtype: AnalysisDataType = AnalysisDataType.float32,
2703
+ nodata: int = -9999,
2704
+ align_to: Optional[str] = None,
2705
+ user_id: Optional[int] = None) -> 'Task':
2706
+ """
2707
+ [async] Create a raster filled with a constant value.
2708
+
2709
+ This endpoint creates a north-up GeoTIFF filled with a constant value.
2710
+ Only users with Publisher role or higher can perform this operation.
2711
+
2712
+ Args:
2713
+ output_raster_name (str): Name for the output constant raster dataset.
2714
+ extent (str): Extent as 'minX,minY,maxX,maxY' (e.g., '0,0,100,100').
2715
+ value (int): Constant value to fill the raster with.
2716
+ pixel_size (int, optional): Pixel size for the output raster (must be > 0). default: 10
2717
+ dtype (AnalysisDataType, optoinal): Output data type. default: AnalysisDataType.float32
2718
+ nodata (int, optional): NoData value for the raster. default: -9999
2719
+ align_to (str, optional): Grid origin to snap to as 'x0,y0' (e.g., '0,0').
2720
+ user_id (int, optional): specific user. priviledges required!
2721
+
2722
+ Returns:
2723
+ Task: task instance of the process
2724
+
2725
+ Example:
2726
+ >>> from geobox.aio import AsyncGeoboxClient
2727
+ >>> async with AsyncGeoboxClient() as client:
2728
+ >>> task = await client.create_constant_raster(output_raster_name='test', extent='0,0,100,100', value=10)
2729
+ """
2730
+ from .analysis import Analysis
2731
+ return await Analysis.constant(self,
2732
+ output_raster_name=output_raster_name,
2733
+ extent=extent,
2734
+ value=value,
2735
+ pixel_size=pixel_size,
2736
+ dtype=dtype,
2737
+ nodata=nodata,
2738
+ align_to=align_to,
2739
+ user_id=user_id)
geobox/aio/query.py CHANGED
@@ -349,8 +349,6 @@ class Query(AsyncBase):
349
349
  >>> query.add_param(name='param_name', value='param_value', type=QueryParamType.LAYER)
350
350
  >>> await query.save()
351
351
  """
352
- self._check_access()
353
-
354
352
  self.params.append({
355
353
  'name': name,
356
354
  'value': value,
@@ -384,8 +382,6 @@ class Query(AsyncBase):
384
382
  >>> query.remove_param(name='param_name')
385
383
  >>> await quary.save()
386
384
  """
387
- self._check_access()
388
-
389
385
  for i, param in enumerate(self.params):
390
386
  if param.get('name') == name:
391
387
  self.params.pop(i)
@@ -430,8 +426,6 @@ class Query(AsyncBase):
430
426
  >>> query = await client.get_query(uuid="12345678-1234-5678-1234-567812345678")
431
427
  >>> await query.execute(f='json')
432
428
  """
433
- self._check_access()
434
-
435
429
  if not self.sql:
436
430
  raise ValueError('"sql" parameter is required for this action!')
437
431
  if not self.params:
@@ -632,7 +626,6 @@ class Query(AsyncBase):
632
626
  >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
633
627
  >>> query.thumbnail
634
628
  """
635
- self._check_access()
636
629
  return super().thumbnail()
637
630
 
638
631
 
@@ -657,8 +650,6 @@ class Query(AsyncBase):
657
650
  >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
658
651
  >>> await query.save_as_layer(layer_name='test')
659
652
  """
660
- self._check_access()
661
-
662
653
  params = [{
663
654
  "name": item.get('name'),
664
655
  "type": item.get('type'),