|
6 | 6 | import datetime
|
7 | 7 | import logging
|
8 | 8 | import math
|
| 9 | +import re |
9 | 10 | import tempfile
|
10 | 11 | import time
|
11 | 12 | import warnings
|
12 | 13 | from pathlib import Path
|
13 |
| -from typing import Dict, Callable, List, Union, Tuple, Any, Iterable |
| 14 | +from typing import Any, Callable, Dict, Iterable, List, Tuple, Union |
14 | 15 |
|
15 |
| -import pandas as pd |
16 | 16 | import geopandas as gpd
|
17 | 17 | import numpy as np
|
| 18 | +import openeo.udf |
18 | 19 | import openeo_processes
|
| 20 | +import pandas as pd |
19 | 21 | import pyproj
|
20 | 22 | import requests
|
21 |
| -from dateutil.relativedelta import relativedelta |
22 |
| -from requests.structures import CaseInsensitiveDict |
23 | 23 | import shapely.geometry
|
24 |
| -from shapely.geometry import shape, GeometryCollection, shape, mapping, MultiPolygon |
25 | 24 | import shapely.ops
|
26 |
| - |
27 |
| -import openeo.udf |
| 25 | +from dateutil.relativedelta import relativedelta |
28 | 26 | from openeo.capabilities import ComparableVersion
|
29 |
| -from openeo.internal.process_graph_visitor import ProcessGraphVisitor, ProcessGraphVisitException |
| 27 | +from openeo.internal.process_graph_visitor import ProcessGraphVisitException, ProcessGraphVisitor |
30 | 28 | from openeo.metadata import CollectionMetadata, MetadataException
|
31 |
| -from openeo.util import load_json, rfc3339, deep_get, str_truncate |
| 29 | +from openeo.util import deep_get, load_json, rfc3339, str_truncate |
| 30 | +from shapely.geometry import GeometryCollection, MultiPolygon, mapping, shape |
| 31 | + |
32 | 32 | from openeo_driver import dry_run
|
33 | 33 | from openeo_driver.backend import (
|
34 | 34 | UserDefinedProcessMetadata,
|
|
53 | 53 | to_save_result, AggregatePolygonSpatialResult, MlModelResult
|
54 | 54 | from openeo_driver.specs import SPECS_ROOT, read_spec
|
55 | 55 | from openeo_driver.util.date_math import month_shift
|
56 |
| -from openeo_driver.util.geometry import ( |
57 |
| - geojson_to_geometry, |
58 |
| - geojson_to_multipolygon, |
59 |
| - spatial_extent_union, |
60 |
| -) |
| 56 | +from openeo_driver.util.geometry import geojson_to_geometry, geojson_to_multipolygon, spatial_extent_union |
61 | 57 | from openeo_driver.util.utm import auto_utm_epsg_for_geometry
|
62 |
| -from openeo_driver.utils import smart_bool, EvalEnv |
| 58 | +from openeo_driver.utils import EvalEnv, smart_bool |
63 | 59 |
|
64 | 60 | _log = logging.getLogger(__name__)
|
65 | 61 |
|
@@ -1540,26 +1536,24 @@ def read_vector(args: Dict, env: EvalEnv) -> DelayedVector:
|
1540 | 1536 |
|
1541 | 1537 |
|
1542 | 1538 | @process_registry_100.add_function(spec=read_spec("openeo-processes/1.x/proposals/load_uploaded_files.json"))
|
1543 |
| -def load_uploaded_files(args: dict, env: EvalEnv) -> Union[DriverVectorCube,DriverDataCube]: |
| 1539 | +def load_uploaded_files(args: ProcessArgs, env: EvalEnv) -> Union[DriverVectorCube, DriverDataCube]: |
1544 | 1540 | # TODO #114 EP-3981 process name is still under discussion https://github.com/Open-EO/openeo-processes/issues/322
|
1545 |
| - paths = extract_arg(args, 'paths', process_id="load_uploaded_files") |
1546 |
| - format = extract_arg(args, 'format', process_id="load_uploaded_files") |
1547 |
| - options = args.get("options", {}) |
1548 |
| - |
1549 |
| - input_formats = CaseInsensitiveDict(env.backend_implementation.file_formats()["input"]) |
1550 |
| - if format not in input_formats: |
1551 |
| - raise FileTypeInvalidException(type=format, types=", ".join(input_formats.keys())) |
| 1541 | + paths = args.get_required("paths", expected_type=list) |
| 1542 | + format = args.get_required( |
| 1543 | + "format", |
| 1544 | + expected_type=str, |
| 1545 | + validator=ProcessArgs.validator_file_format(formats=env.backend_implementation.file_formats()["input"]), |
| 1546 | + ) |
| 1547 | + options = args.get_optional("options", default={}) |
1552 | 1548 |
|
1553 |
| - if format.lower() in {"geojson", "esri shapefile", "gpkg", "parquet"}: |
| 1549 | + if DriverVectorCube.from_fiona_supports(format): |
1554 | 1550 | return DriverVectorCube.from_fiona(paths, driver=format, options=options)
|
1555 | 1551 | elif format.lower() in {"GTiff"}:
|
1556 |
| - if(len(paths)!=1): |
1557 |
| - raise FeatureUnsupportedException(f"load_uploaded_files only supports a single raster of format {format!r}, you provided {paths}") |
1558 |
| - kwargs = dict( |
1559 |
| - glob_pattern=paths[0], |
1560 |
| - format=format, |
1561 |
| - options=options |
1562 |
| - ) |
| 1552 | + if len(paths) != 1: |
| 1553 | + raise FeatureUnsupportedException( |
| 1554 | + f"load_uploaded_files only supports a single raster of format {format!r}, you provided {paths}" |
| 1555 | + ) |
| 1556 | + kwargs = dict(glob_pattern=paths[0], format=format, options=options) |
1563 | 1557 | dry_run_tracer: DryRunDataTracer = env.get(ENV_DRY_RUN_TRACER)
|
1564 | 1558 | if dry_run_tracer:
|
1565 | 1559 | return dry_run_tracer.load_disk_data(**kwargs)
|
@@ -1604,6 +1598,24 @@ def load_geojson(args: ProcessArgs, env: EvalEnv) -> DriverVectorCube:
|
1604 | 1598 | return vector_cube
|
1605 | 1599 |
|
1606 | 1600 |
|
| 1601 | +@process_registry_100.add_function(spec=read_spec("openeo-processes/2.x/proposals/load_url.json")) |
| 1602 | +def load_url(args: ProcessArgs, env: EvalEnv) -> DriverVectorCube: |
| 1603 | + # TODO: Follow up possible `load_url` changes https://github.com/Open-EO/openeo-processes/issues/450 ? |
| 1604 | + url = args.get_required("url", expected_type=str, validator=re.compile("^https?://").match) |
| 1605 | + format = args.get_required( |
| 1606 | + "format", |
| 1607 | + expected_type=str, |
| 1608 | + validator=ProcessArgs.validator_file_format(formats=env.backend_implementation.file_formats()["input"]), |
| 1609 | + ) |
| 1610 | + options = args.get_optional("options", default={}) |
| 1611 | + |
| 1612 | + if DriverVectorCube.from_fiona_supports(format): |
| 1613 | + # TODO: for GeoJSON (and related) support `properties` option like load_geojson? https://github.com/Open-EO/openeo-processes/issues/450 |
| 1614 | + return DriverVectorCube.from_fiona(paths=[url], driver=format, options=options) |
| 1615 | + else: |
| 1616 | + raise FeatureUnsupportedException(f"Loading format {format!r} is not supported") |
| 1617 | + |
| 1618 | + |
1607 | 1619 | @non_standard_process(
|
1608 | 1620 | ProcessSpec("get_geometries", description="Reads vector data from a file or a URL or get geometries from a FeatureCollection")
|
1609 | 1621 | .param('filename', description="filename or http url of a vector file", schema={"type": "string"}, required=False)
|
|
0 commit comments