See the Dutch website for more info on the programme.
All presentations will be in Dutch. Please have a look at the Dutch version of this page to see more…
For those interested in dutch OpenData: our national OpenData service PDOK has a Solr based geocoding service available.
Since this week it is possible to search for ‘parcel’ codes to find cadastral parcels, but also to search on so called ‘hectometer-paaltjes': the little green number signs you see when you drive the dutch highways.
So in QGIS with the ‘PDOK services plugin’ you can use different filters to search for such objects.
Below a screenie with both a search and one of the reference maps from PDOK:
Via twitter: AmsterdamTimeMachine.nl.
Jan Hartman’s and WebMappers hard work of georeferencing a set of Old Amsterdam maps: http://amsterdamtimemachine.nl.
6 XYZ-Map services with maps old as 1625 to have a look into history, off course also to be loaded in QGIS
Wanna see ‘the red light district’ in 1625?
Or see Dutch 17th century glory on a map (well, 135 degrees rotated ):
Or see that there was also a ‘Waag’ (“weigh house”) on Dam Square?
The zip contains a .qgs file which you can load as project with both QGIS 2.18 and QGIS 3.x NOW. But also a file ‘amsterdamtimemachine.nl.xml’ which you can load as a set of XYZ-services IF you have a QGIS newer then 3.1 (so you either run a nighly, or wait for 3.2 to come out)..
What is a Locator (plugin)
Some months ago, Nyall Dawson silently dropped a nice widget into the lower left corner of your QGIS screen:
People familiar with QtCreator (the Qt-development environment) should recognize it as a QtCreator Locator look-a-like: a way to (very) quickly search in your project for words, classes, bookmarks, help topics, files etc etc.. It is actually a multipurpose tool to ‘quickly’ search for something, or ‘start’ something. See the original Qt documentation.
Nyall had the brilliant idea to add something like that to QGIS too… and he did. In the code it is called a QgsLocator and it can load/register all kind of so called ‘QgsLocatorFilters’.
Out of the box by starting to type in the search field, you search for: Actions, Processing Algorithms, Spatial Bookmarks, Active Layer Features, Project Layers and Project Layouts.
Just start to type ‘bel…’ and you will see there are a lot of buff(er) related Processing Algorithms available.
Then by clicking on one of the algorithms, you actually start it in processing, super fast, super cool.
Or if you have a world map loaded like in the image and click on ‘Belgium’ you zoom to that ‘feature’.
BUT the coolest thing is, that as a (python) developer you can ‘easily’ implement such a QgsLocatorFilter yourself.
The thing that came up with me first is: ‘Wow, what about using this for a fast searching geocoder…’
So, let’s try…
How to create one
YOUR implementation of this piece of code is actually the work horse of your Locator Filter. It will take the user input, do something with it (in our case: throw it to an Online Geocoder Api), get back the results, create ‘QgsLocatorResult’s from that, which then will be shown to the user AND describe what happens when a user double clicks on the result.
Off course you need some ‘glue’ to put it in QGIS after this:
– a plugin which you can put in the QGIS plugin repository so a user can download your filter
– the ‘registering’ of your filter to QGIS so it is ‘picked up’ and shown in the Locator search widget
(see the nominatim locator plugin code)
Some geocoders (notably the Google one), need a personal api key to work.
When you left click on the little magnifier-icon a menu will appear in which you can select ‘Configure’
That will bring you to the Locator tab in the Options dialog:
There you can choose to always enable a Locator Filter, or fully disable it.
As you can see in the right, there is also an (now inactive) configure button. If your locator returns True as a result of calling hasConfigWidget(), then that button becomes active and you can for example implement your own Geocoder configuration window.
An example geocoder: Nominatim_Locator_Plugin
Nominatim (from the Latin, ‘by name’) is “a tool to search OSM data by name and address and to generate synthetic addresses of OSM points (reverse geocoding)”. You can read the OSM wiki or the OSM api information.
I have created a plugin called the ‘Nominatim_Locator_Plugin’ which implements this QgsLocatorFilter interface. Install it in QGIS by enabling the experimental plugins, search for ‘Nominatim’ and install the ‘Nominatim Locator Filter’ plugin. Or … have a look into the python code.
As you can see in the ‘fetchResults’ we wait until we have at least 2 characters, and then we start searching.
One special case with the Nominatim service is that it is a free service, but you are NOT allowed to use it as a ‘suggest’ service. That is: only search a full place name. To handle this, I added the gesture that you have to finish your place- or address-term with a ‘space’, and THEN the request is fired.
The cool thing with Nominatim and OpenStreetMap is that it handles all kind of languages. If you type the dutch word of Statue of Liberty: ‘vrijheidsbeeld’, it will just show up:
Some technical details
Which methods you have to define you can find in qgslocatorfilter.h.
One thing to be aware of is that the searching/retrieving/showing of the results is all done in multiple threads! I thought to be clever and tried to use asynchronous GET requests to the services, but ended up fighting ‘thread troubles’. So my tip: just use synchronous HTTP for your requests.
Which brings me to which library to use for the HTTP traffic. In QGIS 2 plugins you see people use the Requests-module pretty often, or plain httplib2 or implement their own NetworkAccessManagers.
Disadvantage of using external modules or home-brew solutions is that often QGIS-configurations like Proxy Settings or Network Timeout values are ignored…
For my experiments I used this module: networkaccessmanager.py.
The nice thing is that it tries to be a thin Python wrapper around QGIS’s own QgsNetworkAccessManager (which in this case is actually a thin wrapper around Qt’s QnetworkAccessManager).
It uses the Proxy settings that a User configured and if needed it can use QGIS’s authorisation module so the HTTP traffix is authenticated against the users own systems.
This boundless solution is a great one, but it would be even cooler if the (rather naive) QgsNetworkAccessManager Cpp implementation could be extended to be more Python/User friendly. So it is easier to handle redirects, timouts, headers etc. And like in the boundless module you could choose between synchronous (blocking) or asynchronous (non-blocking) calls.
I created a QEP (QGIS Enhancement Proposal) for it, and hope others are interested and chime in.
Off course FOSS is never ‘finished’, as in the good sense of being ‘never finished’
New ideas always pop up when you are coding:
– use a Nominatim configuration screen, to for example only search for certain osm tags (what about: “find all pubs in current mapcanvas view”, best to be done with a map of your current surroundings )
– use the accept-language option of Nominatim (use current QGIS language) in the query, so you can use ‘Эйфелева башня’ or ‘eiffeltoren’ and get your results back in your preferred language.
– a Locator for Google Maps api searching. You will need a key for that one, so create a configuration Window for it too (actually: done )
– the PDOK locatieserver interface, our national geocoder service (actually: done )
– YOUR national geocoder service
So, I hope we get you interested in Locators and will see your plugins appear at plugins.qgis.org
Ah, and some last tips for Python QGIS / PyQGIS programmers:
This post is to announce the availability of a new version of the PdokServicePlugin.
Unless a heavy user of Dutch Public Datasources (WMS, WFS, WCS), this is probably mostly interesting for Dutchies.
But if you want to know how many kilometers somebody is living from the nearest Fire Department Station:
Imagine you have a list of different features at locations and you want to display those on a map like this:
The QGIS diagrams expect a column for each pie or bar, but our features are all listed in one column:
And our geometry is stored in a good old shapefile:
So, we can use the ‘code’ field for joining as well as for grouping the items to one single row per location.
Since QGIS vector joins cannot handle 1:n relations, we are going to use a virtual layer for this. In a virtual layer you can use all sql that sqlite supports, including JOIN and GROUP BY statements.
So we create a new virtual layer ‘cities_grouped’ with this sql:
SELECT c.name, c.code, group_concat(amenity) AS amenities, CASE WHEN INSTR(group_concat(amenity),'university') > 0 THEN 1 ELSE 0 END AS university, CASE WHEN INSTR(group_concat(amenity),'airport') > 0 THEN 1 ELSE 0 END AS airport, CASE WHEN INSTR(group_concat(amenity),'station') > 0 THEN 1 ELSE 0 END AS station, CASE WHEN INSTR(group_concat(amenity),'harbor') > 0 THEN 1 ELSE 0 END AS harbor, count(*) AS cnt, c.geometry FROM amenities a LEFT JOIN cities c ON a.code = c.code GROUP BY c.code, c.geometry
The attribute table of this new virtual layer looks like this:
We can use diagrams as symbology for this new layer, adding in all the new columns university, airport, station and harbor. I used the count column (cnt) for sizing the diagram and offsetting the labels.
Hope this helps you, and if you know an easier way for doing this please let me know!