diff --git a/base_geoengine/README.rst b/base_geoengine/README.rst index 518ab5557..427507628 100644 --- a/base_geoengine/README.rst +++ b/base_geoengine/README.rst @@ -76,9 +76,7 @@ The module also requires two additional python libs: - `geojson `__ When you will install the module this two additional libs will be -installed. - -For a complete documentation please refer to the `public +installed. For a complete documentation please refer to the `public documenation `__ Usage diff --git a/base_geoengine/__pycache__/__init__.cpython-310.pyc b/base_geoengine/__pycache__/__init__.cpython-310.pyc index 01bdbbd49..908aff07a 100644 Binary files a/base_geoengine/__pycache__/__init__.cpython-310.pyc and b/base_geoengine/__pycache__/__init__.cpython-310.pyc differ diff --git a/base_geoengine/__pycache__/domains.cpython-310.pyc b/base_geoengine/__pycache__/domains.cpython-310.pyc index cbb0ee9c1..90d90aaa7 100644 Binary files a/base_geoengine/__pycache__/domains.cpython-310.pyc and b/base_geoengine/__pycache__/domains.cpython-310.pyc differ diff --git a/base_geoengine/__pycache__/fields.cpython-310.pyc b/base_geoengine/__pycache__/fields.cpython-310.pyc index 40fa1ceaf..22d8241b3 100644 Binary files a/base_geoengine/__pycache__/fields.cpython-310.pyc and b/base_geoengine/__pycache__/fields.cpython-310.pyc differ diff --git a/base_geoengine/__pycache__/geo_convertion_helper.cpython-310.pyc b/base_geoengine/__pycache__/geo_convertion_helper.cpython-310.pyc index bfd7f84c2..4a739723c 100644 Binary files a/base_geoengine/__pycache__/geo_convertion_helper.cpython-310.pyc and b/base_geoengine/__pycache__/geo_convertion_helper.cpython-310.pyc differ diff --git a/base_geoengine/__pycache__/geo_db.cpython-310.pyc b/base_geoengine/__pycache__/geo_db.cpython-310.pyc index c41349b26..232db0bb5 100644 Binary files a/base_geoengine/__pycache__/geo_db.cpython-310.pyc and b/base_geoengine/__pycache__/geo_db.cpython-310.pyc differ diff --git a/base_geoengine/fields.py b/base_geoengine/fields.py index c922bb088..4b2236a5f 100644 --- a/base_geoengine/fields.py +++ b/base_geoengine/fields.py @@ -13,7 +13,7 @@ import string from operator import attrgetter -from odoo import fields +from odoo import _, fields from odoo.fields import Domain from odoo.models import BaseModel from odoo.orm.fields import Field @@ -281,7 +281,7 @@ def entry_to_shape(self, value, same_type=False): shape = convert.value_to_shape(value) if same_type and not shape.is_empty: if shape.geom_type.lower() != self.geo_type.lower(): - msg = self.env._( + msg = _( "Geo Value %(geom_type)s must be of the same type %(geo_type)s \ as fields", geom_type=shape.geom_type.lower(), @@ -301,14 +301,14 @@ def update_geo_db_column(self, model): check_data = cr.fetchone() if not check_data: raise TypeError( - self.env._( + _( "geometry_columns table seems to be corrupted." " SRID check is not possible" ) ) if check_data[0] != self.srid: raise TypeError( - self.env._( + _( "Reprojection of column is not implemented." " We can not change srid %(srid)s to %(data)s", srid=self.srid, @@ -317,7 +317,7 @@ def update_geo_db_column(self, model): ) elif check_data[1] != self.geo_type.upper(): raise TypeError( - self.env._( + _( "Geo type modification is not implemented." " We can not change type %(data)s to %(geo_type)s", data=check_data[1], @@ -326,7 +326,7 @@ def update_geo_db_column(self, model): ) elif check_data[2] != self.dim: raise TypeError( - self.env._( + _( "Geo dimention modification is not implemented." " We can not change dimention %(data)s to %(dim)s", data=check_data[2], diff --git a/base_geoengine/geo_convertion_helper.py b/base_geoengine/geo_convertion_helper.py index f325d1252..9ad590aa1 100644 --- a/base_geoengine/geo_convertion_helper.py +++ b/base_geoengine/geo_convertion_helper.py @@ -2,9 +2,11 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging +from shapely.errors import GEOSException + from odoo import _ -logger = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) try: import geojson @@ -12,12 +14,15 @@ from shapely.geometry import shape from shapely.geometry.base import BaseGeometry except ImportError: - logger = logging.getLogger(__name__) - logger.warning(_("Shapely or geojson are not available in the sys path")) # pylint: disable=prefer-env-translation + _logger.warning(_("Shapely or geojson are not available in the sys path")) # pylint: disable=prefer-env-translation def value_to_shape(value, use_wkb=False): """Transforms input into a Shapely object""" + + # always use_wkb for now + use_wkb = True + if not value: return wkt.loads("GEOMETRYCOLLECTION EMPTY") if isinstance(value, str): @@ -26,19 +31,35 @@ def value_to_shape(value, use_wkb=False): if "{" in value: geo_dict = geojson.loads(value) return shape(geo_dict) - elif use_wkb: - return wkb.loads(value, hex=True) - else: - # - # 'POINT(0.0 0.0)' - + if use_wkb: try: - return wkt.loads(value) + res = wkb.loads(value, hex=True) + return res + except GEOSException as e: + _logger.warning("GEOSException:") + _logger.warning(e) except Exception as e: - logger.warning(_("Failed to parse WKT: %s", e)) # pylint: disable=prefer-env-translation - empty = "POINT(0.0 0.0)" - return wkt.loads(empty) - # + _logger.warning("WKB conversion failed:") + _logger.warning(e) + # elif len(value) == 42 and "POINT" not in value and "(" not in value: + # not clear why use_wkb is not set correctly anymore. + # if a record is stored it's instantly + # executed again with the hash value + # The hash value eg "0101000000A4703D0AD7232C400AD7A3703D0A4840" + # is also possible, but we do not handle it now. + # value = wkb.loads(value, hex=True) + # return value + # + # 'POINT(0.0 0.0)' + try: + return wkt.loads(value) + except Exception as e: + # error = _("Failed to parse WKT: %(e)s") % {"e":e} + error = f"Failed to parse WKT: {e}" + _logger.warning(error) # pylint: disable=prefer-env-translation + empty = "POINT(0 0)" + return wkt.loads(empty) + # elif hasattr(value, "wkt"): return value if isinstance(value, BaseGeometry) else wkt.loads(value.wkt) else: diff --git a/base_geoengine/models/__pycache__/__init__.cpython-310.pyc b/base_geoengine/models/__pycache__/__init__.cpython-310.pyc index 2d60ff9b6..7c6a7bd16 100644 Binary files a/base_geoengine/models/__pycache__/__init__.cpython-310.pyc and b/base_geoengine/models/__pycache__/__init__.cpython-310.pyc differ diff --git a/base_geoengine/models/__pycache__/base.cpython-310.pyc b/base_geoengine/models/__pycache__/base.cpython-310.pyc index 3e868cb1b..445d3f41a 100644 Binary files a/base_geoengine/models/__pycache__/base.cpython-310.pyc and b/base_geoengine/models/__pycache__/base.cpython-310.pyc differ diff --git a/base_geoengine/models/__pycache__/geo_raster_layer.cpython-310.pyc b/base_geoengine/models/__pycache__/geo_raster_layer.cpython-310.pyc index f20c30208..9cab27b14 100644 Binary files a/base_geoengine/models/__pycache__/geo_raster_layer.cpython-310.pyc and b/base_geoengine/models/__pycache__/geo_raster_layer.cpython-310.pyc differ diff --git a/base_geoengine/models/__pycache__/geo_vector_layer.cpython-310.pyc b/base_geoengine/models/__pycache__/geo_vector_layer.cpython-310.pyc index 34c4e9995..3fb9fbe75 100644 Binary files a/base_geoengine/models/__pycache__/geo_vector_layer.cpython-310.pyc and b/base_geoengine/models/__pycache__/geo_vector_layer.cpython-310.pyc differ diff --git a/base_geoengine/models/__pycache__/ir_model.cpython-310.pyc b/base_geoengine/models/__pycache__/ir_model.cpython-310.pyc index 4638a3b5a..57b23218b 100644 Binary files a/base_geoengine/models/__pycache__/ir_model.cpython-310.pyc and b/base_geoengine/models/__pycache__/ir_model.cpython-310.pyc differ diff --git a/base_geoengine/models/__pycache__/ir_view.cpython-310.pyc b/base_geoengine/models/__pycache__/ir_view.cpython-310.pyc index e171d60bd..aa0de17e9 100644 Binary files a/base_geoengine/models/__pycache__/ir_view.cpython-310.pyc and b/base_geoengine/models/__pycache__/ir_view.cpython-310.pyc differ diff --git a/base_geoengine/readme/INSTALL.md b/base_geoengine/readme/INSTALL.md index c72a805b7..feb12f188 100644 --- a/base_geoengine/readme/INSTALL.md +++ b/base_geoengine/readme/INSTALL.md @@ -14,6 +14,5 @@ The module also requires two additional python libs: When you will install the module this two additional libs will be installed. - For a complete documentation please refer to the [public documenation](http://oca.github.io/geospatial/index.html) diff --git a/base_geoengine/static/description/index.html b/base_geoengine/static/description/index.html index 03fc525c3..15d930bb6 100644 --- a/base_geoengine/static/description/index.html +++ b/base_geoengine/static/description/index.html @@ -430,8 +430,7 @@

Installation

  • geojson
  • When you will install the module this two additional libs will be -installed.

    -

    For a complete documentation please refer to the public +installed. For a complete documentation please refer to the public documenation

    diff --git a/base_geoengine/tests/__pycache__/__init__.cpython-310.pyc b/base_geoengine/tests/__pycache__/__init__.cpython-310.pyc index 0fd13ba2c..1988a4b61 100644 Binary files a/base_geoengine/tests/__pycache__/__init__.cpython-310.pyc and b/base_geoengine/tests/__pycache__/__init__.cpython-310.pyc differ diff --git a/base_geoengine/tests/__pycache__/models.cpython-310.pyc b/base_geoengine/tests/__pycache__/models.cpython-310.pyc deleted file mode 100644 index dc8ae2f0e..000000000 Binary files a/base_geoengine/tests/__pycache__/models.cpython-310.pyc and /dev/null differ diff --git a/base_geoengine/tests/__pycache__/test_model.cpython-310.pyc b/base_geoengine/tests/__pycache__/test_model.cpython-310.pyc deleted file mode 100644 index 7beb7262d..000000000 Binary files a/base_geoengine/tests/__pycache__/test_model.cpython-310.pyc and /dev/null differ diff --git a/base_geoengine/tests/__pycache__/test_nikstests.cpython-310.pyc b/base_geoengine/tests/__pycache__/test_nikstests.cpython-310.pyc deleted file mode 100644 index cc036f360..000000000 Binary files a/base_geoengine/tests/__pycache__/test_nikstests.cpython-310.pyc and /dev/null differ diff --git a/base_geoengine/tests/test_model.py b/base_geoengine/tests/test_model.py index d379966dc..aca47c162 100644 --- a/base_geoengine/tests/test_model.py +++ b/base_geoengine/tests/test_model.py @@ -1,10 +1,12 @@ # Copyright 2023 ACSONE SA/NV import geojson -from odoo_test_helper import FakeModelLoader + +# from odoo_test_helper import FakeModelLoader from shapely import wkt from shapely.geometry import shape +from odoo.orm.model_classes import add_to_registry from odoo.tests.common import TransactionCase from ..fields import GeoPoint @@ -14,12 +16,25 @@ class TestModel(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.loader = FakeModelLoader(cls.env, cls.__module__) - cls.loader.backup_registry() from .models import DummyZip, GeoModelTest, RetailMachine - cls.loader.update_registry((GeoModelTest, DummyZip, RetailMachine)) + add_to_registry(cls.registry, GeoModelTest) + cls.registry._setup_models__(cls.env.cr, ["geo.model.test"]) + cls.registry.init_models( + cls.env.cr, ["geo.model.test"], {"models_to_check": True} + ) + + add_to_registry(cls.registry, DummyZip) + cls.registry._setup_models__(cls.env.cr, ["dummy.zip"]) + cls.registry.init_models(cls.env.cr, ["dummy.zip"], {"models_to_check": True}) + + add_to_registry(cls.registry, RetailMachine) + cls.registry._setup_models__(cls.env.cr, ["retail.machine"]) + cls.registry.init_models( + cls.env.cr, ["retail.machine"], {"models_to_check": True} + ) + cls.geo_model = cls.env["geo.model.test"].create({}) cls.env["dummy.zip"].create( { @@ -145,7 +160,10 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - cls.loader.restore_registry() + cls.addClassCleanup(cls.registry.__delitem__, "geo.model.test") + cls.addClassCleanup(cls.registry.__delitem__, "retail.machine") + cls.addClassCleanup(cls.registry.__delitem__, "dummy.zip") + super().tearDownClass() def test_create_multipolygon_wkt_format(self): @@ -481,7 +499,7 @@ def test_search_contains_for_retails_21(self): def test_search_within_for_retails_34(self): retails = self.env["retail.machine"] - zip_item = self.env["dummy.zip"].search([("city", "ilike", "Yens")]) + zip_item = self.env["dummy.zip"].search([("city", "=", "Yens")], limit=1) result = retails.search( [("name", "ilike", "34"), ("the_point", "geo_within", zip_item.the_geom)] )