Download SoilGrids raster layers via WCS.
You can provide either a boundary polygon or an explicit bounding box. Bounding boxes are expected in
(west, south, east, north) order.
| Parameters: |
-
path
(str | Path)
–
Directory where downloaded GeoTIFF files are written.
-
maps
(list[str], default:
ALL_MAPS
)
–
Map identifiers in property@layer format.
-
boundary
(Polygon | None, default:
None
)
–
Optional polygon used to derive a buffered bounding box.
-
bbox
(tuple[float, float, float, float] | None, default:
None
)
–
Optional explicit bounding box as (west, south, east, north).
-
crs
(str, default:
'epsg:4326'
)
–
CRS of the provided bbox coordinates.
|
| Raises: |
-
ValueError
–
If neither boundary nor bbox is provided.
|
Source code in cycles/soilgrids/soilgrids.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253 | def download_soilgrids_data(path: str | Path, *,
maps: list[str]=ALL_MAPS, boundary: Polygon | None=None, bbox: tuple[float, float, float, float] | None=None, crs: str='epsg:4326') -> None:
"""Download SoilGrids raster layers via WCS.
You can provide either a boundary polygon or an explicit bounding box. Bounding boxes are expected in
``(west, south, east, north)`` order.
Args:
path: Directory where downloaded GeoTIFF files are written.
maps: Map identifiers in ``property@layer`` format.
boundary: Optional polygon used to derive a buffered bounding box.
bbox: Optional explicit bounding box as ``(west, south, east, north)``.
crs: CRS of the provided ``bbox`` coordinates.
Returns:
None.
Raises:
ValueError: If neither ``boundary`` nor ``bbox`` is provided.
"""
if boundary is not None and bbox is None:
bbox = _bbox_from_boundary(boundary)
if bbox is None:
raise ValueError("Either boundary or bbox must be provided.")
bbox = _get_bounding_box(bbox, crs)
for m in maps:
parameter, layer = m.split('@')
v = SOILGRIDS_PROPERTIES[parameter].soilgrids_name
wcs = WebCoverageService(f'http://maps.isric.org/mapserv?map=/map/{v}.map', version='1.0.0')
while True:
try:
response = wcs.getCoverage( # type: ignore
identifier=f'{v}_{layer}_mean',
crs='urn:ogc:def:crs:EPSG::152160',
bbox=bbox,
resx=250,
resy=250,
format='GEOTIFF_INT16',
)
(Path(path) / f'{v}_{layer}.tif').write_bytes(response.read())
break
except Exception:
continue
|