Skip to content

Commit

Permalink
Merge pull request #25 from openig/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
IdrissaD authored Apr 27, 2022
2 parents ce28e7a + 7146861 commit 05450be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 2 additions & 7 deletions gag_app/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions gag_app/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 05450be

Please sign in to comment.