geobox 2.0.1__py3-none-any.whl → 2.2.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.
Files changed (70) hide show
  1. geobox/__init__.py +61 -63
  2. geobox/aio/__init__.py +61 -63
  3. geobox/aio/api.py +489 -473
  4. geobox/aio/apikey.py +263 -263
  5. geobox/aio/attachment.py +341 -339
  6. geobox/aio/base.py +261 -262
  7. geobox/aio/basemap.py +196 -196
  8. geobox/aio/dashboard.py +340 -342
  9. geobox/aio/feature.py +23 -33
  10. geobox/aio/field.py +315 -321
  11. geobox/aio/file.py +72 -72
  12. geobox/aio/layout.py +340 -341
  13. geobox/aio/log.py +23 -23
  14. geobox/aio/map.py +1033 -1034
  15. geobox/aio/model3d.py +415 -415
  16. geobox/aio/mosaic.py +696 -696
  17. geobox/aio/plan.py +314 -314
  18. geobox/aio/query.py +693 -693
  19. geobox/aio/raster.py +907 -869
  20. geobox/aio/raster_analysis.py +740 -0
  21. geobox/aio/route.py +4 -4
  22. geobox/aio/scene.py +340 -342
  23. geobox/aio/settings.py +18 -18
  24. geobox/aio/task.py +404 -402
  25. geobox/aio/tile3d.py +337 -339
  26. geobox/aio/tileset.py +102 -103
  27. geobox/aio/usage.py +52 -51
  28. geobox/aio/user.py +506 -507
  29. geobox/aio/vector_tool.py +1968 -0
  30. geobox/aio/vectorlayer.py +315 -306
  31. geobox/aio/version.py +272 -273
  32. geobox/aio/view.py +1019 -983
  33. geobox/aio/workflow.py +340 -341
  34. geobox/api.py +18 -2
  35. geobox/apikey.py +262 -262
  36. geobox/attachment.py +336 -337
  37. geobox/base.py +384 -384
  38. geobox/basemap.py +194 -194
  39. geobox/dashboard.py +339 -341
  40. geobox/enums.py +432 -348
  41. geobox/feature.py +5 -5
  42. geobox/field.py +320 -320
  43. geobox/file.py +4 -4
  44. geobox/layout.py +339 -340
  45. geobox/log.py +4 -4
  46. geobox/map.py +1031 -1032
  47. geobox/model3d.py +410 -410
  48. geobox/mosaic.py +696 -696
  49. geobox/plan.py +313 -313
  50. geobox/query.py +691 -691
  51. geobox/raster.py +907 -863
  52. geobox/raster_analysis.py +737 -0
  53. geobox/scene.py +341 -342
  54. geobox/settings.py +194 -194
  55. geobox/task.py +399 -400
  56. geobox/tile3d.py +337 -338
  57. geobox/tileset.py +4 -4
  58. geobox/usage.py +3 -3
  59. geobox/user.py +503 -503
  60. geobox/vector_tool.py +1968 -0
  61. geobox/vectorlayer.py +5 -5
  62. geobox/version.py +272 -272
  63. geobox/view.py +981 -981
  64. geobox/workflow.py +338 -339
  65. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/METADATA +15 -1
  66. geobox-2.2.0.dist-info/RECORD +72 -0
  67. geobox-2.0.1.dist-info/RECORD +0 -68
  68. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/WHEEL +0 -0
  69. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/licenses/LICENSE +0 -0
  70. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,740 @@
1
+ from typing import Dict, Optional, TYPE_CHECKING, Union
2
+
3
+ from geobox.field import Field
4
+
5
+ from .vectorlayer import AsyncVectorLayer
6
+ from .view import AsyncVectorLayerView
7
+ from .base import AsyncBase
8
+ from .raster import AsyncRaster
9
+ from ..enums import (AnalysisDataType, PolygonizeConnectivity, AnalysisResampleMethod,
10
+ SlopeUnit, AnalysisAlgorithm, RangeBound, DistanceUnit)
11
+ from ..utils import clean_data
12
+
13
+ if TYPE_CHECKING:
14
+ from . import AsyncGeoboxClient
15
+ from .task import AsyncTask
16
+
17
+ class AsyncRasterAnalysis(AsyncBase):
18
+
19
+ BASE_ENDPOINT = 'analysis/'
20
+
21
+ def __init__(self,
22
+ api: 'AsyncGeoboxClient',
23
+ data: Optional[Dict] = {}):
24
+ """
25
+ [async] Initialize a workflow instance.
26
+
27
+ Args:
28
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
29
+ uuid (str): The unique identifier for the workflow.
30
+ data (Dict): The response data of the workflow.
31
+ """
32
+ super().__init__(api, data=data)
33
+
34
+
35
+ def __repr__(self) -> str:
36
+ return f"AsyncRasterAnalysis()"
37
+
38
+
39
+ async def rasterize(self,
40
+ layer: Union[AsyncVectorLayer, AsyncVectorLayerView],
41
+ output_raster_name: str,
42
+ pixel_size: int = 10,
43
+ nodata: Optional[int] = -9999,
44
+ data_type: Optional[AnalysisDataType] = AnalysisDataType.int16,
45
+ burn_value: Optional[int] = 1,
46
+ burn_attribute: Optional[str] = None,
47
+ user_id: Optional[int] = None) -> 'AsyncTask':
48
+ """
49
+ [async] Rasterize a vector layer
50
+
51
+ This method converts a vector layer (or view) to a raster dataset using the specified parameters.
52
+ You can control the output raster's name, pixel size, data type, nodata value, and the value to burn (either a constant or from an attribute field).
53
+ Only users with Publisher role or higher can perform this operation.
54
+
55
+ Args:
56
+ layer (AsyncVectorLayer | AsyncVectorLayerView): VectorLayer or VectorLayerView instance
57
+ output_raster_name (str): Name for the output raster dataset
58
+ pixel_size (int, optional): Pixel size for the output raster (must be > 0). default: 10
59
+ nodata (int, optional): NoData value to use in the output raster. default: -9999
60
+ data_type (AnalysisDataType, optional): Data type for the output raster (e.g., int16, float32). default: AnalysisDataType.int16
61
+ burn_value (int, optional): Value to burn into the raster for all features (if burn_attribute is not set). default: 1
62
+ burn_attribute (str, optional): Name of the attribute field to use for burning values into the raster
63
+ user_id (int, optional): specific user. priviledges required!
64
+
65
+ Returns:
66
+ AsyncTask: task instance of the process
67
+
68
+ Example:
69
+ >>> from geobox.aio import AsyncGeoboxClient
70
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
71
+ >>> async with AsyncGeoboxClient() as client:
72
+ >>> vector = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
73
+ >>> task = await client.raster_analysis.rasterize(layer=vector, output_raster_name='test')
74
+ or
75
+ >>> raster_analysis = AsyncRasterAnalysis(client)
76
+ >>> task = await raster_analysis.rasterize(layer=vector, output_raster_name='test')
77
+ """
78
+ if not isinstance(layer, AsyncVectorLayer) and not isinstance(layer, AsyncVectorLayerView):
79
+ raise ValueError("'layer' input only accepts vector layer and view objects!")
80
+
81
+ endpoint = f'{self.BASE_ENDPOINT}rasterize/'
82
+
83
+ data = clean_data({
84
+ 'layer_uuid': layer.uuid,
85
+ 'output_raster_name': output_raster_name,
86
+ 'is_view': False if isinstance(layer, AsyncVectorLayer) else True,
87
+ 'pixel_size': pixel_size,
88
+ 'nodata': nodata,
89
+ 'data_type': data_type.value,
90
+ 'burn_value': burn_value,
91
+ 'burn_attribute': burn_attribute,
92
+ 'user_id': user_id
93
+ })
94
+
95
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
96
+ return await self.api.get_task(response['task_id'])
97
+
98
+
99
+ async def polygonize(self,
100
+ raster: 'AsyncRaster',
101
+ output_layer_name: str,
102
+ band_index: int = 1,
103
+ value_field: Optional[str] = None,
104
+ mask_nodata: bool = False,
105
+ connectivity: PolygonizeConnectivity = PolygonizeConnectivity.connected_4,
106
+ keep_values: Optional[str] = None,
107
+ layer_name: Optional[str] = None,
108
+ user_id: Optional[int] = None) -> 'AsyncTask':
109
+ """
110
+ [async] Convert a raster to vector polygons
111
+
112
+ vectorizes a raster (polygonize) to a vector dataset (*.gpkg). Only users with Publisher role or higher can perform this operation
113
+
114
+ Args:
115
+ raster (Raster): Raster instance
116
+ output_layer_name (str): Name for the output vector layer.
117
+ band_index (int, optional): Raster band to polygonize. default: 1
118
+ value_field (str, optional): Name of attribute field storing the pixel value. default: None
119
+ mask_nodata (bool, optional): If True, NoData pixels are excluded using the band mask. default: False
120
+ connectivity (PolygonizeConnectivity, optional): 4 or 8 connectivity for region grouping. default: PolygonizeConnectivity.connected_4
121
+ keep_values (str, optional): JSON array of values to keep (e.g., '[1,2,3]'). default: None
122
+ layer_name (str, optional): Output layer name. default: None
123
+ user_id (int, optional): specific user. priviledges required!
124
+
125
+ Returns:
126
+ AsyncTask: task instance of the process
127
+
128
+ Example:
129
+ >>> from geobox.aio import AsyncGeoboxClient
130
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
131
+ >>> async with AsyncGeoboxClient() as client:
132
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
133
+ >>> task = await client.raster_analysis.polygonize(raster=raster, output_layer_name='test')
134
+ or
135
+ >>> raster_analysis = AsyncRasterAnalysis(client)
136
+ >>> task = await raster_analysis.polygonize(raster=raster, output_layer_name='test')
137
+ """
138
+ endpoint = f'{self.BASE_ENDPOINT}polygonize/'
139
+
140
+ data = clean_data({
141
+ 'raster_uuid': raster.uuid,
142
+ 'output_layer_name': output_layer_name,
143
+ 'band_index': band_index,
144
+ 'value_field': value_field,
145
+ 'mask_nodata': mask_nodata,
146
+ 'connectivity': connectivity.value,
147
+ 'keep_values': keep_values,
148
+ 'layer_name': layer_name,
149
+ 'user_id': user_id
150
+ })
151
+
152
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
153
+ return await self.api.get_task(response['task_id'])
154
+
155
+
156
+ async def clip(self,
157
+ raster: 'AsyncRaster',
158
+ layer: Union[AsyncVectorLayer, AsyncVectorLayerView],
159
+ output_raster_name: str,
160
+ where: Optional[str] = None,
161
+ dst_nodata: int = -9999,
162
+ crop: bool = True,
163
+ resample: AnalysisResampleMethod = AnalysisResampleMethod.near,
164
+ user_id: Optional[int] = None) -> 'AsyncTask':
165
+ """
166
+ [async] Clip a raster using a vector layer as a mask
167
+
168
+ clips a raster dataset using a vector layer as the clipping boundary. Only users with Publisher role or higher can perform this operation
169
+
170
+ Args:
171
+ raster (Raster): Raster instance
172
+ layer (AsyncVectorLayer | AsyncVectorLayerView): VectorLayer or VectorLayerView instance
173
+ output_raster_name (str): Name for the output raster dataset
174
+ where (str, optional): Optional attribute filter, e.g. 'VEG=forest'.
175
+ dst_nodata (int, optional): Output NoData value. default: -9999
176
+ crop (bool, optional): True=shrink extent to polygon(s); False=keep full extent but mask outside. default: True
177
+ resample (CropResample, optional): Resampling method: 'near', 'bilinear', 'cubic', 'lanczos', etc. default: CropResample.near
178
+ user_id (int, optional): specific user. priviledges required!
179
+
180
+ Returns:
181
+ AsyncTask: task instance of the process
182
+
183
+ Example:
184
+ >>> from geobox.aio import AsyncGeoboxClient
185
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
186
+ >>> async with AsyncGeoboxClient() as client:
187
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
188
+ >>> vector = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
189
+ >>> task = await client.raster_analysis.clip(raster=raster, layer=vector, output_raster_name='test')
190
+ or
191
+ >>> raster_analysis = AsyncRasterAnalysis(client)
192
+ >>> task = await raster_analysis.clip(raster=raster, layer=vector, output_raster_name='test')
193
+ """
194
+ if not isinstance(layer, AsyncVectorLayer) and not isinstance(layer, AsyncVectorLayerView):
195
+ raise ValueError("'layer' input only accepts vector layer and view objects!")
196
+
197
+ endpoint = f'{self.BASE_ENDPOINT}clip/'
198
+
199
+ data = clean_data({
200
+ 'raster_uuid': raster.uuid,
201
+ 'layer_uuid': layer.uuid,
202
+ 'output_raster_name': output_raster_name,
203
+ 'is_view': False if isinstance(layer, AsyncVectorLayer) else True,
204
+ 'where': where,
205
+ 'dst_nodata': dst_nodata,
206
+ 'crop': crop,
207
+ 'resample': resample.value,
208
+ 'user_id': user_id
209
+ })
210
+
211
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
212
+ return await self.api.get_task(response['task_id'])
213
+
214
+
215
+ async def calculator(self,
216
+ variables: str,
217
+ expr: str,
218
+ output_raster_name: str,
219
+ match_raster_uuid: Optional[str] = None,
220
+ resample: AnalysisResampleMethod = AnalysisResampleMethod.bilinear,
221
+ out_dtype: AnalysisDataType = AnalysisDataType.float32,
222
+ dst_nodata: int = -9999,
223
+ user_id: Optional[int] = None) -> 'AsyncTask':
224
+ """
225
+ [async] Perform raster calculator operations on multiple raster datasets.
226
+
227
+ it allows you to perform mathematical operations on one or more raster datasets using NumPy expressions.
228
+ Variables in the expression correspond to raster datasets specified in the variables dictionary.
229
+
230
+ Examples:
231
+ NDVI calculation: variables='{"NIR": "raster_uuid_1", "RED": "raster_uuid_2"}', expr="(NIR-RED)/(NIR+RED)"
232
+ Slope threshold: variables='{"SLOPE": "raster_uuid_1"}', expr="np.where(SLOPE>30,1,0)"
233
+ Multi-band operations: variables='{"IMG": ["raster_uuid_1", 2]}', expr="IMG*2"
234
+
235
+ Args:
236
+ 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.
237
+ 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.
238
+ output_raster_name (str): Name for the output raster dataset.
239
+ 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.
240
+ resample (CropResample, optional): Resampling method: 'near', 'bilinear', 'cubic', 'lanczos', etc. default: CropResample.near
241
+ out_dtype (AnalysisDataType, optional): Data type for the output raster (e.g., int16, float32). default: AnalysisDataType.float32
242
+ dst_nodata (int, optional): NoData value for the output raster. default = -9999
243
+ user_id (int, optional): specific user. priviledges required!
244
+
245
+ Returns:
246
+ AsyncTask: task instance of the process
247
+
248
+ Example:
249
+ >>> from geobox.aio import AsyncGeoboxClient
250
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
251
+ >>> async with AsyncGeoboxClient() as client:
252
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
253
+ >>> task = await client.raster_analysis.calculator(variables={"NIR": "raster_uuid_1", "RED": "raster_uuid_2"},
254
+ ... expr='where(SLOPE>30,1,0)',
255
+ ... output_raster_name='test')
256
+ or
257
+ >>> raster_analysis = AsyncRasterAnalysis(client)
258
+ >>> task = raster_analysis.calculator(variables={"NIR": "raster_uuid_1", "RED": "raster_uuid_2"},
259
+ ... expr='where(SLOPE>30,1,0)',
260
+ ... output_raster_name='test')
261
+ """
262
+ endpoint = f'{self.BASE_ENDPOINT}calculator/'
263
+
264
+ data = clean_data({
265
+ 'variables': variables,
266
+ 'expr': expr,
267
+ 'output_raster_name': output_raster_name,
268
+ 'match_raster_uuid': match_raster_uuid,
269
+ 'resample': resample.value,
270
+ 'out_dtype': out_dtype.value,
271
+ 'dst_nodata': dst_nodata,
272
+ 'user_id': user_id
273
+ })
274
+
275
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
276
+ return await self.api.get_task(response['task_id'])
277
+
278
+
279
+ async def slope(self,
280
+ raster: 'AsyncRaster',
281
+ output_raster_name: str,
282
+ slope_units: SlopeUnit = SlopeUnit.degree,
283
+ algorithm: AnalysisAlgorithm = AnalysisAlgorithm.Horn,
284
+ scale: int = 1,
285
+ compute_edges: bool = True,
286
+ nodata_out: int = -9999,
287
+ user_id: Optional[int] = None) -> 'AsyncTask':
288
+ """
289
+ [async] Calculate slope from a DEM raster.
290
+
291
+ This endpoint creates a slope raster from a Digital Elevation Model (DEM). Only users with Publisher role or higher can perform this operation.
292
+
293
+ Args:
294
+ raster (Raster): DEM Raster instance
295
+ output_raster_name (str): Name for the output raster dataset.
296
+ slope_units (SlopeUnit, optional): Slope units: 'degree' or 'percent'. default: SlopeUnit.degree
297
+ algorithm (AnalysisAlgorithm, optional): Algorithm: 'Horn' or 'ZevenbergenThorne'. default: AnalysisAlgorithm.Horn
298
+ scale (int, optional): Ratio of vertical units to horizontal units. default: 1
299
+ compute_edges (bool, optional): Whether to compute edges. default: True
300
+ nodata (int, optional): NoData value for the output raster. default = -9999
301
+ user_id (int, optional): specific user. priviledges required!
302
+
303
+ Returns:
304
+ AsyncTask: task instance of the process
305
+
306
+ Example:
307
+ >>> from geobox.aio import AsyncGeoboxClient
308
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
309
+ >>> async with AsyncGeoboxClient() as client:
310
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
311
+ >>> task = await client.raster_analysis.slope(raster=raster, output_raster_name='test')
312
+ or
313
+ >>> raster_analysis = AsyncRasterAnalysis(client)
314
+ >>> task = await raster_analysis.slope(raster=raster, output_raster_name='test')
315
+ """
316
+ endpoint = f'{self.BASE_ENDPOINT}slope/'
317
+
318
+ data = clean_data({
319
+ 'raster_uuid': raster.uuid,
320
+ 'output_raster_name': output_raster_name,
321
+ 'slope_units': slope_units.value,
322
+ 'algorithm': algorithm.value,
323
+ 'scale': scale,
324
+ 'compute_edges': compute_edges,
325
+ 'nodata_out': nodata_out,
326
+ 'user_id': user_id
327
+ })
328
+
329
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
330
+ return await self.api.get_task(response['task_id'])
331
+
332
+
333
+ async def aspect(self,
334
+ raster: 'AsyncRaster',
335
+ output_raster_name: str,
336
+ algorithm: AnalysisAlgorithm = AnalysisAlgorithm.Horn,
337
+ trigonometric: bool = False,
338
+ zero_for_flat: bool = True,
339
+ compute_edges: bool = True,
340
+ nodata_out: int = -9999,
341
+ user_id: Optional[int] = None) -> 'AsyncTask':
342
+ """
343
+ [async] Calculate aspect from a DEM raster.
344
+
345
+ it creates an aspect raster (degrees 0–360) from a Digital Elevation Model (DEM).
346
+ Only users with Publisher role or higher can perform this operation.
347
+
348
+ Args:
349
+ raster (Raster): DEM Raster instance
350
+ output_raster_name (str): Name for the output raster dataset.
351
+ algorithm (AnalysisAlgorithm, optional): Algorithm: 'Horn' or 'ZevenbergenThorne'. default: AnalysisAlgorithm.Horn
352
+ trigonometric (bool, optional): False: azimuth (0°=N, 90°=E, clockwise); True: 0°=E, counter-clockwise. default: False
353
+ zero_for_flat (bool, optional): Set flats (slope==0) to 0 instead of NoData. default: True
354
+ compute_edges (bool, optional): Whether to compute edges. default: True
355
+ nodata (int, optional): NoData value for the output raster. default = -9999
356
+ user_id (int, optional): specific user. priviledges required!
357
+
358
+ Returns:
359
+ AsyncTask: task instance of the process
360
+
361
+ Example:
362
+ >>> from geobox.aio import AsyncGeoboxClient
363
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
364
+ >>> async with AsyncGeoboxClient() as client:
365
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
366
+ >>> task = await client.raster_analysis.aspect(raster=raster, output_raster_name='test')
367
+ or
368
+ >>> raster_analysis = AsyncRasterAnalysis(client)
369
+ >>> task = await raster_analysis.aspect(raster=raster, output_raster_name='test')
370
+ """
371
+
372
+ endpoint = f'{self.BASE_ENDPOINT}aspect/'
373
+
374
+ data = clean_data({
375
+ 'raster_uuid': raster.uuid,
376
+ 'output_raster_name': output_raster_name,
377
+ 'algorithm': algorithm.value,
378
+ 'trigonometric': trigonometric,
379
+ 'zero_for_flat': zero_for_flat,
380
+ 'compute_edges': compute_edges,
381
+ 'nodata_out': nodata_out,
382
+ 'user_id': user_id
383
+ })
384
+
385
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
386
+ return await self.api.get_task(response['task_id'])
387
+
388
+
389
+ async def reclassify(self,
390
+ raster: 'AsyncRaster',
391
+ output_raster_name: str,
392
+ rules: str,
393
+ default_value: Optional[int] = None,
394
+ nodata_in: int = -9999,
395
+ nodata_out: int = -9999,
396
+ out_dtype: AnalysisDataType = AnalysisDataType.int16,
397
+ inclusive: RangeBound = RangeBound.left,
398
+ user_id: Optional[int] = None) -> 'AsyncTask':
399
+ """
400
+ [async] Reclassify a raster using value mapping or class breaks.
401
+
402
+ This endpoint reclassifies raster values according to specified rules.
403
+ Only users with Publisher role or higher can perform this operation.
404
+
405
+ Args:
406
+ raster (Raster): Raster instance
407
+ output_raster_name (str): Name for the output reclassified raster dataset.
408
+ rules (str): JSON string containing reclassification rules.
409
+ For mode='exact', it should be a dict {old_value: new_value}.
410
+ For mode='range', it should be a list of (low, high, new_value).
411
+ Example for mode='exact': '{"1": 10, "2": 20, "3": 30}'.
412
+ Example for mode='range': '[[0, 10, 1], [10, 20, 2], [20, 30, 3]]'.
413
+ the method would detect the mode type based on the rules input.
414
+ default_value (str, optional): Value to assign when a pixel matches no rule.
415
+ nodata_in (int, optional): NoData of input. If None, tries to get from the input raster.
416
+ nodata_out (int, optional): NoData value to set on output band.
417
+ out_dtype (AnalysisDataType, optional): Output data type. default: AnalysisDataType.int16
418
+ inclusive (RangeBound, optional): Range bound semantics for mode='range': 'left', 'right', 'both', 'neither'. default: RangeBound.left
419
+ user_id (int, optional): specific user. priviledges required!
420
+
421
+ Returns:
422
+ AsyncTask: task instance of the process
423
+
424
+ Example:
425
+ >>> from geobox.aio import AsyncGeoboxClient
426
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
427
+ >>> async with AsyncGeoboxClient() as client:
428
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
429
+ >>> task = await client.raster_analysis.reclassify(raster=raster, output_raster_name='test', rules='{"1": 10, "2": 20, "3": 30}')
430
+ or
431
+ >>> raster_analysis = AsyncRasterAnalysis(client)
432
+ >>> task = raster_analysis.reclassify(raster=raster, output_raster_name='test', rules='{"1": 10, "2": 20, "3": 30}')
433
+ """
434
+ endpoint = f'{self.BASE_ENDPOINT}reclassify/'
435
+
436
+ data = clean_data({
437
+ 'raster_uuid': raster.uuid,
438
+ 'output_raster_name': output_raster_name,
439
+ 'rules': rules,
440
+ 'mode': 'exact' if isinstance(rules, dict) else 'range' if isinstance(rules, list) else None,
441
+ 'default_value': default_value,
442
+ 'nodata_in': nodata_in,
443
+ 'nodata_out': nodata_out,
444
+ 'out_dtype': out_dtype.value,
445
+ 'inclusive': inclusive.value,
446
+ 'user_id': user_id
447
+ })
448
+
449
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
450
+ return await self.api.get_task(response['task_id'])
451
+
452
+
453
+ async def resample(self,
454
+ raster: 'AsyncRaster',
455
+ output_raster_name: str,
456
+ out_res: Optional[str] = None,
457
+ scale_factor: Optional[str] = None,
458
+ match_raster_uuid: Optional[str] = None,
459
+ resample_method: AnalysisResampleMethod = AnalysisResampleMethod.near,
460
+ dst_nodata: int = -9999,
461
+ user_id: Optional[int] = None) -> 'AsyncTask':
462
+ """
463
+ [async] Resample a raster to a different resolution.
464
+
465
+ it resamples a raster using GDAL Warp.
466
+ Exactly one of out_res, scale_factor, or match_raster_uuid must be provided.
467
+ Only users with Publisher role or higher can perform this operation.
468
+
469
+ Args:
470
+ raster (Raster): Raster instance
471
+ output_raster_name (str): Name for the output reclassified raster dataset.
472
+ out_res (str, optional): Output resolution as 'x_res,y_res' (e.g., '10,10').
473
+ scale_factor (int, optional): Scale factor (e.g., 2.0 for 2x finer resolution).
474
+ match_raster_uuid (str, optional): UUID of reference raster to match resolution/extent.
475
+ resample_method (AnalysisResampleMethod, optional): Resampling method: 'near', 'bilinear', 'cubic', 'lanczos', etc.
476
+ dst_nodata (int, optional): Output NoData value.
477
+ user_id (int, optional): specific user. priviledges required!
478
+
479
+ Returns:
480
+ AsyncTask: task instance of the process
481
+
482
+ Example:
483
+ >>> from geobox.aio import AsyncGeoboxClient
484
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
485
+ >>> async with AsyncGeoboxClient() as client:
486
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
487
+ >>> task = await client.raster_analysis.resample(raster=raster, output_raster_name='test', out_res='10,10')
488
+ or
489
+ >>> raster_analysis = AsyncRasterAnalysis(client)
490
+ >>> task = await raster_analysis.resample(raster=raster, output_raster_name='test', out_res='10,10')
491
+ """
492
+ if sum(x is not None for x in [out_res, scale_factor, match_raster_uuid]) != 1:
493
+ raise ValueError('Exactly one of out_res, scale_factor, or match_raster_uuid must be provided!')
494
+
495
+ endpoint = f'{self.BASE_ENDPOINT}resample/'
496
+
497
+ data = clean_data({
498
+ 'raster_uuid': raster.uuid,
499
+ 'output_raster_name': output_raster_name,
500
+ 'out_res': out_res,
501
+ 'scale_factor': scale_factor,
502
+ 'match_raster_uuid': match_raster_uuid,
503
+ 'resample_method': resample_method.value,
504
+ 'dst_nodata': dst_nodata,
505
+ 'user_id': user_id
506
+ })
507
+
508
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
509
+ return await self.api.get_task(response['task_id'])
510
+
511
+
512
+ async def idw_interpolation(self,
513
+ layer: Union[AsyncVectorLayer, AsyncVectorLayerView],
514
+ output_raster_name: str,
515
+ z_field: Field,
516
+ match_raster_uuid: Optional[str] = None,
517
+ pixel_size: int = 10,
518
+ extent: Optional[str] = None,
519
+ power: float = 2.0,
520
+ smoothing: float = 0.0,
521
+ max_points: int = 16,
522
+ radius: int = 1000,
523
+ nodata: int = -9999,
524
+ out_dtype: AnalysisDataType = AnalysisDataType.float32,
525
+ user_id: Optional[int] = None) -> 'AsyncTask':
526
+ """
527
+ [async] Create an IDW (Inverse Distance Weighting) interpolation raster from point data.
528
+
529
+ it creates a raster using IDW interpolation from point data in a vector layer.
530
+ Only users with Publisher role or higher can perform this operation.
531
+
532
+ Args:
533
+ layer (AsyncVectorLayer | AsyncVectorLayerview): layer containing point data
534
+ output_raster_name (str): Name for the output IDW raster dataset.
535
+ z_field (Field): the field containing the values to interpolate.
536
+ match_raster_uuid (str, optional): UUID of reference raster to match resolution/extent.
537
+ pixel_size (int, optional): Pixel size for the output raster. default: 10
538
+ extent (str, optional): Extent as 'minX,minY,maxX,maxY'.
539
+ power (float, optional): Power parameter for IDW. default: 2.0
540
+ smoothing (float, optional): Smoothing parameter for IDW. default: 0.0
541
+ max_points (int, optional): Maximum number of neighbors to use. default: 16
542
+ radius (int, optional): Search radius in map units. default: 1000
543
+ nodata (int, optional): NoData value for the output raster. default: -9999
544
+ out_dtype (AnalysisDataType, optional): Output data type.
545
+ user_id (int, optional): specific user. priviledges required!
546
+
547
+ Returns:
548
+ AsyncTask: task instance of the process
549
+
550
+ Example:
551
+ >>> from geobox.aio import AsyncGeoboxClient
552
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
553
+ >>> async with AsyncGeoboxClient() as client:
554
+ >>> vector = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
555
+ >>> field = await vector.get_field_by_name('field_name')
556
+ >>> task = await client.raster_analysis.idw_interpolation(layer=vector, output_raster_name='test', z_field=field)
557
+ or
558
+ >>> raster_analysis = AsyncRasterAnalysis(client)
559
+ >>> task = await raster_analysis.idw_interpolation(layer=vector, output_raster_name='test', z_field=field)
560
+ """
561
+ endpoint = f'{self.BASE_ENDPOINT}idw/'
562
+
563
+ data = clean_data({
564
+ 'layer_uuid': layer.uuid,
565
+ 'output_raster_name': output_raster_name,
566
+ 'z_field': z_field.name,
567
+ 'is_view': False if isinstance(layer, AsyncVectorLayer) else True,
568
+ 'match_raster_uuid': match_raster_uuid,
569
+ 'pixel_size': pixel_size,
570
+ 'extent': extent,
571
+ 'power': power,
572
+ 'smoothing': smoothing,
573
+ 'max_points': max_points,
574
+ 'radius': radius,
575
+ 'nodata': nodata,
576
+ 'out_dtype': out_dtype.value,
577
+ 'user_id': user_id
578
+ })
579
+
580
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
581
+ return await self.api.get_task(response['task_id'])
582
+
583
+
584
+ async def constant(self,
585
+ output_raster_name: str,
586
+ extent: str,
587
+ value : int,
588
+ pixel_size: int = 10,
589
+ dtype: AnalysisDataType = AnalysisDataType.float32,
590
+ nodata: int = -9999,
591
+ align_to: Optional[str] = None,
592
+ user_id: Optional[int] = None) -> 'AsyncTask':
593
+ """
594
+ [async] Create a raster filled with a constant value.
595
+
596
+ This endpoint creates a north-up GeoTIFF filled with a constant value.
597
+ Only users with Publisher role or higher can perform this operation.
598
+
599
+ Args:
600
+ output_raster_name (str): Name for the output constant raster dataset.
601
+ extent (str): Extent as 'minX,minY,maxX,maxY' (e.g., '0,0,100,100').
602
+ value (int): Constant value to fill the raster with.
603
+ pixel_size (int, optional): Pixel size for the output raster (must be > 0). default: 10
604
+ dtype (AnalysisDataType, optoinal): Output data type. default: AnalysisDataType.float32
605
+ nodata (int, optional): NoData value for the raster. default: -9999
606
+ align_to (str, optional): Grid origin to snap to as 'x0,y0' (e.g., '0,0').
607
+ user_id (int, optional): specific user. priviledges required!
608
+
609
+ Returns:
610
+ AsyncTask: task instance of the process
611
+
612
+ Example:
613
+ >>> from geobox.aio import AsyncGeoboxClient
614
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
615
+ >>> async with AsyncGeoboxClient() as client:
616
+ >>> task = await client.raster_analysis.constant(output_raster_name='test', extent='0,0,100,100', value=10)
617
+ or
618
+ >>> raster_analysis = AsyncRasterAnalysis(client)
619
+ >>> task = await raster_analysis.constant(output_raster_name='test', extent='0,0,100,100', value=10)
620
+ """
621
+ endpoint = f'{self.BASE_ENDPOINT}constant/'
622
+
623
+ data = clean_data({
624
+ 'output_raster_name': output_raster_name,
625
+ 'extent': extent,
626
+ 'value': value,
627
+ 'pixel_size': pixel_size,
628
+ 'dtype': dtype.value,
629
+ 'nodata': nodata,
630
+ 'align_to': align_to,
631
+ 'user_id': user_id
632
+ })
633
+
634
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
635
+ return await self.api.get_task(response['task_id'])
636
+
637
+
638
+ async def fill_nodata(self,
639
+ raster: 'AsyncRaster',
640
+ output_raster_name: str,
641
+ band: Union[int, str] = 1,
642
+ nodata: Optional[int] = None,
643
+ max_search_dist: Optional[int] = None,
644
+ smoothing_iterations: Optional[int] = None,
645
+ mask_raster_uuid: Optional[str] = None,
646
+ user_id: Optional[int] = None) -> 'AsyncTask':
647
+ """
648
+ [async] Fill NoData regions in a raster using GDAL's FillNodata algorithm.
649
+
650
+ it fills gaps (NoData regions) in a raster by interpolating values from surrounding valid pixels.
651
+ This is commonly used for data cleaning and gap filling in remote sensing and elevation data.
652
+ Only users with Publisher role or higher can perform this operation.
653
+
654
+ Args:
655
+ raster (Raster): the input raster to fill NoData regions in
656
+ output_raster_name (str): Name for the output filled raster dataset.
657
+ band (int | str): 1-based band index to process or 'all' to process all bands. default: 1
658
+ nodata (int, optional): NoData value to use. If None, uses the band's existing NoData.
659
+ max_search_dist (int, optoinal): Maximum distance in pixels to search for valid data.
660
+ smoothing_iterations (int, optional): Number of smoothing iterations to apply.
661
+ mask_raster_uuid (str, optional): Optional UUID of a mask raster (0=masked, >0=valid).
662
+ user_id (int, optional): specific user. priviledges required!
663
+
664
+ Returns:
665
+ AsyncTask: task instance of the process
666
+
667
+ Example:
668
+ >>> from geobox.aio import AsyncGeoboxClient
669
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
670
+ >>> async with AsyncGeoboxClient() as client:
671
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
672
+ >>> task = await client.raster_analysis.fill_nodata(raster=raster, output_raster_name='test')
673
+ or
674
+ >>> raster_analysis = AsyncRasterAnalysis(client)
675
+ >>> task = await raster_analyis.fill_nodata(raster=raster, output_raster_name='test')
676
+ """
677
+ endpoint = f'{self.BASE_ENDPOINT}fill/'
678
+
679
+ data = clean_data({
680
+ 'raster_uuid': raster.uuid,
681
+ 'output_raster_name': output_raster_name,
682
+ 'band': band,
683
+ 'nodata': nodata,
684
+ 'max_search_dist': max_search_dist,
685
+ 'smoothing_iterations': smoothing_iterations,
686
+ 'mask_raster_uuid': mask_raster_uuid,
687
+ 'user_id': user_id
688
+ })
689
+
690
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
691
+ return await self.api.get_task(response['task_id'])
692
+
693
+
694
+ async def proximity(self,
695
+ raster: 'AsyncRaster',
696
+ output_raster_name: str,
697
+ dist_units: DistanceUnit = DistanceUnit.GEO,
698
+ burn_value: int = 1,
699
+ nodata: int = -9999,
700
+ user_id: Optional[int] = None) -> 'AsyncTask':
701
+ """
702
+ [async] Create a proximity (distance) raster from a raster layer.
703
+
704
+ it creates a raster showing the distance from each pixel to the nearest pixel in the input raster layer.
705
+ Only users with Publisher role or higher can perform this operation.
706
+
707
+ Args:
708
+ raster (Raster): the raster layer to create proximity raster from.
709
+ output_raster_name (str): Name for the output proximity raster dataset.
710
+ dist_units (DistanceUnit, optional): Distance units: 'GEO' for georeferenced units, 'PIXEL' for pixels. default: DistanceUnit.GEO
711
+ burn_value (int, optional): Value treated as targets (distance 0). default: 1
712
+ nodata (int, optional): NoData value to use in the output raster. default: -9999
713
+ user_id (int, optional): specific user. priviledges required!
714
+
715
+ Returns:
716
+ AsyncTask: task instance of the process
717
+
718
+ Example:
719
+ >>> from geobox.aio import AsyncGeoboxClient
720
+ >>> from geobox.aio.raster_analysis import AsyncRasterAnalysis
721
+ >>> async with AsyncGeoboxClient() as client:
722
+ >>> raster = await client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
723
+ >>> task = await client.raster_analysis.proximity(raster=raster, output_raster_name='test')
724
+ or
725
+ >>> raster_analysis = AsyncRasterAnalysis(client)
726
+ >>> task = await raster_analysis.proximity(raster=raster, output_raster_name='test')
727
+ """
728
+ endpoint = f'{self.BASE_ENDPOINT}proximity/'
729
+
730
+ data = clean_data({
731
+ 'raster_uuid': raster.uuid,
732
+ 'output_raster_name': output_raster_name,
733
+ 'dist_units': dist_units.value,
734
+ 'burn_value': burn_value,
735
+ 'nodata': nodata,
736
+ 'user_id': user_id
737
+ })
738
+
739
+ response = await self.api.post(endpoint=endpoint, payload=data, is_json=False)
740
+ return await self.api.get_task(response['task_id'])