Skip to content

Commit

Permalink
version 2.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
warrieka committed Oct 22, 2021
1 parent 119f366 commit 07189dc
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 61 deletions.
25 changes: 18 additions & 7 deletions geopunt/basisregisters.py
Expand Up @@ -3,7 +3,6 @@


class adresMatch(object):

def __init__(self):
self._gemUrl = "https://api.basisregisters.vlaanderen.be/v1/gemeenten/"
self._amUrl = "https://api.basisregisters.vlaanderen.be/v1/adresmatch"
Expand All @@ -26,7 +25,7 @@ def gemeenten(self, langcode="nl", step=500, stop=1500):
"Naam": n['gemeentenaam']['geografischeNaam']['spelling'] }
for n in result["gemeenten"]
if n['gemeentenaam']['geografischeNaam']['taal'] == langcode
and n["gemeenteStatus"] == "inGebruik"]
and n["gemeenteStatus"].lower() != "gehistoreerd"]

return sorted(gemeenten, key=lambda k: k['Naam'])

Expand All @@ -43,8 +42,13 @@ def findMatches(self, municipality="", niscode="", postalcode="", kadstreetcode=
data["Index"] = rrindex if rrindex else ""
data["Busnummer"] = boxnr if boxnr else ""

result = json.loads( getUrlData(self._amUrl, params=data) )
return [ n for n in result['adresMatches'] if n["adresStatus"] == "InGebruik" ]
try:
result = json.loads( getUrlData(self._amUrl, params=data) )
except BaseException as err:
print(f"Unexpected {err=}, {type(err)=}")
return []

return [ n for n in result['adresMatches'] if not "adresStatus" in n.keys() or n["adresStatus"].lower() != "gehistoreerd" ]

def findMatchFromSingleLine(self, adres):
adr = [n.strip() for n in adres.split(",")]
Expand All @@ -67,8 +71,14 @@ def findMatchFromSingleLine(self, adres):
data["Straatnaam"] = street
data["Huisnummer"] = housenr

result = json.loads( getUrlData( self._amUrl, params=data ) )
return [ n for n in result['adresMatches'] if n["adresStatus"] == "InGebruik" ]
try:
result = json.loads( getUrlData( self._amUrl, params=data ) )
except BaseException as err:
print(f"Unexpected {err=}, {type(err)=}")
return []

return [ n for n in result['adresMatches']
if not "adresStatus" in n.keys() or n["adresStatus"].lower() != "gehistoreerd" ]


def findAdresSuggestions(self, single=None, municipality="", niscode="", postalcode="",
Expand All @@ -81,6 +91,7 @@ def findAdresSuggestions(self, single=None, municipality="", niscode="", postalc

results = []
for match in matches:
if "volledigAdres" in match.keys() and not 'busnummer' in match.keys() and not match["adresStatus"] == "InGebruik":
if ("volledigAdres" in match.keys() and not 'busnummer' in match.keys()
and ("adresStatus" not in match.keys() or match["adresStatus"].lower() != "gehistoreerd")):
results.append( match['volledigAdres']['geografischeNaam']['spelling'] )
return results
3 changes: 3 additions & 0 deletions geopunt/metadataParser.py
Expand Up @@ -102,13 +102,15 @@ def _createFindUrl(self, q="", start=0, maxRecords=100, orgName='', dataType='')
def list_suggestionKeyword(self):
url = self.geoNetworkUrl + "?request=GetDomain&service=CSW&version=2.0.2&PropertyName=title"
response = getUrlData(url )

result = ET.fromstring( response )
val1 = [ n.text for n in result.findall('.//{http://www.opengis.net/cat/csw/2.0.2}Value') ]
return val1

def list_organisations(self):
url = self.geoNetworkUrl + '?request=GetDomain&service=CSW&version=2.0.2&PropertyName=OrganisationName'
response = getUrlData(url )

result = ET.fromstring( response )
organisations = [ n.text for n in result.findall('.//{http://www.opengis.net/cat/csw/2.0.2}Value') ]
organisations.sort()
Expand All @@ -117,6 +119,7 @@ def list_organisations(self):
def search(self, q="", start=0, step=100, orgName='', dataType=''):
url = self._createFindUrl( q, start, step, orgName, dataType)
response = getUrlData(url )

result = ET.fromstring( response )
return result

Expand Down
92 changes: 44 additions & 48 deletions geopunt4QgisBatchGeoCode.py
Expand Up @@ -7,7 +7,7 @@
from .ui_geopunt4QgisBatchGeoCode import Ui_batchGeocodeDlg
from .tools.batchGeo import batcGeoHelper
from .mapTools.reverseAdres import reverseAdresMapTool
from .geopunt import Adres, adresMatch
from .geopunt import adresMatch
from .tools.settings import settings
from .tools.geometry import geometryHelper

Expand Down Expand Up @@ -103,7 +103,6 @@ def addToMap(self):

row= 0
while row < rowCount:

attributes = {}
self.ui.statusProgress.setValue(row)
if self.ui.outPutTbl.cellWidget(row,adresCol):
Expand Down Expand Up @@ -228,11 +227,11 @@ def loadTable(self):
self.ui.outPutTbl.setHorizontalHeaderLabels(header + [QCoreApplication.translate("batcGeoCodedialog", "gevalideerd adres")])

self.ui.adresColSelect.insertItems(0, header)
self.ui.huisnrSelect.insertItems(0, header )
self.ui.huisnrSelect.insertItems(0, [QCoreApplication.translate("batcGeoCodedialog", "<geen>")]+ header )

self.ui.pcColSelect.insertItems(0, header + [QCoreApplication.translate("batcGeoCodedialog", "<geen>")])
self.ui.pcColSelect.insertItems(0, header+ [QCoreApplication.translate("batcGeoCodedialog", "<geen>")] )
self.ui.pcColSelect.setCurrentIndex(colCount)
self.ui.gemeenteColSelect.insertItems(0, header + [QCoreApplication.translate("batcGeoCodedialog", "<geen>")])
self.ui.gemeenteColSelect.insertItems(0, header+ [QCoreApplication.translate("batcGeoCodedialog", "<geen>")] )
self.ui.gemeenteColSelect.setCurrentIndex(colCount)

rowCount = 0
Expand Down Expand Up @@ -303,65 +302,62 @@ def validateRows(self , rowIds):
huisnrTxt = self.ui.huisnrSelect.currentText()
pcTxt = self.ui.pcColSelect.currentText()
gemeenteTxt = self.ui.gemeenteColSelect.currentText()
geenSymbol = QCoreApplication.translate("batcGeoCodedialog", "<geen>")


if gemeenteTxt == QCoreApplication.translate("batcGeoCodedialog", "<geen>") and pcTxt == QCoreApplication.translate("batcGeoCodedialog", "<geen>"):
msg = QCoreApplication.translate("batcGeoCodedialog", "Je moet een postcode of gemeente kolom opgeven.")
QMessageBox.warning(self, 'Warning', msg)
return
if gemeenteTxt == geenSymbol and pcTxt == geenSymbol and not self.ui.singleLineChk.isChecked():
msg = QCoreApplication.translate("batcGeoCodedialog", "Je moet een postcode of gemeente kolom opgeven.")
QMessageBox.warning(self, 'Warning', msg)
return

validAdresCol = self.ui.outPutTbl.columnCount() -1
adresCol = self.headers[adresTxt]
huisnrCol = self.headers[huisnrTxt]
if gemeenteTxt != QCoreApplication.translate("batcGeoCodedialog", "<geen>"):
gemeenteCol = self.headers[gemeenteTxt]
if pcTxt != QCoreApplication.translate("batcGeoCodedialog", "<geen>"):
pcCol = self.headers[pcTxt]
adresCol = self.headers[adresTxt]
huisnrCol = None if huisnrTxt == geenSymbol else self.headers[huisnrTxt]
gemeenteCol = None if gemeenteTxt == geenSymbol else self.headers[gemeenteTxt]
pcCol = None if pcTxt == geenSymbol else self.headers[pcTxt]

self.ui.statusProgress.setValue(0)
self.ui.statusProgress.setMaximum(len(rowIds))
self.ui.statusMsg.setText("")

i= 0
while i < len( rowIds):
rowIdx = rowIds[i]
#status Progress
self.ui.statusProgress.setValue(i)
rowIdx = rowIds[i]
#status Progress
self.ui.statusProgress.setValue(i)

adres = self.ui.outPutTbl.item(rowIdx, adresCol).text()
huisNr = self.ui.outPutTbl.item(rowIdx, huisnrCol).text()
pc, muni = ('', '')
if pcTxt != QCoreApplication.translate("batcGeoCodedialog", "<geen>"): pc = self.ui.outPutTbl.item(rowIdx, pcCol).text()
if gemeenteTxt != QCoreApplication.translate("batcGeoCodedialog", "<geen>"): muni = self.ui.outPutTbl.item(rowIdx, gemeenteCol).text()
try:
adres = self.ui.outPutTbl.item(rowIdx, adresCol).text() if adresCol else ''
huisNr = self.ui.outPutTbl.item(rowIdx, huisnrCol).text() if huisnrCol else ''
pc = self.ui.outPutTbl.item(rowIdx, pcCol).text() if pcCol else ''
muni = self.ui.outPutTbl.item(rowIdx, gemeenteCol).text() if gemeenteCol else ''
if not self.ui.singleLineChk.isChecked():
validAdres = self.am.findAdresSuggestions(municipality=muni, postalcode=pc, housenr=huisNr, streetname=adres)
except:
validAdres = []
if type( validAdres ) is list:
else:
validAdres = self.am.findAdresSuggestions(single=adres)

if type( validAdres ) is list:
if len(validAdres) > 1 and len( validAdres[0].split(',')) >= 2 and len(adres.strip()):
resultNR = validAdres[0].split(',')[0].split()[-1] if len(validAdres[0].split(',')[0].split()) > 0 else validAdres[0]
adresNR = adres.split(',')[0].split()[-1] if len(adres.split(',')[0].split()) > 0 else adres
if adresNR == resultNR: validAdres = [validAdres[0]]
resultNR = validAdres[0].split(',')[0].split()[-1] if len(validAdres[0].split(',')[0].split()) > 0 else validAdres[0]
adresNR = adres.split(',')[0].split()[-1] if len(adres.split(',')[0].split()) > 0 else adres
if adresNR == resultNR: validAdres = [validAdres[0]]

validCombo = QComboBox(self.ui.adresColSelect)
validCombo.addItems(validAdres)
self.ui.outPutTbl.setCellWidget(rowIdx, validAdresCol, validCombo)
if len(validAdres) == 1:
self.ui.outPutTbl.cellWidget(rowIdx, validAdresCol).setEnabled(0)
for col in range(len(self.headers)):
self.ui.outPutTbl.item(rowIdx, col).setBackground( QBrush( QColor("#CCFFCC")) )
elif len(validAdres) > 1:
self.ui.outPutTbl.cellWidget(rowIdx, validAdresCol).addItem("")
for col in range(len(self.headers)):
self.ui.outPutTbl.item(rowIdx, col).setBackground( QBrush( QColor("#FFFFC8")) )
elif len(validAdres) == 0:
self.ui.outPutTbl.setCellWidget(rowIdx, validAdresCol, None)
for col in range(len(self.headers)):
self.ui.outPutTbl.item(rowIdx, col).setBackground( QBrush( QColor("#FFBEBE")) )
i += 1

if len(validAdres) == 1:
self.ui.outPutTbl.cellWidget(rowIdx, validAdresCol).setEnabled(0)
for col in range(len(self.headers)):
self.ui.outPutTbl.item(rowIdx, col).setBackground( QBrush( QColor("#CCFFCC")) )
elif len(validAdres) > 1:
self.ui.outPutTbl.cellWidget(rowIdx, validAdresCol).addItem("")
for col in range(len(self.headers)):
self.ui.outPutTbl.item(rowIdx, col).setBackground( QBrush( QColor("#FFFFC8")) )

elif len(validAdres) == 0:
self.ui.outPutTbl.setCellWidget(rowIdx, validAdresCol, None)
for col in range(len(self.headers)):
self.ui.outPutTbl.item(rowIdx, col).setBackground( QBrush( QColor("#FFBEBE")) )
i += 1

#reset statusbar
self.ui.statusMsg.setText("")
Expand Down
3 changes: 1 addition & 2 deletions geopunt4QgisDataCatalog.py
Expand Up @@ -121,8 +121,7 @@ def resultViewClicked(self):
uuid = self.proxyModel.data(self.proxyModel.index(row, 3))
abstract = self.proxyModel.data(self.proxyModel.index(row, 4))

self.ui.descriptionText.setText(
"""<h3>%s</h3><div>%s</div><br/><div>
self.ui.descriptionText.setText( """<h3>%s</h3><div>%s</div><br/><div>
<a href='https://metadata.vlaanderen.be/srv/dut/catalog.search#/metadata/%s'>
Ga naar fiche</a></div>""" % (title, abstract, uuid))

Expand Down
8 changes: 4 additions & 4 deletions metadata.txt
Expand Up @@ -4,7 +4,7 @@

[general]
name=geopunt4Qgis
qgisMinimumVersion=3.4
qgisMinimumVersion=3.10
description=NL: Plugin om geopunt diensten in QGIS te gebruiken
EN: Plug-in to use geopunt services in QGIS
about=NL: "Geopunt voor QGIS" is een plugin voor de QGIS open source desktop GIS, die de webservices van het Vlaamse geoportaal Geopunt ontsluit naar desktop GIS-gebruikers. Het Vlaamse Geoportaal Geopunt biedt een aantal geografische diensten (web-services) aan die mogen gebruikt worden door derden zoals andere overheden en bedrijven.
Expand All @@ -21,15 +21,15 @@ about=NL: "Geopunt voor QGIS" is een plugin voor de QGIS open source desktop GIS
- Search for Parcels
- Search for layers in the geopunt catalog

version=2.2.5
version=2.2.6
author=Kay Warie
email=kaywarrie@gmail.be

# end of mandatory metadata

# Optional items:
# Uncomment the following line and add your changelog entries:
changelog=Update for new metadata-center
changelog=Refractor to remove deprecated elementen in the code.

# tags are comma separated with spaces allowed
tags=INSPIRE, GEOPUNT, GDI, VLAANDEREN, BRUSSEL, BELGIE, ADRES, ADRESSEN, AGIV, GEOLOKATIE, GEOCODE, WEBSERVICE, GRB, CRAB, FLANDERS, BELGIUM, BRUSSELS, LOCATION, ADDRESS, POINT OF INTEREST, POI, URBIS, GIPOD
Expand All @@ -40,7 +40,7 @@ repository=https://github.com/warrieka/geopunt4Qgis
icon=images/geopunt.png
category=Web
# experimental flag
experimental=False
experimental=True

# deprecated flag (applies to the whole plugin, not just a single version
deprecated=False
Expand Down

0 comments on commit 07189dc

Please sign in to comment.