From 1142fc14011146d960ba0e53e5699ce37d95fd91 Mon Sep 17 00:00:00 2001 From: Kay Warrie Date: Wed, 20 Sep 2017 12:06:14 +0200 Subject: [PATCH] 1.7.0 --- geopunt.py | 237 +++++++++++++++------------------ geopunt4QgisAdresdialog.py | 15 +-- geopunt4QgisParcel.py | 19 +-- metadata.txt | 2 +- metadataParser.py | 84 ++++++------ parcelHelper.py | 17 ++- ui_geopunt4QgisBatchGeoCode.ui | 34 ++++- 7 files changed, 200 insertions(+), 208 deletions(-) diff --git a/geopunt.py b/geopunt.py index a089d74..04bb183 100644 --- a/geopunt.py +++ b/geopunt.py @@ -28,10 +28,10 @@ def __init__(self, timeout=15, proxyUrl=""): self._sugUrl = "http://loc.api.geopunt.be/v3/Suggestion?" if isinstance(proxyUrl, (str, unicode)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None + proxy = urllib2.ProxyHandler() + auth = urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) def _createLocationUrl(self, q, c=1): geopuntUrl = self._locUrl @@ -45,15 +45,13 @@ def _createLocationUrl(self, q, c=1): def fetchLocation(self, q, c=1): url = self._createLocationUrl(q, c=1) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - return str( e.reason ) + raise geopuntError( str( e.reason ) ) except: - return str( sys.exc_info()[1] ) + raise geopuntError( sys.exc_info()[1] ) else: - resp= response.read() - LocationResult = json.loads(resp) + LocationResult = json.load(response) return LocationResult["LocationResult"] def _createSuggestionUrl(self, q, c=5): @@ -68,15 +66,13 @@ def _createSuggestionUrl(self, q, c=5): def fetchSuggestion(self, q, c=5): url = self._createSuggestionUrl(q,c) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - return str( e.reason ) + raise geopuntError( str( e.reason )) except: - return str( sys.exc_info()[1] ) + raise geopuntError( sys.exc_info()[1] ) else: - resp= response.read() - suggestion = json.loads(resp) + suggestion = json.load(response) return suggestion["SuggestionResult"] class Poi: @@ -87,10 +83,10 @@ def __init__(self, timeout=15, proxyUrl=""): if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None + proxy = urllib2.ProxyHandler() + auth= urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) #REMARK: WGS coordinates as input! self.maxBounds = [1.17, 49.77, 7.29, 52.35] @@ -104,8 +100,7 @@ def listPoiThemes(self): url = self._poiUrl + "/themes" poithemes = None try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except urllib2.HTTPError as e: return json.load(e)["Message"] except urllib2.URLError as e: @@ -126,8 +121,7 @@ def listPoiCategories(self, themeid=""): poicategories = None try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except urllib2.HTTPError as e: return json.load(e)["Message"] except urllib2.URLError as e: @@ -146,8 +140,7 @@ def listPoitypes(self, themeid="", categoriename=""): url = self._poiUrl + "/poitypes" try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except urllib2.HTTPError as e: return json.load(e)["Message"] except urllib2.URLError as e: @@ -199,19 +192,18 @@ def fetchPoi(self, q, c=30, srs=31370, maxModel=True , updateResults=True, url = self._createPoiUrl( q, c, srs, maxModel, bbox, theme, category, POItype, region, clustering) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except urllib2.HTTPError as e: - error = e.read() - errorjs = json.loads(error) - if "Message" in errorjs.keys(): - return error["Message"] - else: - return error + error = e.read() + errorjs = json.loads(error) + if "Message" in errorjs.keys(): + return error["Message"] + else: + return error except urllib2.URLError as e: - return str( e.reason ) + return str( e.reason ) except: - return str( sys.exc_info()[1] ) + return str( sys.exc_info()[1] ) else: poi = json.load(response) @@ -301,66 +293,62 @@ def __init__(self, timeout=15, proxyUrl=""): if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None + proxy = urllib2.ProxyHandler() + auth = urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) def getCity(self, q="" ): query = urllib.quote(q) url = self.baseUri + "referencedata/city/" + query try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise geopuntError(str( e.reason )) + raise geopuntError(str( e.reason )) except: - raise geopuntError( str( sys.exc_info()[1] )) + raise geopuntError( str( sys.exc_info()[1] )) else: - city = json.load(response) - return city + city = json.load(response) + return city def getProvince(self, q="" ): query = urllib.quote(q) url = self.baseUri + "referencedata/province/" + query try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise geopuntError(str( e.reason )) + raise geopuntError(str( e.reason )) except: - raise geopuntError( str( sys.exc_info()[1] )) + raise geopuntError( str( sys.exc_info()[1] )) else: - province = json.load(response) - return province + province = json.load(response) + return province def getEventType(self, q="" ): query = urllib.quote(q) url = self.baseUri + "referencedata/eventtype/" + query try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise geopuntError( str( e.reason )) + raise geopuntError( str( e.reason )) except: - raise geopuntError( str( sys.exc_info()[1] )) + raise geopuntError( str( sys.exc_info()[1] )) else: - eventtype = json.load(response) - return eventtype + eventtype = json.load(response) + return eventtype def getOwner(self, q=''): query = urllib.quote(q) url = self.baseUri + "referencedata/owner/" + query try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise geopuntError( str( e.reason )) + raise geopuntError( str( e.reason )) except: - raise geopuntError( str( sys.exc_info()[1] )) + raise geopuntError( str( sys.exc_info()[1] )) else: - owner = json.load(response) - return owner + owner = json.load(response) + return owner def _createWorkassignmentUrl(self, owner="", startdate=None, enddate=None, city="", province="", srs=31370, bbox=[], c=50, offset=0 ): "startdate and enddate are datetime.date\n bbox is [xmin,ymin,xmax,ymax]" @@ -368,24 +356,24 @@ def _createWorkassignmentUrl(self, owner="", startdate=None, enddate=None, city= data = {} data['limit'] = c if offset: - data["offset"] = offset + data["offset"] = offset if owner: - data['owner'] = owner + data['owner'] = owner if startdate and isinstance(startdate, datetime.date): - data["startdate"] = startdate.__str__() + data["startdate"] = startdate.__str__() if enddate and isinstance(enddate, datetime.date): - data["enddate"] = enddate.__str__() + data["enddate"] = enddate.__str__() if city: - data['city'] = city + data['city'] = city if province: - data['province'] = province + data['province'] = province if srs in [31370,4326,3857]: - data['CRS'] = srs + data['CRS'] = srs if bbox and isinstance(bbox,(list,tuple)) and len(bbox) == 4: - xmin,ymin,xmax,ymax = bbox - xymin = str(xmin) +','+ str(ymin) - xymax = str(xmax) +','+ str(ymax) - data["bbox"] = '|'.join([xymin,xymax]) + xmin,ymin,xmax,ymax = bbox + xymin = str(xmin) +','+ str(ymin) + xymax = str(xmax) +','+ str(ymax) + data["bbox"] = '|'.join([xymin,xymax]) values = urllib.urlencode(data) result = endpoint + values return result @@ -393,15 +381,14 @@ def _createWorkassignmentUrl(self, owner="", startdate=None, enddate=None, city= def fetchWorkassignment(self,owner="", startdate=None, enddate=None, city="", province="", srs=31370, bbox=[], c=50, offset=0 ): url = self._createWorkassignmentUrl(owner, startdate, enddate, city, province, srs, bbox, c, offset ) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise geopuntError( str( e.reason )) + raise geopuntError( str( e.reason )) except: - raise geopuntError( str( sys.exc_info()[1] )) + raise geopuntError( str( sys.exc_info()[1] )) else: - workassignment = json.load(response) - return workassignment + workassignment = json.load(response) + return workassignment def allWorkassignments(self, owner="", startdate=None, enddate=None, city="", province="", srs=31370, bbox=[]): counter = 0 @@ -446,8 +433,7 @@ def _createManifestationUrl(self, owner="", eventtype="", startdate=None, enddat def fetchManifestation(self, owner="", eventtype="", startdate=None, enddate=None, city="", province="", srs=31370, bbox=[], c=50, offset=0 ): url = self._createManifestationUrl(owner, eventtype, startdate, enddate, city, province, srs, bbox, c, offset ) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( str( e.reason )) except: @@ -474,11 +460,11 @@ def __init__(self, timeout=15, proxyUrl=""): if isinstance(proxyUrl, (str, unicode)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl}) - auth = urllib2.HTTPBasicAuthHandler() - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None - + proxy = urllib2.ProxyHandler() + auth = urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + def _createElevationRequest(self, LineString, srs=31370, samples=50 ): geojson = {} geojson["SrsIn"] = srs @@ -493,17 +479,14 @@ def fetchElevaton(self, LineString, srs=31370, samples=50 ): "LineString= a serie of points in form [[4.2,51.27],[4.7,51.2],...], srs=ESPGcode, samples=nummer to return" req = self._createElevationRequest( LineString, srs, samples ) try: - if self.opener: - response = self.opener.open(req, timeout= self.timeout) - else: - response = urllib2.urlopen(req, timeout= self.timeout) + response = self.opener.open(req, timeout= self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise geopuntError( str( e.reason )) + raise geopuntError( str( e.reason )) except: - raise geopuntError( str( sys.exc_info()[1] )) + raise geopuntError( str( sys.exc_info()[1] )) else: - elevationJson = json.load(response) - return elevationJson + elevationJson = json.load(response) + return elevationJson class capakey: def __init__(self, timeout=15, proxyUrl=""): @@ -512,19 +495,15 @@ def __init__(self, timeout=15, proxyUrl=""): if isinstance(proxyUrl, (str, unicode)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None + proxy = urllib2.ProxyHandler() + auth = urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) def getMunicipalities(self): url = self.baseUrl + "/municipality/" try: - if self.opener: - print url +" proxy "+ str(self.opener) - response = self.opener.open(url, timeout=self.timeout) - else: - response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -543,8 +522,7 @@ def getMunicipalitieInfo(self, niscode, srs=31370, geometryType="no" ): url = "{0}/municipality/{1}?{2}".format( self.baseUrl, niscode, values ) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -557,8 +535,7 @@ def getDepartments(self, niscode): url = "{0}/municipality/{1}/department/".format( self.baseUrl, niscode) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -577,8 +554,7 @@ def getDepartmentInfo(self, niscode, departmentCode, srs=31370, geometryType="no url = "{0}/municipality/{1}/department/{2}?{3}".format( self.baseUrl, niscode, departmentCode, values) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -591,8 +567,7 @@ def getSections(self, niscode, departmentCode): url = "{0}/municipality/{1}/department/{2}/section/".format( self.baseUrl, niscode, departmentCode) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -611,8 +586,7 @@ def getSectionInfo(self, niscode, departmentCode, sectieCode, srs=31370, geometr url = "{0}/municipality/{1}/department/{2}/section/{3}?{4}".format( self.baseUrl, niscode, departmentCode, sectieCode, values) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -625,8 +599,7 @@ def getParcels(self, niscode, departmentCode, sectieCode): url = "{0}/municipality/{1}/department/{2}/section/{3}/parcel".format( self.baseUrl, niscode, departmentCode, sectieCode) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -645,8 +618,7 @@ def getParcel(self, niscode, departmentCode, sectieCode, perceelnummer, srs=3137 url = "{0}/municipality/{1}/department/{2}/section/{3}/parcel/{4}?{5}".format( self.baseUrl, niscode, departmentCode, sectieCode, perceelnummer, values) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: raise geopuntError( e.reason ) except: @@ -664,10 +636,10 @@ def __init__(self, timeout=15, proxyUrl=""): self._sugUrl = "http://perc.geopunt.be/Perceel/Suggestion?" if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None + proxy = urllib2.ProxyHandler() + auth = urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) def _createLocationUrl(self, q, c=1): geopuntUrl = self._locUrl @@ -681,15 +653,14 @@ def _createLocationUrl(self, q, c=1): def fetchLocation(self, q, c=1): url = self._createLocationUrl(q, c=1) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - return str( e.reason ) + return str( e.reason ) except: - return str( sys.exc_info()[1] ) + return str( sys.exc_info()[1] ) else: - LocationResult = json.load(response) - return LocationResult["LocationResult"] + LocationResult = json.load(response) + return LocationResult["LocationResult"] def _createSuggestionUrl(self, q, c=5): geopuntUrl = self._sugUrl @@ -703,15 +674,14 @@ def _createSuggestionUrl(self, q, c=5): def fetchSuggestion(self, q, c=5): url = self._createSuggestionUrl(q,c) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: return str( e.reason ) except: - return str( sys.exc_info()[1] ) + return str( sys.exc_info()[1] ) else: - suggestion = json.load(response) - return suggestion["SuggestionResult"] + suggestion = json.load(response) + return suggestion["SuggestionResult"] def getPercGeom(self, capakey, srs=31370): capaUrl = self._esriCapaServer @@ -722,8 +692,7 @@ def getPercGeom(self, capakey, srs=31370): url = capaUrl + values try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: return str( e.reason ) except: @@ -740,11 +709,15 @@ def __str__(self): def internet_on( proxyUrl="", timeout=15 ): opener = None - if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl != "": + if isinstance(proxyUrl, (str, unicode)) and proxyUrl != "": proxy = urllib2.ProxyHandler({'http': proxyUrl }) auth = urllib2.HTTPBasicAuthHandler() opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) - # try: + else: + proxy = urllib2.ProxyHandler() + auth = urllib2.HTTPBasicAuthHandler() + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + if opener: opener.open( 'http://loc.api.geopunt.be/v2/Suggestion', timeout=timeout ) return True diff --git a/geopunt4QgisAdresdialog.py b/geopunt4QgisAdresdialog.py index c0c4433..0b2900b 100644 --- a/geopunt4QgisAdresdialog.py +++ b/geopunt4QgisAdresdialog.py @@ -133,11 +133,7 @@ def onZoekActivated(self): self.ui.resultLijst.addItems(suggesties) if len(suggesties) == 1: self.ui.resultLijst.setCurrentRow(0) - elif type( suggesties ) is str: - self.bar.pushMessage( - QtCore.QCoreApplication.translate("geopunt4QgisAdresDialog","Waarschuwing"), - suggesties, level=QgsMessageBar.WARNING) - + def onItemActivated( self, item): txt = item.text() self._zoomLoc(txt) @@ -209,15 +205,6 @@ def _addToMap(self, txt): self.gh.save_adres_point( pt, adres, typeAddress=LocationType, layername=self.layerName, saveToFile=self.saveToFile, sender=self, startFolder= os.path.join(self.startDir, self.layerName)) - - elif type( locations ) is str: - self.bar.pushMessage( - QtCore.QCoreApplication.translate("geopunt4QgisAdresDialog","Waarschuwing"), - locations, level=QgsMessageBar.WARNING) - else: - self.bar.pushMessage("Error", - QtCore.QCoreApplication.translate("geopunt4QgisAdresDialog","onbekende fout"), - level=QgsMessageBar.CRITICAL) def layernameValid(self): if not hasattr(self, 'layerName'): diff --git a/geopunt4QgisParcel.py b/geopunt4QgisParcel.py index 1577519..b9fa284 100644 --- a/geopunt4QgisParcel.py +++ b/geopunt4QgisParcel.py @@ -133,19 +133,12 @@ def saveParcel(self): if '' in (niscode, departmentcode, section, parcelNr): return - try: - parcelInfo = self.parcel.getParcel( niscode, departmentcode, section, parcelNr, 31370, 'full') - shape = json.loads( parcelInfo['geometry']['shape']) - pts = [n.asPolygon() for n in self.PolygonsFromJson( shape )] - mPolygon = QgsGeometry.fromMultiPolygon( pts ) - self.ph.save_parcel_polygon(mPolygon, parcelInfo, self.layerName, self.saveToFile, - self, os.path.join(self.startDir, self.layerName)) - except geopunt.geopuntError as e: - self.bar.pushMessage("Error", str( e.message) , level=QgsMessageBar.WARNING, duration=5) - return - except Exception as e: - self.bar.pushMessage("Error", str( e.message) , level=QgsMessageBar.CRITICAL) - return + parcelInfo = self.parcel.getParcel( niscode, departmentcode, section, parcelNr, 31370, 'full') + shape = json.loads( parcelInfo['geometry']['shape']) + pts = [n.asPolygon() for n in self.PolygonsFromJson( shape )] + mPolygon = QgsGeometry.fromMultiPolygon( pts ) + self.ph.save_parcel_polygon(mPolygon, parcelInfo, self.layerName, self.saveToFile, + self, os.path.join(self.startDir, self.layerName)) self.accept() diff --git a/metadata.txt b/metadata.txt index cae1239..4d75852 100644 --- a/metadata.txt +++ b/metadata.txt @@ -8,7 +8,7 @@ qgisMinimumVersion=2.4 description= NL: Plugin om geopunt diensten in QGIS te gebruiken: - Zoeken op adres [gewoon, in batch en prikken op kaart] op basis van CRAB (Vlaanderen) en URBIS (Brussel) - Zoeken naar Intressepunten in geopunt - zoeken naar wegenwerken en manifestaties in GIPOD - Hoogte Profielen tekenen - Zoeken naar percelen - Zoeken naar lagen in de geopunt catlogus EN: Plug-in to use geopunt services in QGIS: - Geocoding [regular, batch and reverse] based on CRAB (Flanders) and and URBIS (Brussels) - Search for POI's in geopunt - Search for trafic obstructions in GIPOD - Draw elevation profiles - Search for Parcels - Search for layers in the geopunt catalog about="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. -version=1.6.9 +version=1.7.0 author=Kay Warrie email=kay@kgis.be diff --git a/metadataParser.py b/metadataParser.py index 26cfd2a..84c1c7b 100644 --- a/metadataParser.py +++ b/metadataParser.py @@ -79,11 +79,12 @@ def __init__(self, timeout=15, proxyUrl='' ): self.inspireannex = ["i","ii","iii"] if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl != "": - auth = urllib2.HTTPBasicAuthHandler() proxy = urllib2.ProxyHandler({'http': proxyUrl }) - self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) else: - self.opener = None + proxy = urllib2.ProxyHandler() + + auth = urllib2.HTTPBasicAuthHandler() + self.opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) def _createFindUrl(self, q='', start=1, to=20, themekey='', orgName='', dataType='', siteId='', inspiretheme='', inspireannex='', inspireServiceType=''): geopuntUrl = self.geoNetworkUrl + "/q?fast=index&sortBy=changeDate&" @@ -123,14 +124,12 @@ def _createFindUrl(self, q='', start=1, to=20, themekey='', orgName='', dataType def list_GDI_theme(self, q=''): url = self.geoNetworkUrl + "/xml.search.keywords?pNewSearch=true&pTypeSearch=1&pThesauri=external.theme.GDI-Vlaanderen-trefwoorden&pKeyword=*" + unicode(q).encode('utf-8') +"*" try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: #raise metaError( str( e.reason )) return [] except: - print metaError( str( sys.exc_info()[1] )) - return [] + raise metaError( str( e.reason )) else: result = ET.parse(response) r= result.getroot() @@ -141,14 +140,12 @@ def list_GDI_theme(self, q=''): def list_inspire_theme(self, q=''): url = self.geoNetworkUrl + "/xml.search.keywords?pNewSearch=true&pTypeSearch=1&pThesauri=external.theme.inspire-theme&pKeyword=*" + unicode(q).encode('utf-8') +"*" try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: #raise metaError( str( e.reason )) return [] except: - print metaError( str( sys.exc_info()[1] )) - return [] + raise metaError( str( e.reason )) else: result = ET.parse(response) r= result.getroot() @@ -160,12 +157,10 @@ def list_suggestionKeyword(self, q=''): url = self.geoNetworkUrl + "/main.search.suggest?field=any" if q: url= url + "&q=" + unicode(q).encode('utf-8') - try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - print metaError( str( e.reason )) + #raise metaError( str( e.reason )) return [] except: raise metaError( str( sys.exc_info()[1] )) @@ -178,10 +173,9 @@ def list_organisations(self, q=''): if q: url= url + "&q=" + unicode(q).encode('utf-8') try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - print metaError( str( e.reason )) + #raise metaError( str( e.reason )) return [] except: raise metaError( str( sys.exc_info()[1] )) @@ -197,10 +191,9 @@ def list_organisations(self, q=''): def list_bronnen(self): url = self.geoNetworkUrl + "/xml.info?type=sources" try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise metaError( str( e.reason )) + return [] except: raise metaError( str( sys.exc_info()[1] )) else: @@ -214,10 +207,9 @@ def list_bronnen(self): def search(self, q='', start=1, to=20, themekey='', orgName='', dataType='', siteId='', inspiretheme='', inspireannex='', inspireServiceType='' ): url = self._createFindUrl( q, start, to, themekey, orgName, dataType, siteId, inspiretheme, inspireannex, inspireServiceType) try: - if self.opener: response = self.opener.open(url, timeout=self.timeout) - else: response = urllib2.urlopen(url, timeout=self.timeout) + response = self.opener.open(url, timeout=self.timeout) except (urllib2.HTTPError, urllib2.URLError) as e: - raise metaError( str( e.reason ) +' on '+ url ) + return [] except: raise metaError( str( sys.exc_info()[1] )) else: @@ -252,16 +244,18 @@ def getWmsLayerNames( url='', proxyUrl=''): else: capability = url + auth = urllib2.HTTPBasicAuthHandler() if isinstance(proxyUrl, (unicode, str)) and proxyUrl != "": if url.startswith("https"): proxy = urllib2.ProxyHandler({'https': proxyUrl }) else: proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) responseWMS = opener.open(capability) else: - responseWMS = urllib2.urlopen(capability) + proxy = urllib2.ProxyHandler() + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + responseWMS = opener.open(capability) result = ET.parse(responseWMS) layers = result.findall( ".//{http://www.opengis.net/wms}Layer" ) + result.findall( ".//Layer" ) @@ -285,16 +279,18 @@ def getWFSLayerNames( url, proxyUrl=''): else: capability = url + auth = urllib2.HTTPBasicAuthHandler() if isinstance(proxyUrl, (unicode, str)) and proxyUrl != "": if url.startswith("https"): proxy = urllib2.ProxyHandler({'https': proxyUrl }) else: proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) responseWFS = opener.open(capability) else: - responseWFS = urllib2.urlopen(capability) + proxy = urllib2.ProxyHandler() + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + responseWFS = opener.open(capability) result = ET.parse(responseWFS) layers = result.findall( ".//{http://www.opengis.net/wfs}FeatureType" ) @@ -315,16 +311,19 @@ def getWMTSlayersNames( url, proxyUrl='' ): capability = url.split("?")[0] + "?service=WMTS&request=Getcapabilities" else: capability = url + + auth = urllib2.HTTPBasicAuthHandler() if isinstance(proxyUrl, (unicode, str)) and proxyUrl != "": - if url.startswith("https"): + if url.startswith("https"): proxy = urllib2.ProxyHandler({'https': proxyUrl }) - else: + else: proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) - responseWMTS = opener.open(capability) + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + responseWMTS = opener.open(capability) else: - responseWMTS = urllib2.urlopen(capability) + proxy = urllib2.ProxyHandler() + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + responseWMTS = opener.open(capability) result = ET.parse(responseWMTS).getroot() content = result.find( "{http://www.opengis.net/wmts/1.0}Contents" ) @@ -357,16 +356,19 @@ def getWCSlayerNames( url, proxyUrl='' ): capability = url.split("?")[0] + "?request=GetCapabilities&version=1.1.0&service=wcs" else: capability = url + + auth = urllib2.HTTPBasicAuthHandler() if isinstance(proxyUrl, (unicode, str)) and proxyUrl != "": - if url.startswith("https"): + if url.startswith("https"): proxy = urllib2.ProxyHandler({'https': proxyUrl }) - else: + else: proxy = urllib2.ProxyHandler({'http': proxyUrl }) - auth = urllib2.HTTPBasicAuthHandler() - opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) - responseWCS = opener.open(capability) + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + responseWCS = opener.open(capability) else: - responseWCS = urllib2.urlopen(capability) + proxy = urllib2.ProxyHandler() + opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) + responseWCS = opener.open(capability) responseTxt = responseWCS.read() if 'xmlns:wcs="http://www.opengis.net/wcs/1.1.1"' in responseTxt: @@ -391,7 +393,7 @@ def getWCSlayerNames( url, proxyUrl='' ): opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) responseDC = opener.open(DescribeCoverage) else: - responseDC = urllib2.urlopen(DescribeCoverage) + responseDC = urllib2.urlopen(DescribeCoverage) resultDC = ET.parse(responseDC).getroot() CoverageDescription = resultDC.find( "{%s}CoverageDescription" % wcsNS) diff --git a/parcelHelper.py b/parcelHelper.py index d759d0a..c961de1 100644 --- a/parcelHelper.py +++ b/parcelHelper.py @@ -37,9 +37,11 @@ def __init__(self, iface, parent= None, startFolder="" ): def save_parcel_polygon(self, polygon, parcelInfo, layername="perceel", saveToFile=False, sender=None, startFolder=None ): - attributes =[ QgsField("macht", QVariant.Int), QgsField("bisnummer", QVariant.Int) , QgsField("exponent", QVariant.String), - QgsField("adres", QVariant.String), QgsField("capakey", QVariant.String), QgsField("grondnr", QVariant.Int), - QgsField("type", QVariant.String), QgsField("perceelnr", QVariant.String) ] + attributes =[ QgsField("niscode", QVariant.String), QgsField("afdeling", QVariant.String), QgsField("afdcode", QVariant.String), + QgsField("sectie", QVariant.String), QgsField("bisnummer", QVariant.Int) , + QgsField("exponent", QVariant.String), QgsField("macht", QVariant.Int), + QgsField("grondnr", QVariant.Int), QgsField("capakey", QVariant.String), + QgsField("perceelnr", QVariant.String), QgsField("adres", QVariant.String) ] if not QgsMapLayerRegistry.instance().mapLayer(self.parcellayerid): self.parcellayer = QgsVectorLayer("MultiPolygon", layername, "memory") @@ -55,14 +57,17 @@ def save_parcel_polygon(self, polygon, parcelInfo, layername="perceel", saveToFi fet.setGeometry(polygon) #populate fields - fet['macht'] = parcelInfo['macht'] + fet['adres'] = ", ".join( parcelInfo['adres'] ) + fet['sectie'] = parcelInfo['sectionCode'] fet['bisnummer'] = parcelInfo['bisnummer'] fet['exponent'] = parcelInfo['exponent'] fet['adres'] = ", ".join( parcelInfo['adres'] ) fet['capakey'] = parcelInfo['capakey'] fet['grondnr'] = parcelInfo['grondnummer'] - fet['type'] = parcelInfo['type'] - fet['perceelnr'] = parcelInfo['perceelnummer'] + fet['NISCode'] = parcelInfo['municipalityCode'] + fet['afdeling'] = parcelInfo['departmentName'] + fet['perceelnr'] = parcelInfo['perceelnummer'] + fet['afdcode'] = parcelInfo['departmentCode'] self.parcelProvider.addFeatures([ fet ]) "" diff --git a/ui_geopunt4QgisBatchGeoCode.ui b/ui_geopunt4QgisBatchGeoCode.ui index 6c9c068..adc6b05 100644 --- a/ui_geopunt4QgisBatchGeoCode.ui +++ b/ui_geopunt4QgisBatchGeoCode.ui @@ -8,7 +8,7 @@ 0 0 621 - 520 + 599 @@ -647,5 +647,37 @@ + + multipleColChk + toggled(bool) + huisnrLbl + setVisible(bool) + + + 165 + 157 + + + 170 + 248 + + + + + multipleColChk + toggled(bool) + huisnrSelect + setVisible(bool) + + + 165 + 157 + + + 450 + 248 + + +