From 34c48ee9b6f3893f1f9584cb0f58a19114bd6fb1 Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Wed, 15 Jul 2020 14:34:08 +0200 Subject: [PATCH 1/7] test redirect layer source --- crdppf/models/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crdppf/models/models.py b/crdppf/models/models.py index 36d7012..39e7a13 100644 --- a/crdppf/models/models.py +++ b/crdppf/models/models.py @@ -363,8 +363,8 @@ class CHPollutedSitesPublicTransportsPDF(): if 'road_noise' in db_config['restrictions']: class RoadNoise(GeoInterface, Base): - __tablename__ = 'r145_sens_bruit' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = 'v_r145_sens_bruit' + __table_args__ = {'schema': 'noise_sensitivity_levels', 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: From 7c89313e24751ce9f1dbc24c548895a941ff632f Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Thu, 16 Jul 2020 16:44:31 +0200 Subject: [PATCH 2/7] added a spinner while UI is loading --- crdppf/static/js/Crdppf/main.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crdppf/static/js/Crdppf/main.js b/crdppf/static/js/Crdppf/main.js index 6ba0211..52e0f45 100644 --- a/crdppf/static/js/Crdppf/main.js +++ b/crdppf/static/js/Crdppf/main.js @@ -49,9 +49,16 @@ Ext.onReady(function() { }; Crdppf.triggerFunction = function(counter) { + + var loadMask = new Ext.LoadMask(Ext.getBody(), {msg: 'Chargement en cours... Merci de patienter.'}); + if (counter == 3) { + loadMask.hide(); synchronize(sync); } + else { + loadMask.show(); + } }; var redirectAfterDisclaimer = function(userChoice){ From d1433c50018d170df80c28dbc3b62e7df5d036bf Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Fri, 25 Sep 2020 08:48:02 +0200 Subject: [PATCH 3/7] removed getting app_config from database --- crdppf/__init__.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/crdppf/__init__.py b/crdppf/__init__.py index 19eae35..0713ebc 100644 --- a/crdppf/__init__.py +++ b/crdppf/__init__.py @@ -14,21 +14,6 @@ db_config = 'to_overwrite' -# GET THE INITIAL CONFIGURATION FROM THE DB -def read_app_config(settings): - """ - Read the initial app config - """ - from crdppf.models import DBSession, Base - from crdppf.models.models import AppConfig - results = {} - results = DBSession.query(AppConfig).all() - - for result in results : - settings['app_config'].update({str(result.parameter):str(result.paramvalue)}) - - return True - # INCLUDE THE CORE CONFIGURATION AND CREATE THE APPLICATION def includeme(config): """ This function returns a Pyramid WSGI application. @@ -55,9 +40,6 @@ def includeme(config): engine = engine_from_config(settings, 'sqlalchemy.') init_model(engine) - # add app configuration from db - read_app_config(settings) - config.include(papyrus.includeme) config.include('pyramid_mako') # bind the mako renderer to other file extensions From 17449df1a344ef80b556c98ea1c665a2e29d22be Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Fri, 25 Sep 2020 08:50:07 +0200 Subject: [PATCH 4/7] adapted paths to new app configuration --- crdppf/lib/cached_content.py | 21 +++++++++++++-------- crdppf/lib/content.py | 9 ++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crdppf/lib/cached_content.py b/crdppf/lib/cached_content.py index d9d7b10..04000cd 100644 --- a/crdppf/lib/cached_content.py +++ b/crdppf/lib/cached_content.py @@ -1,5 +1,5 @@ # -*- coding: UTF-8 -*- - +from pyramid.exceptions import ConfigurationError from dogpile.cache.region import make_region cache_region = make_region() @@ -7,7 +7,7 @@ from crdppf.models import DBSession -from crdppf.models.models import AppConfig, Translations, Glossar +from crdppf.models.models import Translations, Glossar from crdppf.models.models import Informations, ExclusionsResponsabilite import logging @@ -20,26 +20,31 @@ def get_cached_content(request): d = {} - canton_logo = DBSession.query(AppConfig).filter_by(parameter='cantonlogopath').first() - ch_logo = DBSession.query(AppConfig).filter_by(parameter='CHlogopath').first() - crdppf_logo = DBSession.query(AppConfig).filter_by(parameter='crdppflogopath').first() + if request.registry.settings['pdf_config']: + settings = request.registry.settings['pdf_config'] + else: + raise ConfigurationError('Missing mandatory configuration settings for the application to work.') + + canton_logo = settings['cantonlogo']['path'] + ch_logo = settings['CHlogopath'] + crdppf_logo = settings['crdppflogopath'] d['canton_logo'] = '/'.join([ request.registry.settings['localhost_url'], 'proj/images', - canton_logo.paramvalue + canton_logo ]) d['ch_logo'] = '/'.join([ request.registry.settings['localhost_url'], 'proj/images', - ch_logo.paramvalue + ch_logo ]) d['crdppf_logo'] = '/'.join([ request.registry.settings['localhost_url'], 'proj/images', - crdppf_logo.paramvalue + crdppf_logo ]) return d diff --git a/crdppf/lib/content.py b/crdppf/lib/content.py index d2c2d56..f147f03 100644 --- a/crdppf/lib/content.py +++ b/crdppf/lib/content.py @@ -10,7 +10,7 @@ from crdppf.util.pdf_functions import get_feature_info, get_translations from crdppf.models import DBSession -from crdppf.models.models import Topics, AppConfig +from crdppf.models.models import Topics from geoalchemy2.shape import to_shape, WKTElement import logging @@ -162,7 +162,7 @@ def get_content(id, request): """ # Start a session session = request.session - configs = DBSession.query(AppConfig).all() + configs = request.registry.settings['app_config'] # initalize extract object extract = Extract(request) @@ -171,9 +171,8 @@ def get_content(id, request): if type == 'file': type = 'reduced' directprint = True - for config in configs: - if config.parameter not in ['crdppflogopath', 'cantonlogopath']: - extract.baseconfig[config.parameter] = config.paramvalue + for config in configs.keys(): + extract.baseconfig[config] = configs[config] extract.srid = db_config['srid'] extract.topiclegenddir = request.static_url('crdppfportal:static/public/legend/') From 04a997908b765f4f80b9c19356e15b7cf3723751 Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Fri, 25 Sep 2020 08:51:06 +0200 Subject: [PATCH 5/7] Cleanup and adaptions to point on pyramid_oereb data --- crdppf/models/models.py | 64 ++++------------------------ crdppf/util/get_feature_functions.py | 2 + 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/crdppf/models/models.py b/crdppf/models/models.py index 72e84aa..df53efb 100644 --- a/crdppf/models/models.py +++ b/crdppf/models/models.py @@ -17,12 +17,6 @@ from crdppf.models import Base -# Models for the configuration of the application -class AppConfig(Base): - __tablename__ = 'appconfig' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - - # START models used for static extraction and general models class Topics(Base): __tablename__ = 'topics' @@ -255,40 +249,22 @@ class CHAirportSecurityZones(GeoInterface, Base): __table_args__ = {'schema': db_config['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) - - class CHAirportSecurityZonesPDF(GeoInterface, Base): - __tablename__ = 'r108_bazl_sicherheitszonenplan_pdf' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bazl.sicherheitszonenplan.oereb else: class CHAirportSecurityZones(): pass - class CHAirportSecurityZonesPDF(): - pass if 'airport_project_zones' in db_config['restrictions']: class CHAirportProjectZones(GeoInterface, Base): __tablename__ = 'r103_bazl_projektierungszonen_flughafenanlagen' __table_args__ = {'schema': db_config['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) - - class CHAirportProjectZonesPDF(GeoInterface, Base): - __tablename__ = 'r103_bazl_projektierungszonen_flughafenanlagen_pdf' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bazl.projektierungszonen-flughafenanlagen.oereb - else: class CHAirportProjectZones(): pass - class CHAirportProjectZonesPDF(): - pass if 'airport_construction_limits' in db_config['restrictions']: class CHAirportConstructionLimits(GeoInterface, Base): @@ -296,21 +272,12 @@ class CHAirportConstructionLimits(GeoInterface, Base): __table_args__ = {'schema': db_config['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) - - class CHAirportConstructionLimitsPDF(GeoInterface, Base): - __tablename__ = 'r104_bazl_baulinien_flughafenanlagen_pdf' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bazl.projektierungszonen-flughafenanlagen.oereb else: class CHAirportConstructionLimits(): pass - class CHAirportConstructionLimitsPDF(): - pass - # models for theme: register of polluted sites class PollutedSites(GeoInterface, Base): @@ -319,36 +286,30 @@ class PollutedSites(GeoInterface, Base): idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) -if 'military_polluted_sites' in db_config['restrictions']: +if 'contaminated_military_sites' in db_config['restrictions']: + table_def_ = db_config['tables']['contaminated_military_sites'] + class ContaminatedMilitarySites(GeoInterface, Base): - __tablename__ = 'r117_vbs_belastete_standorte_militaer' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(String, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: class ContaminatedMilitarySites(): pass + if 'airport_polluted_sites' in db_config['restrictions']: class CHPollutedSitesCivilAirports(GeoInterface, Base): __tablename__ = 'r118_bazl_belastete_standorte_zivilflugplaetze' __table_args__ = {'schema': db_config['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) - - class CHPollutedSitesCivilAirportsPDF(GeoInterface, Base): - __tablename__ = 'r118_bazl_belastete_standorte_zivilflugplaetze_pdf' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) - else: class CHPollutedSitesCivilAirports(): pass - class CHPollutedSitesCivilAirportsPDF(): - pass if 'transportation_polluted_sites' in db_config['restrictions']: class CHPollutedSitesPublicTransports(GeoInterface, Base): @@ -356,20 +317,11 @@ class CHPollutedSitesPublicTransports(GeoInterface, Base): __table_args__ = {'schema': db_config['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) - - class CHPollutedSitesPublicTransportsPDF(GeoInterface, Base): - __tablename__ = 'r119_bav_belastete_standorte_oev_pdf' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) - - # ch.bav.kataster-belasteter-standorte-oev.oereb + # ch.bav.kataster-belasteter-standorte-oev.oereb else: class CHPollutedSitesPublicTransports(): pass - class CHPollutedSitesPublicTransportsPDF(): - pass # models for the topic noise if 'road_noise' in db_config['restrictions']: diff --git a/crdppf/util/get_feature_functions.py b/crdppf/util/get_feature_functions.py index 8da61cf..92673fb 100644 --- a/crdppf/util/get_feature_functions.py +++ b/crdppf/util/get_feature_functions.py @@ -67,5 +67,7 @@ def get_features_function(parcelGeom, params): jsonFeature['properties']['intersectionMeasure'] = intersectionMeasureTxt jsonFeature['properties']['geomType'] = 'point' featureList.append(jsonFeature) + else: + return('Error on geometry type:' + geometryType) return featureList From 5b0dc1ac043b5179b646c8268c1f8795aa27bec6 Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Fri, 25 Sep 2020 14:35:18 +0200 Subject: [PATCH 6/7] cleanup of unused models and xml import --- crdppf/util/pdf_functions.py | 249 ----------------------------------- 1 file changed, 249 deletions(-) diff --git a/crdppf/util/pdf_functions.py b/crdppf/util/pdf_functions.py index d317880..b023076 100644 --- a/crdppf/util/pdf_functions.py +++ b/crdppf/util/pdf_functions.py @@ -17,8 +17,6 @@ from crdppf.models import DBSession from crdppf.models.models import Translations, PaperFormats from crdppf.models.models import Town, Property, LocalName -from crdppf.models.models import CHAirportSecurityZonesPDF, CHAirportProjectZonesPDF -from crdppf.models.models import CHPollutedSitesCivilAirportsPDF, CHPollutedSitesPublicTransportsPDF def geom_from_coordinates(coords): @@ -51,253 +49,6 @@ def get_translations(lang): return locals -def get_XML(geometry, srid, topicid, extracttime, lang, translations): - """Gets the XML extract of the federal data feature service for a given topic - and validates it against the schema. - """ - # baseurl of the server of the swiss confederation - server = 'https://api3.geo.admin.ch' - # rest service call - url = '/rest/services/api/MapServer/identify' - # layers = 'all:ch.bazl.sicherheitszonenplan.oereb' - # bbox = 'mapExtent=671164.31244,253770,690364.31244,259530' - # geometry of the feature to call the feature server for - feature = geometry - # geomtype = 'geometryType=esriGeometryEnvelope' - # wktfeature = DBSession.scalar(geometry.ST_AsText()) - bbox = get_bbox_from_geometry(DBSession.scalar(functions.ST_AsText(geometry.ST_Envelope()))) - # geometrytype used for feature service call - geomtype = 'esriGeometryPolygon' - # geomtype = 'esriGeometryEnvelope' - BBOX - # geomtype = 'esriGeometryPoint' - Point - # Size and resolution of the returned image - mapparams = '1920,576,96' - # geometry tolerance for intersection - tolerance = 5 - # data format - format = 'interlis' - xml_layers = { - 'R103': 'ch.bazl.projektierungszonen-flughafenanlagen.oereb', - 'R108': 'ch.bazl.sicherheitszonenplan.oereb', - 'R118': 'ch.bazl.kataster-belasteter-standorte-zivilflugplaetze.oereb', - 'R119': 'ch.bav.kataster-belasteter-standorte-oev.oereb' - } - - geomGeoJSON = loads(DBSession.scalar(geometry.ST_AsGeoJSON())) - coords = geomGeoJSON['coordinates'] - - if geomGeoJSON['type'] == 'MultiPolygon': - coords = coords[0] - - # Stupid ESRI stuff: double quotes are needed to call the feature service, thus we have to hardcode "rings" - esrifeature = '{"rings":' + str(coords) + '}' - - # Composing the feature service request - fsurl = server+url - - params = { - 'geometry': esrifeature, - 'geometryType': geomtype, - 'layers': 'all:'+xml_layers[topicid], - 'mapExtent': str(bbox.values()).strip('[]'), - 'imageDisplay': mapparams, - 'tolerance': str(tolerance), - 'geometryFormat': format, - 'lang': lang - } - params = urllib.urlencode(params) - - # Call the feature service URL wich sends back an XML Interlis 2.3 file in the OEREB Transfer structure - h = httplib2.Http() - (resp_headers, content) = h.request(fsurl, method="POST", body=params) - - # trim all whitespace and newlines - content_lines = content.splitlines() - count = 0 - for line in content_lines: - content_lines[count] = line.strip() - count += 1 - content = ''.join(content_lines) - - # validate XML - # xmldoc = parseString(content).firstChild - xmldoc = parseString(content).getElementsByTagName("TRANSFER")[0] - # extract the datasection from the response - datasection = xmldoc.getElementsByTagName("DATASECTION")[0] - # extract the complete tranfert structure - transferstructure = xmldoc.getElementsByTagName("OeREBKRM09trsfr.Transferstruktur") - - if len(transferstructure[0].childNodes) > 0: - - # Get the competent authority for the legal provisions - vsauthority = { - 'shortname': xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Amt")[0].getAttributeNode("TID").value, - 'namede': xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Amt")[0].getElementsByTagName("Text")[0].firstChild.data, - 'namefr': xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Amt")[0].getElementsByTagName("Text")[1].firstChild.data, - 'namefr': xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Amt")[0].getElementsByTagName("Text")[2].firstChild.data, - 'url': xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Amt")[0].getElementsByTagName("AmtImWeb")[0].firstChild.data - } - vslegalprovisions = xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Dokument") - # Get the WMS and it's legend - xtfwms = { - 'wmsurl': xmldoc.getElementsByTagName( - "OeREBKRM09trsfr.Transferstruktur.DarstellungsDienst")[0].getElementsByTagName("VerweisWMS")[0].firstChild.data, - 'wmslegend': xmldoc.getElementsByTagName( - "OeREBKRM09trsfr.Transferstruktur.DarstellungsDienst")[0].getElementsByTagName("LegendeImWeb")[0].firstChild.data - } - # GET restrictions - xtfrestrictions = xmldoc.getElementsByTagName("OeREBKRM09trsfr.Transferstruktur.Eigentumsbeschraenkung") - if xtfrestrictions: - restrictions = [] - restriction = {} - for xtfrestriction in xtfrestrictions: - restriction = { - 'restrictionid': xtfrestriction.getAttributeNode("TID").value, - 'teneurde': xtfrestriction.getElementsByTagName("Aussage")[0].getElementsByTagName("Text")[0].firstChild.data, - 'teneurfr': xtfrestriction.getElementsByTagName("Aussage")[0].getElementsByTagName("Text")[1].firstChild.data, - 'teneurit': xtfrestriction.getElementsByTagName("Aussage")[0].getElementsByTagName("Text")[2].firstChild.data, - 'topic': xtfrestriction.getElementsByTagName("Thema")[0].firstChild.data, - 'legalstate': xtfrestriction.getElementsByTagName("Rechtsstatus")[0].firstChild.data, - 'publishedsince': xtfrestriction.getElementsByTagName("publiziertAb")[0].firstChild.data, - 'url': xtfrestriction.getElementsByTagName("DarstellungsDienst")[0].getAttributeNode("REF").value, - 'authority': xtfrestriction.getElementsByTagName("ZustaendigeStelle")[0].getAttributeNode("REF").value - } - restrictions.append(restriction) - - xtfvslinkprovisions = xmldoc.getElementsByTagName("OeREBKRM09trsfr.Transferstruktur.HinweisVorschrift") - vslinkprovisions = [] - for vslinkprovision in xtfvslinkprovisions: - vslinkprovisions.append({ - 'origin': vslinkprovision.getElementsByTagName("Eigentumsbeschraenkung")[0].getAttributeNode("REF").value, - 'link': vslinkprovision.getElementsByTagName("Vorschrift")[0].getAttributeNode("REF").value - }) - - xtfvslinkreferences = xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.HinweisWeitereDokumente") - vslinkreferences = [] - for vslinkreference in xtfvslinkreferences: - vslinkreferences.append({ - 'origin': vslinkreference.getElementsByTagName("Ursprung")[0].getAttributeNode("REF").value, - 'link': vslinkreference.getElementsByTagName("Hinweis")[0].getAttributeNode("REF").value - }) - - xtfvslegalprovisions = xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Rechtsvorschrift") - vslegalprovisions = [] - for vslegalprovision in xtfvslegalprovisions: - vslegalprovisions.append({ - 'provisionid': vslegalprovision.getAttributeNode("TID").value, - 'titel': vslegalprovision.getElementsByTagName("Text")[0].firstChild.data, - 'legalstate': vslegalprovision.getElementsByTagName("Rechtsstatus")[0].firstChild.data, - 'publishedsince': vslegalprovision.getElementsByTagName("publiziertAb")[0].firstChild.data, - 'authority': vslegalprovision.getElementsByTagName("ZustaendigeStelle")[0].getAttributeNode("REF").value, - 'url': vslegalprovision.getElementsByTagName("TextImWeb")[0].firstChild.data - }) - - xtfvsdocuments = xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.Dokument") - vsdocuments = [] - for vsdocument in xtfvsdocuments: - vsdocuments.append({ - 'provisionid': vsdocument.getAttributeNode("TID").value, - 'titel': vsdocument.getElementsByTagName("Text")[0].firstChild.data, - 'legalstate': vsdocument.getElementsByTagName("Rechtsstatus")[0].firstChild.data, - 'publishedsince': vsdocument.getElementsByTagName("publiziertAb")[0].firstChild.data, - 'authority': vsdocument.getElementsByTagName("ZustaendigeStelle")[0].getAttributeNode("REF").value, - 'url': vsdocument.getElementsByTagName("TextImWeb")[0].firstChild.data - }) - - xtflegalprovisions = xmldoc.getElementsByTagName("OeREBKRM09trsfr.Transferstruktur.HinweisVorschrift") - feature = [] - for xtflegalprovision in xtflegalprovisions: - feature.append({ - 'restrictionid': xtflegalprovision.getElementsByTagName("Eigentumsbeschraenkung")[0].getAttributeNode("REF").value, - 'provision': xtflegalprovision.getElementsByTagName("Vorschrift")[0].getAttributeNode("REF").value - }) - - xtfreferences = xmldoc.getElementsByTagName("OeREBKRM09vs.Vorschriften.HinweisWeitereDokumente") - - xtfgeoms = xmldoc.getElementsByTagName("OeREBKRM09trsfr.Transferstruktur.Geometrie") - geometries = [] - for xtfgeom in xtfgeoms: - if xtfgeom.getElementsByTagName("Flaeche"): - if xtfgeom.getElementsByTagName("SURFACE"): - surfaces = xtfgeom.getElementsByTagName("SURFACE") - if xtfgeom.getElementsByTagName("BOUNDARY"): - boundaries = xtfgeom.getElementsByTagName("BOUNDARY") - if xtfgeom.getElementsByTagName("POLYLINE"): - polylines = xtfgeom.getElementsByTagName("POLYLINE") - multipolygon = [] - for polyline in polylines: - coordlist = [] - for coords in polyline.childNodes: - coordlist.append(( - float(coords.getElementsByTagName("C1")[0].firstChild.data), - float(coords.getElementsByTagName("C2")[0].firstChild.data) - )) - # del coordlist[-1] - polygon = splPolygon(coordlist) - if len(polylines) > 1: - multipolygon.append(polygon) - geom = splMultiPolygon(multipolygon) - else: - geom = polygon - elif xtfgeom.getElementsByTagName("Punkt") and not xtfgeom.getElementsByTagName("Flaeche"): - point = xtfgeom.getElementsByTagName("Punkt")[0] - coordlist = [] - for coords in point.childNodes: - coordlist.append(( - float(coords.getElementsByTagName("C1")[0].firstChild.data), - float(coords.getElementsByTagName("C2")[0].firstChild.data) - )) - geom = splPoint(coordlist) - else: - geom = None - - geometries.append({ - 'tid': xtfgeom.getAttributeNode("TID").value, - 'restrictionid': xtfgeom.getElementsByTagName("Eigentumsbeschraenkung")[0].getAttributeNode("REF").value, - 'competentAuthority': xtfgeom.getElementsByTagName("ZustaendigeStelle")[0].getAttributeNode("REF").value, - 'legalstate': xtfgeom.getElementsByTagName("Rechtsstatus")[0].firstChild.data, - 'publishedsince': xtfgeom.getElementsByTagName("publiziertAb")[0].firstChild.data, - # 'metadata': xtfgeom.getElementsByTagName("MetadatenGeobasisdaten")[0].firstChild.data, - 'geom': geom.wkt - }) - - for geometry in geometries: - if topicid in [u'R103', '103']: - xml_model = CHAirportProjectZonesPDF() - xml_model.theme = translations['CHAirportProjectZonesThemeLabel'] # u'Zones réservées des installations aéroportuaires' - xml_model.teneur = translations['CHAirportProjectZonesContentLabel'] # u'Limitation de la hauteur des bâtiments et autres obstacles' - elif topicid in [u'R108', '108']: - xml_model = CHAirportSecurityZonesPDF() - xml_model.theme = translations['CHAirportSecurityZonesThemeLabel'] # u'Plan de la zone de sécurité des aéroports' - xml_model.teneur = translations['CHAirportSecurityZonesContentLabel'] # u'Limitation de la hauteur des bâtiments et autres obstacles' - elif topicid in [u'R118', '118']: - xml_model = CHPollutedSitesCivilAirportsPDF() - xml_model.theme = translations['CHPollutedSitesCivilAirportsThemeLabel'] # u'Cadastre des sites pollués - domaine des transports publics' - xml_model.teneur = translations['CHPollutedSitesCivilAirportsContentLabel'] # u'Sites pollués' - elif topicid in [u'R119', '119']: - xml_model = CHPollutedSitesPublicTransportsPDF() - xml_model.theme = translations['CHPollutedSitesPublicTransportsThemeLabel'] # u'Cadastre des sites pollués - domaine des transports publics' - xml_model.teneur = translations['CHPollutedSitesPublicTransportsContentLabel'] # u'Sites pollués' - - xml_model.codegenre = None - if geometry['legalstate'] == u'inKraft': - xml_model.statutjuridique = translations['legalstateLabelvalid'] # u'En vigueur' - else: - xml_model.statutjuridique = translations['legalstateLabelmodification'] # u'En cours d\'approbation' - if geometry['publishedsince']: - xml_model.datepublication = geometry['publishedsince'] - else: - xml_model.datepublication = None - # It is very important to set the SRID if it's not the default EPSG:4326 !! - xml_model.idobj = str(extracttime)+'_'+str(geometry['restrictionid']) - xml_model.geom = WKTElement(geometry['geom'], srid) - DBSession.add(xml_model) - - DBSession.flush() - - return - - def get_feature_info(id, srid, translations): """The function gets the geometry of a parcel by it's ID and does an overlay with other administrative layers to get the basic parcelInfo and attribute From 5e3cdc2106a43aa7c1213d8cc000ee92ff627786 Mon Sep 17 00:00:00 2001 From: Francois Voisard Date: Fri, 16 Oct 2020 11:35:20 +0200 Subject: [PATCH 7/7] refactored models definition --- crdppf/models/models.py | 220 +++++++++++++++++++++++++--------------- 1 file changed, 140 insertions(+), 80 deletions(-) diff --git a/crdppf/models/models.py b/crdppf/models/models.py index df53efb..b2f1273 100644 --- a/crdppf/models/models.py +++ b/crdppf/models/models.py @@ -47,7 +47,6 @@ class OriginReference(Base): __table_args__ = {'schema': db_config['schema'], 'autoload': True} docid = Column(String, ForeignKey('crdppf.documents.docid')) - class LegalDocuments(Base): __tablename__ = 'documents' __table_args__ = {'schema': db_config['schema'], 'autoload': True} @@ -164,56 +163,86 @@ class LocalName(): # START models used for GetFeature queries # models for theme: allocation plan -class PrimaryLandUseZones(GeoInterface, Base): - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - __tablename__ = 'r73_affectations_primaires' - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) +if 'land_use_plans_primary_use' in db_config['restrictions']: + table_def_ = db_config['tables']['land_use_plans_primary_use'] -class SecondaryLandUseZones(GeoInterface, Base): - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - __tablename__ = 'r73_zones_superposees' - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) + class PrimaryLandUseZones(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) +else: + class PrimaryLandUseZones(): + pass +if 'land_use_plans_overlay_zones' in db_config['restrictions']: + table_def_ = db_config['tables']['land_use_plans_overlay_zones'] -class ComplementaryLandUsePerimeters(GeoInterface, Base): - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - __tablename__ = 'r73_perimetres_superposes' - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) + class SecondaryLandUseZones(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) +else: + class SecondaryLandUseZones(): + pass +if 'land_use_plans_overlay_perimeters' in db_config['restrictions']: + table_def_ = db_config['tables']['land_use_plans_overlay_perimeters'] -class LandUseLinearConstraints(GeoInterface, Base): - __tablename__ = 'r73_contenus_lineaires' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("MULTILINE", srid=srid_)) + class ComplementaryLandUsePerimeters(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) +else: + class ComplementaryLandUsePerimeters(): + pass +if 'land_use_plans_linear_constraints' in db_config['restrictions']: + table_def_ = db_config['tables']['land_use_plans_linear_constraints'] -class LandUsePointConstraints(GeoInterface, Base): - __tablename__ = 'r73_contenus_ponctuels' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("POINT", srid=srid_)) + class LandUseLinearConstraints(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("MULTILINE", srid=srid_)) +else: + class LandUseLinearConstraints(): + pass + +if 'land_use_plans_point_constraints' in db_config['restrictions']: + table_def_ = db_config['tables']['land_use_plans_point_constraints'] + + class LandUsePointConstraints(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("POINT", srid=srid_)) +else: + class LandUsePointConstraints(): + pass # models for the topic national roads +if 'motorways_project_planing_zones' in db_config['restrictions']: + table_def_ = db_config['tables']['motorways_project_planing_zones'] -if 'highways_project_zones' in db_config['restrictions']: class CHHighwaysProjectZones(GeoInterface, Base): - __tablename__ = 'r87_astra_projektierungszonen_nationalstrassen' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: class CHHighwaysProjectZones(): pass -if 'highways_construction_limits' in db_config['restrictions']: +if 'motorways_building_lines' in db_config['restrictions']: + table_def_ = db_config['tables']['motorways_building_lines'] + class CHHighwaysConstructionLimits(GeoInterface, Base): - __tablename__ = 'r88_astra_baulinien_nationalstrassen' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: @@ -221,21 +250,24 @@ class CHHighwaysConstructionLimits(): pass # models for the national railways +if 'railways_project_planning_zones' in db_config['restrictions']: + table_def_ = db_config['tables']['railways_project_planning_zones'] -if 'railways_project_zones' in db_config['restrictions']: class CHRailwaysProjectZones(GeoInterface, Base): - __tablename__ = 'r96_bav_projektierungszonen_eisenbahnanlagen' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: class CHRailwaysProjectZones(): pass -if 'railways_construction_limits' in db_config['restrictions']: +if 'railways_building_lines' in db_config['restrictions']: + table_def_ = db_config['tables']['railways_building_lines'] + class CHRailwaysConstructionLimits(GeoInterface, Base): - __tablename__ = 'r97_bav_baulinien_eisenbahnanlagen' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: @@ -243,10 +275,12 @@ class CHRailwaysConstructionLimits(): pass # models for airports -if 'airport_security_zones' in db_config['restrictions']: +if 'airports_security_zone_plans' in db_config['restrictions']: + table_def_ = db_config['tables']['airports_security_zone_plans'] + class CHAirportSecurityZones(GeoInterface, Base): - __tablename__ = 'r108_bazl_sicherheitszonenplan' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bazl.sicherheitszonenplan.oereb @@ -254,37 +288,46 @@ class CHAirportSecurityZones(GeoInterface, Base): class CHAirportSecurityZones(): pass +if 'airports_project_planning_zones' in db_config['restrictions']: + table_def_ = db_config['tables']['airports_project_planning_zones'] -if 'airport_project_zones' in db_config['restrictions']: class CHAirportProjectZones(GeoInterface, Base): - __tablename__ = 'r103_bazl_projektierungszonen_flughafenanlagen' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bazl.projektierungszonen-flughafenanlagen.oereb else: class CHAirportProjectZones(): pass -if 'airport_construction_limits' in db_config['restrictions']: +if 'airports_building_lines' in db_config['restrictions']: + table_def_ = db_config['tables']['airports_building_lines'] + class CHAirportConstructionLimits(GeoInterface, Base): - __tablename__ = 'r104_bazl_baulinien_flughafenanlagen' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bazl.projektierungszonen-flughafenanlagen.oereb - else: class CHAirportConstructionLimits(): pass # models for theme: register of polluted sites -class PollutedSites(GeoInterface, Base): - __tablename__ = 'r116_sites_pollues' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(Integer, primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) +if 'contaminated_sites' in db_config['restrictions']: + table_def_ = db_config['tables']['contaminated_sites'] + + class PollutedSites(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(Integer, primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) +else: + class PollutedSites(): + pass if 'contaminated_military_sites' in db_config['restrictions']: table_def_ = db_config['tables']['contaminated_military_sites'] @@ -294,16 +337,17 @@ class ContaminatedMilitarySites(GeoInterface, Base): __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(String, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) - else: class ContaminatedMilitarySites(): pass -if 'airport_polluted_sites' in db_config['restrictions']: +if 'contaminated_civil_aviation_sites' in db_config['restrictions']: + table_def_ = db_config['tables']['contaminated_civil_aviation_sites'] + class CHPollutedSitesCivilAirports(GeoInterface, Base): - __tablename__ = 'r118_bazl_belastete_standorte_zivilflugplaetze' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: @@ -311,10 +355,12 @@ class CHPollutedSitesCivilAirports(): pass -if 'transportation_polluted_sites' in db_config['restrictions']: +if 'contaminated_public_transport_sites' in db_config['restrictions']: + table_def_ = db_config['tables']['contaminated_public_transport_sites'] + class CHPollutedSitesPublicTransports(GeoInterface, Base): - __tablename__ = 'r119_bav_belastete_standorte_oev' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) # ch.bav.kataster-belasteter-standorte-oev.oereb @@ -323,47 +369,61 @@ class CHPollutedSitesPublicTransports(): pass # models for the topic noise - if 'road_noise' in db_config['restrictions']: + table_def_ = db_config['tables']['noise_sensitivity_levels'] + class RoadNoise(GeoInterface, Base): - __tablename__ = 'v_r145_sens_bruit' - __table_args__ = {'schema': 'noise_sensitivity_levels', 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: class RoadNoise(): pass - # models for water protection -class WaterProtectionZones(GeoInterface, Base): - __tablename__ = 'r131_zone_prot_eau' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(String(40), primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) +if 'groundwater_protection_zones' in db_config['restrictions']: + table_def_ = db_config['tables']['groundwater_protection_zones'] + class WaterProtectionZones(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(String(40), primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) +else: + class WaterProtectionZones(): + pass +if 'groundwater_protection_sites' in db_config['restrictions']: + table_def_ = db_config['tables']['groundwater_protection_sites'] -class WaterProtectionPerimeters(GeoInterface, Base): - __tablename__ = 'r132_perimetre_prot_eau' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} - idobj = Column(String(40), primary_key=True) - geom = Column(Geometry("GEOMETRY", srid=srid_)) + class WaterProtectionPerimeters(GeoInterface, Base): + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} + idobj = Column(String(40), primary_key=True) + geom = Column(Geometry("GEOMETRY", srid=srid_)) +else: + class WaterProtectionPerimeters(): + pass # models for the topic Forest -if 'forest_limits' in db_config['restrictions']: +if 'forest_perimeters' in db_config['restrictions']: + table_def_ = db_config['tables']['forest_perimeters'] + class ForestLimits(GeoInterface, Base): - __tablename__ = 'r157_lim_foret' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: class ForestLimits(): pass -if 'forest_distances' in db_config['restrictions']: +if 'forest_distance_lines' in db_config['restrictions']: + table_def_ = db_config['tables']['forest_distance_lines'] + class ForestDistances(GeoInterface, Base): - __tablename__ = 'r159_dist_foret' - __table_args__ = {'schema': db_config['schema'], 'autoload': True} + __tablename__ = table_def_['tablename'] + __table_args__ = {'schema': table_def_['schema'], 'autoload': True} idobj = Column(Integer, primary_key=True) geom = Column(Geometry("GEOMETRY", srid=srid_)) else: