Skip to content

Commit

Permalink
in between
Browse files Browse the repository at this point in the history
  • Loading branch information
rduivenvoorde committed May 30, 2014
1 parent da065d1 commit da662ef
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ compile: $(UI_FILES) $(RESOURCE_FILES)
pyrcc4 -o $*_rc.py $<

%.py : %.ui
pyuic4 -o $@ $<
pyuic4 -do $@ $<

%.qm : %.ts
lrelease $<
Expand Down
2 changes: 1 addition & 1 deletion pdok.json

Large diffs are not rendered by default.

67 changes: 47 additions & 20 deletions pdok2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,43 @@ def handleWMS(wmscapsurl):
abstract = childNodeValue(layer, 'Abstract')
maxscale = childNodeValue(layer, 'MaxScaleDenominator')
minscale = childNodeValue(layer, 'MinScaleDenominator')
#meta = layer.getElementsByTagName('MetadataURL')
#if meta != None:
# print "URL%s"%meta[0].getElementsByTagName('OnlineResource')[0].getAttribute('xlink:href')
# abstract can have newlines in it, which create havoc in json
# because we only use abstract in html, we make <br/> of them
abstract = abstract.replace('\r', '')
abstract = abstract.replace('\t', ' ')
abstract = abstract.replace('\n', '<br/>')
comma = ''
try:
if not firstOne:
comma = ','
# some extract have strange chars, we decode to utf8
s = unicode('%s{"type":"wms","title":"%s","abstract":"%s","url":"%s","layers":"%s","minscale":"%s","maxscale":"%s","servicetitle":"%s","imgformats":"%s"}' % (comma, title, abstract, url, layername, minscale, maxscale, servicetitle, imgformats)).encode('utf8')
# the comma behind the print makes print NOT add a \n newline behind it
# from: http://stackoverflow.com/questions/3249524/print-in-one-line-dynamically-python
print s,
firstOne=False
except Exception, e:
#pass
print "\n\nFout!! In laag: %s" % layername
print e
return
for style in layer.getElementsByTagName('Style'):
styleName = childNodeValue(style, 'Name')
try:
if not firstOne:
comma = ','
# some extract have strange chars, we decode to utf8
s = unicode('%s{"type":"wms","title":"%s","abstract":"%s","url":"%s","layers":"%s","minscale":"%s","maxscale":"%s","servicetitle":"%s","imgformats":"%s", "style":"%s"}' % (comma, title, abstract, url, layername, minscale, maxscale, servicetitle, imgformats, styleName)).encode('utf8')
# the comma behind the print makes print NOT add a \n newline behind it
# from: http://stackoverflow.com/questions/3249524/print-in-one-line-dynamically-python
print s,
firstOne=False
except Exception, e:
#pass
print "\n\nFout!! In laag: %s" % layername
print e
return

# services zoals genoemd in https://www.pdok.nl/nl/producten/pdok-services/overzicht-urls/
services = [
# alle wmts lagen (behalve luchtfoto) zitten in 1 service
('wmts', 'PDOK luchtfoto', 'http://geodata1.nationaalgeoregister.nl/luchtfoto/wmts/1.0.0/WMTSCapabilities.xml'),
('wmts', 'PDOK overige services', 'http://geodata.nationaalgeoregister.nl/wmts?VERSION=1.0.0&request=GetCapabilities'),

#('wmts', 'Basisregistratie Grootschalige Topografie - Achtergrond (WMTS | Open)', 'http://geodata.nationaalgeoregister.nl/wmts?VERSION=1.0.0&request=GetCapabilities'),
#('wmts', 'Basisregistratie Grootschalige Topografie - Lijngericht (WMTS | Open)', 'http://geodata.nationaalgeoregister.nl/wmts?VERSION=1.0.0&request=GetCapabilities'),
#('wmts', 'Basisregistratie Grootschalige Topografie - Omtrekgericht (WMTS | Open)', 'http://geodata.nationaalgeoregister.nl/wmts?VERSION=1.0.0&request=GetCapabilities'),
#('wmts', 'Basisregistratie Grootschalige Topografie - Standaard (WMTS | Open)', 'http://geodata.nationaalgeoregister.nl/wmts?VERSION=1.0.0&request=GetCapabilities'),

# GESLOTEN
#('wms', 'Asbest scholenkaart (WMS | PDOK Basis)', 'http://geodata.nationaalgeoregister.nl/asbestscholenkaart/wms?SERVICE=WMS&request=GetCapabilities'),
# GESLOTEN
Expand All @@ -217,11 +228,11 @@ def handleWMS(wmscapsurl):
('wfs', 'AHN2 (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/ahn2/wfs?version=1.0.0&request=GetCapabilities') ,
('wcs', 'AHN2 (WCS | Open)', 'http://geodata.nationaalgeoregister.nl/ahn2/wcs?request=getcapabilities') ,
# https//www.pdok.nl/nl/producten/pdok-services/overzicht-urls/b
('wfs', 'BAG (tijdelijk) (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bagviewer/wfs?request=getcapabilities') ,
('wms', 'BAG (tijdelijk) (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bagviewer/wms?request=getcapabilities') ,
('wfs', 'BAG (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bagviewer/wfs?request=getcapabilities') ,
('wms', 'BAG (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bagviewer/wms?request=getcapabilities') ,
('wfs', 'BBG 2008 (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2008/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'BBG 2008 (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2008/wms?request=getcapabilities') ,
('wfs', 'Bekendmakingen (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/pdok/wfs?version=1.0.0&request=GetCapabilities') ,
('wfs', 'Bekendmakingen (WFS | Open)', 'http://geozet.koop.overheid.nl/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'Beschermde natuurmonumenten (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/beschermdenatuurmonumenten/ows?service=wms&request=getcapabilities') ,
('wfs', 'Beschermde natuurmonumenten (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/beschermdenatuurmonumenten/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'Bestuurlijke grenzen (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wms?&Request=getcapabilities') ,
Expand All @@ -231,8 +242,14 @@ def handleWMS(wmscapsurl):
#zit in algemene WMTS Caps ('wmts', 'BRP Gewaspercelen (WMTS | Open) ', 'http://geodata.nationaalgeoregister.nl/wmts/brtachtergrondkaart?VERSION=1.0.0&request=GetCapabilities') ,
#zit in algemene WMTS Caps ('wmts', 'BRT achtergrondkaart (WMTS | Open) ', 'http://geodata.nationaalgeoregister.nl/wmts/brtachtergrondkaart?VERSION=1.0.0&request=GetCapabilities') ,
# https//www.pdok.nl/nl/producten/pdok-services/overzicht-urls/c
('wms', 'CBS Bestand Bodemgebruik 2008 (BBG 2008) (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2008/wms?request=getcapabilities') ,
('wfs', 'CBS Bestand Bodemgebruik 2008 (BBG 2008) (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2008/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'CBS Bestand Bodemgebruik 2010 (BBG 2010) (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2010/wms?service=wms&request=getcapabilities') ,
('wfs', 'CBS Bestand Bodemgebruik 2010 (BBG 2010) (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2010/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'CBS Bevolkingskernen 2008 (WMS | Open) ', 'http://geodata.nationaalgeoregister.nl/bevolkingskernen2008/wms?request=getcapabilities') ,
('wfs', 'CBS Bevolkingskernen 2008 (WFS | Open) ', 'http://geodata.nationaalgeoregister.nl/bevolkingskernen2008/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'CBS Bevolkingskernen 2011 (WMS | Open) ', 'http://geodata.nationaalgeoregister.nl/bevolkingskernen2011/wms?request=getcapabilities') ,
('wfs', 'CBS Bevolkingskernen 2011 (WFS | Open) ', 'http://geodata.nationaalgeoregister.nl/bevolkingskernen2011/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'CBS Provincies (WMS | Open)' , 'http://geodata.nationaalgeoregister.nl/cbsprovincies/wms?request=GetCapabilities') ,
('wfs', 'CBS Provincies (WFS | Open)' , 'http://geodata.nationaalgeoregister.nl/cbsprovincies/wfs?request=GetCapabilities') ,
('wms', 'CBS Vierkantstatistieken 100m (WMS | Open) ', 'http://geodata.nationaalgeoregister.nl/cbsvierkanten100m/wms?request=GetCapabilities') ,
Expand All @@ -247,6 +264,8 @@ def handleWMS(wmscapsurl):
('wfs', 'CBS Wijken en Buurten 2011 (WFS | Open) ', 'http://geodata.nationaalgeoregister.nl/wijkenbuurten2011/wfs?version=1.0.0&request=getcapabilities') ,
('wms', 'CBS Wijken en Buurten 2012 (WMS | Open) ', 'http://geodata.nationaalgeoregister.nl/wijkenbuurten2012/wms?request=getcapabilities') ,
('wfs', 'CBS Wijken en Buurten 2012 (WFS | Open) ', 'http://geodata.nationaalgeoregister.nl/wijkenbuurten2012/wfs?version=1.0.0&request=getcapabilities') ,
('wms', 'CBS Wijken en Buurten 2013 (WMS | Open) ', 'http://geodata.nationaalgeoregister.nl/wijkenbuurten2013/wms?request=getcapabilities') ,
('wfs', 'CBS Wijken en Buurten 2013 (WFS | Open) ', 'http://geodata.nationaalgeoregister.nl/wijkenbuurten2013/wfs?version=1.0.0&request=getcapabilities') ,
('wms', 'CultGIS (WMS | Open) ', 'http://geodata.nationaalgeoregister.nl/cultgis/wms?SERVICE=WMS&request=GetCapabilities') ,
('wfs', 'CultGIS (WFS | Open) ', 'http://geodata.nationaalgeoregister.nl/cultgis/wfs?version=1.0.0&request=GetCapabilities') ,
# https//www.pdok.nl/nl/producten/pdok-services/overzicht-urls/d
Expand Down Expand Up @@ -356,14 +375,20 @@ def handleWMS(wmscapsurl):
('wms', 'Wetlands (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/wetlands/ows?service=wms&request=getcapabilities'),
('wfs', 'Wetlands (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/wetlands/wfs?version=1.0.0&request=GetCapabilities'),
('wms', 'WKPB (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/wkpb/wms?request=GetCapabilities'),
# https://www.pdok.nl/nl/producten/pdok-services/overzicht-urls/z
('wms', 'Zeegraskartering (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/zeegraskartering/wms?request=GetCapabilities'),
('wfs', 'Zeegraskartering (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilities'),
]

# testing
#services = [ ('wcs', 'ff', 'ff') ]

#services = [
#('wfs', 'AAN (WMTS | Open)', 'http://geodata.nationaalgeoregister.nl/nok2013/wfs?version=1.0.0&request=GetCapabilities') ,
#]
sservices = [
('wms', 'CBS Bestand Bodemgebruik 2008 (BBG 2008) (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2008/wms?request=getcapabilities') ,
('wfs', 'CBS Bestand Bodemgebruik 2008 (BBG 2008) (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2008/wfs?version=1.0.0&request=GetCapabilities') ,
('wms', 'CBS Bestand Bodemgebruik 2010 (BBG 2010) (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2010/wms?service=wms&request=getcapabilities') ,
('wfs', 'CBS Bestand Bodemgebruik 2010 (BBG 2010) (WFS | Open)', 'http://geodata.nationaalgeoregister.nl/bestandbodemgebruik2010/wfs?version=1.0.0&request=GetCapabilities') ,
]

#services = [
# GESLOTEN
Expand All @@ -384,10 +409,12 @@ def handleWMS(wmscapsurl):
#('wms', 'AAN (WMS | Open)', 'http://geodata.nationaalgeoregister.nl/aan/wms?request=GetCapabilities') ,
#]


firstOne = True
print '{"services":[',

for (stype, title, url) in services:
#print '\n --> %s'%url
if stype == 'wms':
handleWMS(url)
elif stype == 'wmts':
Expand Down
47 changes: 34 additions & 13 deletions pdokservicesplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@
import resources_rc
# Import the code for the dialog
from pdokservicesplugindialog import PdokServicesPluginDialog
#from pdokservicesplugindockwidget import Ui_DockWidget
from pdokservicesplugindialog import PdokServicesPluginDockWidget
from xml.dom.minidom import parse
import pdokgeocoder

class PdokServicesPlugin:

def __init__(self, iface):
self.docked = True
# Save reference to the QGIS interface
self.iface = iface
# Create the dialog and keep reference
self.dlg = PdokServicesPluginDialog()
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dlg)
if self.docked:
self.dlg = PdokServicesPluginDockWidget()
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dlg)
else:
self.dlg = PdokServicesPluginDialog()
# initialize plugin directory
self.plugin_dir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/pdokservicesplugin"
# initialize locale
Expand All @@ -80,8 +84,10 @@ def initGui(self):
self.action = QAction(QIcon(":/plugins/pdokservicesplugin/icon.png"), \
u"Pdok Services Plugin", self.iface.mainWindow())
# connect the action to the run method
# QObject.connect(self.action, SIGNAL("triggered()"), self.run)
QObject.connect(self.action, SIGNAL("triggered()"), self.showAndRaise)
if self.docked:
QObject.connect(self.action, SIGNAL("triggered()"), self.showAndRaise)
else:
QObject.connect(self.action, SIGNAL("triggered()"), self.run)

# Add toolbar button and menu item
#self.iface.addToolBarIcon(self.action)
Expand Down Expand Up @@ -110,7 +116,7 @@ def initGui(self):

self.dlg.geocoderSearchBtn.clicked.connect(self.searchAddress)
self.dlg.geocoderSearch.returnPressed.connect(self.searchAddress)
self.dlg.geocoderSearch.setPlaceholderText("PDOK Geocoder zoek")
self.dlg.geocoderSearch.setPlaceholderText("PDOK Geocoder zoek, bv postcode of postcode huisnummer")

self.dlg.geocoderResultSearch.textChanged.connect(self.filterGeocoderResult)
self.dlg.geocoderResultSearch.setPlaceholderText("een of meer zoekwoorden uit resultaat")
Expand Down Expand Up @@ -140,7 +146,8 @@ def showService(self, selectedIndexes):
self.currentLayer = None
self.dlg.ui.layerInfo.setHtml('')
return
self.dlg.servicesView.scrollTo(self.dlg.servicesView.selectedIndexes()[1])
# needed to scroll To the selected row incase of using the keyboard / arrows
self.dlg.servicesView.scrollTo(self.dlg.servicesView.selectedIndexes()[0])
# itemType holds the data (== column 1)
self.currentLayer = self.dlg.servicesView.selectedIndexes()[1].data(Qt.UserRole)
if isinstance(self.currentLayer, QVariant):
Expand All @@ -154,6 +161,10 @@ def showService(self, selectedIndexes):
self.currentLayer = currentLayer
url = self.currentLayer['url']
title = self.currentLayer['title']
style = ''
if self.currentLayer.has_key('style'):
style = self.currentLayer['style']
title = title + ' [' + style + ']'
servicetitle = self.currentLayer['servicetitle']
layername = self.currentLayer['layers']
abstract = self.currentLayer['abstract']
Expand All @@ -166,7 +177,7 @@ def showService(self, selectedIndexes):
maxscale = "max. schaal 1:"+self.currentLayer['maxscale']
self.dlg.ui.layerInfo.setText('')
self.dlg.ui.btnLoadLayer.setEnabled(True)
self.dlg.ui.layerInfo.setHtml('<h4>%s</h4><h3>%s</h3><lu><li>%s</li><li>&nbsp;</li><li>%s</li><li>%s</li><li>%s</li><li>%s</li><li>%s</li></lu>' % (servicetitle, title, abstract, stype, url, layername, minscale, maxscale))
self.dlg.ui.layerInfo.setHtml('<h4>%s</h4><h3>%s</h3><lu><li>%s</li><li>&nbsp;</li><li>%s</li><li>%s</li><li>%s</li><li>%s</li><li>%s</li><li>%s</li></lu>' % (servicetitle, title, abstract, stype, url, layername, style, minscale, maxscale))

def loadService(self):
if self.currentLayer == None:
Expand All @@ -179,6 +190,11 @@ def loadService(self):
if query != None and query != '':
url +=('?'+urllib.quote_plus(query))
title = self.currentLayer['title']
if self.currentLayer.has_key('style'):
style = self.currentLayer['style']
title = title + ' [' + style + ']'
else:
style = '' # == default for this service
layers = self.currentLayer['layers']
# mmm, tricky: we take the first one while we can actually want png/gif or jpeg
if servicetype=="wms":
Expand All @@ -191,12 +207,12 @@ def loadService(self):
title, # name for layer (as seen in QGIS)
"wms", # dataprovider key
[layers], # array of layername(s) for provider (id's)
[""], # array of stylename(s)
[""], # array of stylename(s) NOTE: ignoring styles here!!!
imgformat, # image format searchstring
"EPSG:28992") # crs code searchstring
else:
# qgis > 1.8
uri = "crs=EPSG:28992&layers="+layers+"&styles=&format="+imgformat+"&url="+url;
uri = "crs=EPSG:28992&layers="+layers+"&styles="+style+"&format="+imgformat+"&url="+url;
self.iface.addRasterLayer(uri, title, "wms")
elif servicetype=="wmts":
if QGis.QGIS_VERSION_INT < 10900:
Expand Down Expand Up @@ -273,7 +289,11 @@ def addSourceRow(self, serviceLayer):
# service layer = a dict/object with all props of the layer
itemType.setData( serviceLayer, Qt.UserRole )
itemType.setToolTip("%s - %s" % (serviceLayer["type"].upper() ,serviceLayer["title"] ))
itemLayername = QStandardItem("%s" % (serviceLayer["title"]))
# only wms services have styles (sometimes)
if serviceLayer.has_key('style'):
itemLayername = QStandardItem("%s [%s]" % (serviceLayer["title"], serviceLayer["style"]) )
else:
itemLayername = QStandardItem("%s" % (serviceLayer["title"]))
itemLayername.setToolTip("%s - %s" % (serviceLayer["type"].upper() ,serviceLayer["servicetitle"] ))
itemServicetitle = QStandardItem("%s" % (serviceLayer["servicetitle"]))
itemServicetitle.setToolTip("%s - %s" % (serviceLayer["type"].upper() ,serviceLayer["title"] ))
Expand Down Expand Up @@ -334,12 +354,13 @@ def run(self):

self.sourceModel.setHeaderData(2, Qt.Horizontal, "Service")
self.sourceModel.setHeaderData(1, Qt.Horizontal, "Type")
self.sourceModel.setHeaderData(0, Qt.Horizontal, "Laagnaam")
self.sourceModel.setHeaderData(0, Qt.Horizontal, "Laagnaam [style]")
self.sourceModel.horizontalHeaderItem(2).setTextAlignment(Qt.AlignLeft)
self.sourceModel.horizontalHeaderItem(1).setTextAlignment(Qt.AlignLeft)
self.sourceModel.horizontalHeaderItem(0).setTextAlignment(Qt.AlignLeft)
#self.dlg.servicesView.verticalHeader().hide()
self.dlg.servicesView.resizeColumnsToContents()
#self.dlg.servicesView.resizeColumnsToContents()
self.dlg.servicesView.setColumnWidth(0, 300) # set name to 300px (there are some huge layernames)
self.dlg.servicesView.horizontalHeader().setStretchLastSection(True)
# show the dialog
self.dlg.show()
Expand Down
Loading

0 comments on commit da662ef

Please sign in to comment.