CS-SI / eodag

Earth Observation Data Access Gateway
https://eodag.readthedocs.io
Apache License 2.0
324 stars 44 forks source link

Geometry ParseError in search function #845

Closed PMacAddress closed 1 year ago

PMacAddress commented 1 year ago

Describe the bug Parse error of WKT geometry in EODataAccessGateway.search function

Code To Reproduce I have configure 'cop_dataspace' credential, but if I use a geom in search criteria i have a ParseException:

from eodag import EODataAccessGateway
dag= EODataAccessGateway()
dag.set_preferred_provider('cop_dataspace')
search_criteria = {"productType": "S1_SAR_GRD", "start": "2021-03-01 00:00:00", "end": "2021-10-31 00:00:00", "geom": "POLYGON((33.5166 44.6198,33.5166 44.5906,33.5464 44.5906,33.5464 44.6198,33.5166 44.6198))"}
all_products = dag.search(**search_criteria)

Output

Error while searching on provider cop_dataspace (ignored):
Traceback (most recent call last):
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/api/core.py", line 1395, in _do_search
    res, nb_res = search_plugin.query(count=count, **kwargs)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/plugins/search/qssearch.py", line 456, in query
    eo_products = self.normalize_results(provider_results, **kwargs)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/plugins/search/qssearch.py", line 1084, in normalize_results
    products = super(ODataV4Search, self).normalize_results(results, **kwargs)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/plugins/search/qssearch.py", line 809, in normalize_results
    QueryStringSearch.extract_properties[self.config.result_type](
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/api/product/metadata_mapping.py", line 566, in properties_from_json
    properties[metadata] = format_metadata(
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/api/product/metadata_mapping.py", line 503, in format_metadata
    return MetadataFormatter().vformat(search_param, args, kwargs)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/string.py", line 165, in vformat
    result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/string.py", line 209, in _vformat
    obj = self.convert_field(obj, conversion)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/api/product/metadata_mapping.py", line 196, in convert_field
    converted = self.custom_converter(value)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/eodag/api/product/metadata_mapping.py", line 323, in convert_from_ewkt
    input_geom = wkt.loads(g["wkt"])
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/shapely/wkt.py", line 22, in loads
    return shapely.from_wkt(data)
  File "/opt/conda/envs/arcos_openeo_api/lib/python3.9/site-packages/shapely/io.py", line 286, in from_wkt
    return lib.from_wkt(geometry, invalid_handler, **kwargs)
shapely.errors.GEOSException: ParseException: Unexpected text after end of geometry

Environment:

Additional context Printing g["wkt"] in convert_from_ewkt function of EODAG I obtain this output with : MULTIPOLYGON (((34.054619 43.25264, 34.45853 44.752571, 31.247597 45.14983, 30.92403 43.650314, 34.054619 43.25264)))' I think that bug is in convert_from_ewkt function regex:

ewkt_regex = re.compile(r"^(?P<proj>[A-Za-z]+=[0-9]+);(?P<wkt>.*)$")
ewkt_match = ewkt_regex.match(ewkt_string)

because there in an apostrophe at the end.

sbrunato commented 1 year ago

Hello @PMacAddress , and thanks for submitting this issue.

gasparakos commented 1 year ago

I think the problem is here: https://github.com/CS-SI/eodag/blob/094cdb97592302305b00be370b6db88b3c9d9e5e/eodag/resources/providers.yml#L3457

One working rewrite:

- '{$.Footprint.`sub(/.*(SRID=[0-9]+;[A-Z0-9\(,.\) ]*).*/, \\1)`#from_ewkt}'