diff --git a/gag_app/classes.py b/gag_app/classes.py index 08dee63..3591c97 100644 --- a/gag_app/classes.py +++ b/gag_app/classes.py @@ -8,10 +8,9 @@ from warnings import warn from django.apps import apps from django.contrib.contenttypes.models import ContentType -from django.contrib.gis.geos import GEOSGeometry, WKBWriter from gag_app.env import model_to_import, source_cat_to_gag_cat, core_topology, common, list_label_field from gag_app.config.config import AUTHENT_STRUCTURE, AUTH_USER, GAG_BASE_LANGUAGE, PORTALS -from gag_app.utils import get_api_field, deserialize_translated_fields +from gag_app.utils import geom_to_wkt, get_api_field, deserialize_translated_fields class ParserAPIv2ImportContentTypeModel(): @@ -183,11 +182,7 @@ def one_to_one_fields_build_dict(self): print(self.model_to_import_name, ': topology exists') fk_to_insert['kind'] = self.model_to_import_name.upper() - geom = GEOSGeometry(str(self.api_data[self.index]['geometry'])) # default SRID of GEOSGeometry is 4326 - geom.transform(settings.SRID) - geom = WKBWriter().write(geom) # drop Z dimension - geom = GEOSGeometry(geom) - fk_to_insert['geom'] = geom + fk_to_insert['geom'] = geom_to_wkt(self.api_data[self.index]) for ctf in self.coretopology_fields: ctf_name = ctf.name diff --git a/gag_app/utils.py b/gag_app/utils.py index d06fd77..6930266 100644 --- a/gag_app/utils.py +++ b/gag_app/utils.py @@ -1,11 +1,13 @@ -def geom4326_to_wkt(data): - from gag_app.config.config import SRID - from django.contrib.gis.geos import GEOSGeometry +def geom_to_wkt(data): + from django.conf import settings + from django.contrib.gis.geos import GEOSGeometry, WKBWriter - geom = GEOSGeometry(str(data)) # default SRID of GEOSGeometry is 4326 - geom.transform(SRID) + geom = GEOSGeometry(str(data['geometry'])) # default SRID of GEOSGeometry is 4326 + geom.transform(settings.SRID) + geom = WKBWriter().write(geom) # drop Z dimension + geom = GEOSGeometry(geom) - return geom.wkt + return geom def get_api_field(r, index, f_name, value, dict_to_insert):