Skip to content

Commit

Permalink
Support for multiple FeatureTypes in one response; Support for multip…
Browse files Browse the repository at this point in the history
…le GeometryTypes per FeatureType
  • Loading branch information
JuergenWeichand committed Apr 4, 2015
1 parent 11deeec commit 58c13bb
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name=WFS 2.0 Client
description=Client for OGC Web Feature Service 2.0.0
category=Web
version=0.9.2
version=0.9.3
qgisMinimumVersion=2.4
experimental=False
class_name=WfsClient
Expand Down
2 changes: 1 addition & 1 deletion ui_wfsclient.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>WFS 2.0 Client - Version 0.9.2 beta</string>
<string>WFS 2.0 Client - Version 0.9.3 beta</string>
</property>
<widget class="QLabel" name="lblOnlineResource">
<property name="geometry">
Expand Down
2 changes: 1 addition & 1 deletion wfsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def unload(self):
self.iface.removePluginMenu("&WFS 2.0 Client", self.aboutAction)

def about(self):
infoString = "<table><tr><td colspan=\"2\"><b>WFS 2.0 Client 0.9.2 beta</b></td></tr><tr><td colspan=\"2\"></td></tr><tr><td>Author:</td><td>J&uuml;rgen Weichand</td></tr><tr><td>Mail:</td><td><a href=\"mailto:juergen@weichand.de\">juergen@weichand.de</a></td></tr><tr><td>Website:</td><td><a href=\"http://www.weichand.de\">http://www.weichand.de</a></td></tr></table>"
infoString = "<table><tr><td colspan=\"2\"><b>WFS 2.0 Client 0.9.3 beta</b></td></tr><tr><td colspan=\"2\"></td></tr><tr><td>Author:</td><td>J&uuml;rgen Weichand</td></tr><tr><td>Mail:</td><td><a href=\"mailto:juergen@weichand.de\">juergen@weichand.de</a></td></tr><tr><td>Website:</td><td><a href=\"http://www.weichand.de\">http://www.weichand.de</a></td></tr></table>"
QMessageBox.information(self.iface.mainWindow(), "About WFS 2.0 Client", infoString)

# run method that performs all the real work
Expand Down
103 changes: 93 additions & 10 deletions wfsclientdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from qgis.core import *
from xml.etree import ElementTree
from osgeo import gdal
from osgeo import ogr
import urllib
import urllib2
import string
Expand All @@ -35,6 +36,7 @@
import os
import os.path
import re
import logging
import epsglib
import wfs20lib
from metadataclientdialog import MetadataClientDialog
Expand All @@ -52,6 +54,10 @@ def __init__(self, parent):

self.settings = QtCore.QSettings()

logformat = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logfile = self.get_temppath("wfs20client.log")
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=logformat)

self.ui.frmExtent.show()
self.ui.frmParameter.hide()
self.ui.progressBar.setVisible(False)
Expand Down Expand Up @@ -825,10 +831,19 @@ def sslErrors(self, errors):

def load_vector_layer(self, filename, layername):

self.ui.lblMessage.setText("Loading GML - Please wait!")
logging.debug("### LOADING GML ###")

# Configure OGR/GDAL GML-Driver
resolvexlinkhref = self.settings.value("/Wfs20Client/resolveXpathHref")
attributestofields = self.settings.value("/Wfs20Client/attributesToFields")

logging.debug("resolveXpathHref " + resolvexlinkhref)
logging.debug("attributesToFields " + attributestofields)

gdaltimeout = "5"
logging.debug("GDAL_HTTP_TIMEOUT " + gdaltimeout)
gdal.SetConfigOption("GDAL_HTTP_TIMEOUT", gdaltimeout)
if resolvexlinkhref and resolvexlinkhref == "true":
gdal.SetConfigOption('GML_SKIP_RESOLVE_ELEMS', 'NONE')
else:
Expand All @@ -840,20 +855,88 @@ def load_vector_layer(self, filename, layername):
gdal.SetConfigOption('GML_ATTRIBUTES_TO_OGR_FIELDS', 'NO')


vlayer = QgsVectorLayer(filename, layername, "ogr")
vlayer.setProviderEncoding("UTF-8") #Ignore System Encoding --> TODO: Use XML-Header
if not vlayer.isValid():
# Analyse GML-File
ogrdriver = ogr.GetDriverByName("GML")
logging.debug("OGR Datasource: " + filename)
ogrdatasource = ogrdriver.Open(filename)
logging.debug("... loaded")

if ogrdatasource is None:
QtGui.QMessageBox.critical(self, "Error", "Response is not a valid QGIS-Layer!")
self.ui.lblMessage.setText("")

else:
# Determine the LayerCount
ogrlayercount = ogrdatasource.GetLayerCount()
logging.debug("OGR LayerCount: " + str(ogrlayercount))

hasfeatures = False


# Load every Layer
for i in range(0, ogrlayercount):

j = ogrlayercount -1 - i # Reverse Order?
ogrlayer = ogrdatasource.GetLayerByIndex(j)
ogrlayername = ogrlayer.GetName()
logging.debug("OGR LayerName: " + ogrlayername)

ogrgeometrytype = ogrlayer.GetGeomType()
logging.debug("OGR GeometryType: " + ogr.GeometryTypeToName(ogrgeometrytype))

geomtypeids = []

# Abstract Geometry
if ogrgeometrytype==0:
logging.debug("AbstractGeometry-Strategy ...")
geomtypeids = ["1", "2", "3", "100"]

# One GeometryType
else:
logging.debug("DefaultGeometry-Strategy ...")
geomtypeids = [str(ogrgeometrytype)]


# Create a Layer for each GeometryType
for geomtypeid in geomtypeids:

qgislayername = ogrlayername # + "#" + filename
uri = filename + "|layerid=" + str(j)

if len(geomtypeids) > 1:
uri += "|subset=" + self.getsubset(geomtypeid)

logging.debug("Loading QgsVectorLayer: " + uri)
vlayer = QgsVectorLayer(uri, qgislayername, "ogr")
vlayer.setProviderEncoding("UTF-8") #Ignore System Encoding --> TODO: Use XML-Header

if not vlayer.isValid():
QtGui.QMessageBox.critical(self, "Error", "Response is not a valid QGIS-Layer!")
self.ui.lblMessage.setText("")
else:
featurecount = vlayer.featureCount()
if featurecount > 0:
hasfeatures = True
QgsMapLayerRegistry.instance().addMapLayers([vlayer])
logging.debug("... added Layer! QgsFeatureCount: " + str(featurecount))
self.parent.iface.mapCanvas().zoomToFullExtent()


if hasfeatures == False:
QtGui.QMessageBox.information(self, "Information", "No Features returned!")

self.ui.lblMessage.setText("")
# QGIS 1.8, 1.9
if hasattr(QgsMapLayerRegistry.instance(), "addMapLayers"):
QgsMapLayerRegistry.instance().addMapLayers([vlayer])
# QGIS 1.7
else:
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
self.parent.iface.zoomToActiveLayer()



def getsubset(self, geomcode):

if geomcode == "1": return "OGR_GEOMETRY='POINT' OR OGR_GEOMETRY='MultiPoint'"
elif geomcode == "2": return "OGR_GEOMETRY='LineString' OR OGR_GEOMETRY='MultiLineString'"
elif geomcode == "3": return "OGR_GEOMETRY='Polygon' OR OGR_GEOMETRY='MultiPolygon'"
elif geomcode == "100": return "OGR_GEOMETRY='None'"
else: return "OGR_GEOMETRY='Unknown'"



###
Expand Down

0 comments on commit 58c13bb

Please sign in to comment.