Skip to content

Commit 3f8eefe

Browse files
committed
Co-authored-by: Nik weinni2000@gmail.com
1 parent 4cf1990 commit 3f8eefe

14 files changed

+43
-26
lines changed

base_geoengine/README.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ The module also requires two additional python libs:
7676
- `geojson <http://pypi.python.org/pypi/geojson>`__
7777

7878
When you will install the module this two additional libs will be
79-
installed.
80-
81-
For a complete documentation please refer to the `public
79+
installed. For a complete documentation please refer to the `public
8280
documenation <http://oca.github.io/geospatial/index.html>`__
8381

8482
Usage
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.
244 Bytes
Binary file not shown.

base_geoengine/fields.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import string
1414
from operator import attrgetter
1515

16-
from odoo import fields
16+
from odoo import _, fields
1717
from odoo.fields import Domain
1818
from odoo.models import BaseModel
1919
from odoo.orm.fields import Field
@@ -281,7 +281,7 @@ def entry_to_shape(self, value, same_type=False):
281281
shape = convert.value_to_shape(value)
282282
if same_type and not shape.is_empty:
283283
if shape.geom_type.lower() != self.geo_type.lower():
284-
msg = self.env._(
284+
msg = _(
285285
"Geo Value %(geom_type)s must be of the same type %(geo_type)s \
286286
as fields",
287287
geom_type=shape.geom_type.lower(),
@@ -301,14 +301,14 @@ def update_geo_db_column(self, model):
301301
check_data = cr.fetchone()
302302
if not check_data:
303303
raise TypeError(
304-
self.env._(
304+
_(
305305
"geometry_columns table seems to be corrupted."
306306
" SRID check is not possible"
307307
)
308308
)
309309
if check_data[0] != self.srid:
310310
raise TypeError(
311-
self.env._(
311+
_(
312312
"Reprojection of column is not implemented."
313313
" We can not change srid %(srid)s to %(data)s",
314314
srid=self.srid,
@@ -317,7 +317,7 @@ def update_geo_db_column(self, model):
317317
)
318318
elif check_data[1] != self.geo_type.upper():
319319
raise TypeError(
320-
self.env._(
320+
_(
321321
"Geo type modification is not implemented."
322322
" We can not change type %(data)s to %(geo_type)s",
323323
data=check_data[1],
@@ -326,7 +326,7 @@ def update_geo_db_column(self, model):
326326
)
327327
elif check_data[2] != self.dim:
328328
raise TypeError(
329-
self.env._(
329+
_(
330330
"Geo dimention modification is not implemented."
331331
" We can not change dimention %(data)s to %(dim)s",
332332
data=check_data[2],

base_geoengine/geo_convertion_helper.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
import logging
44

5+
from shapely.errors import GEOSException
6+
57
from odoo import _
68

7-
logger = logging.getLogger(__name__)
9+
_logger = logging.getLogger(__name__)
810

911
try:
1012
import geojson
1113
from shapely import wkb, wkt
1214
from shapely.geometry import shape
1315
from shapely.geometry.base import BaseGeometry
1416
except ImportError:
15-
logger = logging.getLogger(__name__)
16-
logger.warning(_("Shapely or geojson are not available in the sys path")) # pylint: disable=prefer-env-translation
17+
_logger.warning(_("Shapely or geojson are not available in the sys path")) # pylint: disable=prefer-env-translation
1718

1819

1920
def value_to_shape(value, use_wkb=False):
2021
"""Transforms input into a Shapely object"""
22+
23+
# always use_wkb for now
24+
use_wkb = True
25+
2126
if not value:
2227
return wkt.loads("GEOMETRYCOLLECTION EMPTY")
2328
if isinstance(value, str):
@@ -26,19 +31,35 @@ def value_to_shape(value, use_wkb=False):
2631
if "{" in value:
2732
geo_dict = geojson.loads(value)
2833
return shape(geo_dict)
29-
elif use_wkb:
30-
return wkb.loads(value, hex=True)
31-
else:
32-
# <NIKMOD>
33-
# 'POINT(0.0 0.0)'
34-
34+
if use_wkb:
3535
try:
36-
return wkt.loads(value)
36+
res = wkb.loads(value, hex=True)
37+
return res
38+
except GEOSException as e:
39+
_logger.warning("GEOSException:")
40+
_logger.warning(e)
3741
except Exception as e:
38-
logger.warning(_("Failed to parse WKT: %s", e)) # pylint: disable=prefer-env-translation
39-
empty = "POINT(0.0 0.0)"
40-
return wkt.loads(empty)
41-
# </NIKMOD>
42+
_logger.warning("WKB conversion failed:")
43+
_logger.warning(e)
44+
# elif len(value) == 42 and "POINT" not in value and "(" not in value:
45+
# not clear why use_wkb is not set correctly anymore.
46+
# if a record is stored it's instantly
47+
# executed again with the hash value
48+
# The hash value eg "0101000000A4703D0AD7232C400AD7A3703D0A4840"
49+
# is also possible, but we do not handle it now.
50+
# value = wkb.loads(value, hex=True)
51+
# return value
52+
# <NIKMOD>
53+
# 'POINT(0.0 0.0)'
54+
try:
55+
return wkt.loads(value)
56+
except Exception as e:
57+
# error = _("Failed to parse WKT: %(e)s") % {"e":e}
58+
error = f"Failed to parse WKT: {e}"
59+
_logger.warning(error) # pylint: disable=prefer-env-translation
60+
empty = "POINT(0 0)"
61+
return wkt.loads(empty)
62+
# </NIKMOD>
4263
elif hasattr(value, "wkt"):
4364
return value if isinstance(value, BaseGeometry) else wkt.loads(value.wkt)
4465
else:
-13 Bytes
Binary file not shown.
65 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)