Registration - deal with self-intersecting polygons
Here is a sample self-intersecting polygon, which it would be great if we had a way to deal with (as it appears often in vhr15 products registrations):
POLYGON ((-2.065070885 55.8494485915), (-1.71213786646 55.6631185244), (-1.71213786646 55.8494485915), (-2.065070885 55.6631185244), (-2.065070885 55.8494485915))
During registration in EOxServer yield a following error:
django.contrib.gis.geos.error.GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSUnion_r".
raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
File "/usr/local/lib/python3.8/dist-packages/django/contrib/gis/geos/prototypes/errcheck.py", line 32, in check_geom
return self.cfunc(self.thread_context.handle.ptr, *args)
File "/usr/local/lib/python3.8/dist-packages/django/contrib/gis/geos/prototypes/threadsafe.py", line 47, in __call__
return self.func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/contrib/gis/geos/libgeos.py", line 155, in __call__
return self._topology(capi.geos_union(self.ptr, other.ptr))
File "/usr/local/lib/python3.8/dist-packages/django/contrib/gis/geos/geometry.py", line 593, in union
collection.footprint = collection.footprint.union(footprint)
File "/usr/local/lib/python3.8/dist-packages/eoxserver/resources/coverages/models.py", line 781, in collection_insert_eo_object
models.collection_insert_eo_object(collection, product)
File "/usr/local/lib/python3.8/dist-packages/registrar-2.0.0a2-py3.8.egg/registrar/backend/eoxserver.py", line 310, in register
return func(*args, **kwds)
File "/usr/lib/python3.8/contextlib.py", line 75, in inner
backend.register(source, item, replace=False)
File "/usr/local/lib/python3.8/dist-packages/registrar-2.0.0a2-py3.8.egg/registrar/registrar.py", line 56, in register_file
register_file(config, value, replace)
File "/usr/local/lib/python3.8/dist-packages/registrar-2.0.0a2-py3.8.egg/registrar/daemon.py", line 56, in run_daemon
Traceback (most recent call last):
ERROR registrar.daemon: Error encountered checking Geometry returned from GEOS C function "GEOSUnion_r".
ERROR django.contrib.gis: GEOS_ERROR: TopologyException: Input geom 1 is invalid: Self-intersection at or near point -1.88860437573 55.756283557949999 at -1.88860437573 55.756283557949999
Could we please try to extend the registration with STAC https://github.com/EOxServer/eoxserver/blob/beca61dc18ac63f0ca7c0fe10fb83781d2952d40/eoxserver/resources/coverages/registration/stac.py#L120 to check the footprint via geos.geometry.valid and try to fix the geometry if possible (removing the self-intersection caused by wrong point order in the source data)?
https://docs.djangoproject.com/en/3.2/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry.valid https://docs.djangoproject.com/en/3.2/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry.buffer https://github.com/strezen/cartopy/commit/ff8f919b6047a23a2fdad772bf6613bd71801156