Some of the outputs from my Data Driven Cartography workshop at the 2nd OSGeo Ireland conference.
Some of the outputs from my Data Driven Cartography workshop at the 2nd OSGeo Ireland conference.
I created a couple of OSM visualisations for my talk at the OSGeo Ireland conference.
These are pretty easy to make, but take a fair bit of time. I did mine for Ireland, but should work with any part of the world.
This is the trickiest part, installing osmium-tools: here.
An OSM full history export. The best source for these is GEOFABRIK.
Due to GDPR, you will have to log in with an OSM id to download the full history extracts. User ID’s are personal data.
The workflow is pretty simple. Osmium-tools provides pretty easy API access to the history files, where you can provide a data, and it will extract what OSM was like at that date. We simply need to loop through the desired dates we want to extract, and pipe the results into a workflow that loads the data into PostgreSQL. The final step is simply rendering in QGIS using the time manager plugin.
The tables in the database will be:
Each feature will be tagged with the date it is associated with.
To visualise the data in QGIS we use simply use the excellent time manager plugin, filtering on the load_date field and with a monthly interval.
Last week I was invited to give a workshop at the Second Irish OSGeo Conference in Portlaoise. The event was a great success with a attendees from across the OSGeo space, from academics to startups.
I also volunteered to give a talk on OpenStreetMap (OSM) in Ireland. Since we are currently in the process of setting up an official chapter of OSM in Ireland. Check out OpenStreetmaMap.ie if you want to help.
Check out my full talk: here
But some of the visuals are more interesting than the talk as a whole.
To start out, the first edits in Ireland.
The first line:
Located in Banbridge, in Northern Ireland between Newry and Belfast:
Clearly St. Stephens Green, a great park in Dublin:
Then a look at the full history of roads in Ireland on OpenStreetMap:
A large part of the history of OpenStreetMap in Ireland is the townlands project. Townlands in Ireland are small divisions of land, often used in addressing for example. Your address could be: Mr. O’Brien, Blue house, Tawny (the townland), Donegal. The postman knows where you are.
There are over 61,000 townlands in Ireland. Traced manually from 650+ out of copyright OSi maps from Trinity College. Check out Townlands.ie for more info.
The project ran from 2012 to 2017 and the progress is clear when charting the history of boundaries in OpenStreetMap in Ireland:
And since the conference was held in Portlaoise, here is how it looks over time in OSM:
For the script to generate these histories see: Creating OpenStreetMap History Visualisations
Runs through each geometry that you want to select from and tests if the centroid or the point of surface central point falls within the selecting geometry. If the central point falls within the selecting polygon, it is usually mostly inside the selecting geometry.
Or selecting based on percentage overlap. By default dissolving the selecting features first.
Useful if you are splitting up a polygon layer based on a polygon coverage layer, as each polygon will only end up in one of the selecting polygon areas. Unlike with an Intersects query which would return the geometry twice if it is on the border one on each side, or a Within query, which would not return the geometry at all. Very useful if your selection and selecting geometries have similar boundaries.
Version 0.4 brings a couple of new features to the Select Within plugin.
Most importantly it now supports mostly within and percentage within selections.
Also introduced is Pole of Inaccessibility within selections. As implemented in the QGIS core with the Polylabel algorithm: https://github.com/mapbox/polylabel
Point within selection examples. Centroid (red), Point on Surface (green), and Pole of Inaccessibility (blue):
Point on Surface within:
Pole of Inaccessibility within (1.0 tolerance):
GitHub Code Base
Issues and bug tracker:
Centroid Within Selection in QGIS
After about 3 years of existing. I am releasing version 1 of the Multi Ring Buffer Plugin.
With version 1 comes a few new features:
Non-doughnut buffer (regular):
Works either in a sequential manner by buffering the resulting buffer and differencing the previous buffer, or a central manner by buffering the original feature with different distances. Also by default the buffer dissolves the features before buffering.
Dissolving makes adjacent features behave in a better manner without overlapping buffers. The QGIS buffer feature has the logic behind this.
Issues and bug tracker:
I have two plugins in the QGIS plugin repository, and with the release of QGIS 3 looming it was time to upgrade them for QGIS 3.
There is a short guide by the QGIS dev team that is a good starting point at:
But I had not done any development on these plugins for a while so a more step by step guide was useful, so hopefully, write the guide for the first plugin and follow it step by step for the second.
I am working on Windows, with OSGeo4W.
Before we start we will need to insure a couple of extras are installed through the OSGeo4w Installer:
Assuming GitHUB is the repo.
In git shell:
git clone https://github.com/HeikkiVesanto/QGIS_Multi_Ring_Buffer.git
There is a conversion script for QGIS plugins provided by the QGIS devs in the main repo.
The qgis2to3 packages can be found on pip now:
We can download just the scripts folder using the following link:
Extract that into a location of your choice.
Then we can run the 2to3 script from the OSGeo4W console (cd to the folder you extracted the script to):
python 2to3 C:\path_to_plugin\QGIS_Multi_Ring_Buffer
This will print out changes that need to be made to convert from QGIS2 to QGIS3.
My first run resulted in many lines of:
RefactoringTool: Line 31: could not convert: from PyQt4.QtCore import * RefactoringTool: Cannot handle star imports.
So my plugins line of:
from PyQt4.QtCore import *
Was impossible to convert with the tool, since I was not 100% sure what I needed from the QtCore library (I was young when I wrote the plugin). I commented out the line for the plugin in QGIS 2.8, booted up QGIS 2.8 and tried running the plugin.
So python errors:
NameError: global name ‘QVariant’ is not defined
NameError: global name ‘Qt’ is not defined
Later. I ended up expanding my other import from QtCore to:
from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication, QVariant, Qt
Running the 2to3 script again looked ok, with a number of changes required. These changes can be applied with –w flag:
python 2to3 C:\path_to_plugin\QGIS_Multi_Ring_Buffer -w
For the next step I booted up my favourite IDE PyCharm. I created a bat file that launched PyCharm with the QGIS dev environmental variables. So copying the “python-qgis-dev.bat” file from:
I changed the final line of:
start /d "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.1\bin\" pycharm64.exe
Then from File> Settings> Project:> Project Interpreter> Set to “C:\OSGeo4W64\apps\Python36\python.exe”
It takes a while to update the interpreter.
I only had 2 errors, both for:
There is a list of API breaks between QGIS 2 and QGIS 3 at:
Looks like QgsMapLayerRegistry was moved to QgsProject. So I edit it to:
Then we can edit the metadata.txt to QGIS 3:
And increase the version number.
Then we need to recompile the icon and ui for Python3 and QT5.
I was struggling a bit with the environmental variables to get it working, and ended up using a great batch script form StackExchange:
@ECHO OFF set OSGEO4W_ROOT=C:\OSGeo4W64 set PATH=%OSGEO4W_ROOT%\bin;%PATH% set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis\bin @echo off call "%OSGEO4W_ROOT%\bin\o4w_env.bat" call "%OSGEO4W_ROOT%\bin\qt5_env.bat" call "%OSGEO4W_ROOT%\bin\py3_env.bat" @echo off path %OSGEO4W_ROOT%\apps\qgis-dev\bin;%OSGEO4W_ROOT%\apps\grass\grass-7.2.2\lib;%OSGEO4W_ROOT%\apps\grass\grass-7.2.2\bin;%PATH% cd /d %~dp0 @ECHO ON ::Ui Compilation call pyuic5 multi_ring_buffer_dialog_base.ui -o multi_ring_buffer_dialog_base.py ::Resources call pyrcc5 resources.qrc -o resources_rc.py @ECHO OFF GOTO END :ERROR echo "Failed!" set ERRORLEVEL=%ERRORLEVEL% pause :END @ECHO ON
So create the .bat file and run it in the folder of you plugin (editing where needed). Note: Your resources_rc may be called resource_rc or something slightly different.
Move the plugin folder to:
Boot up QGIS2.99/3.
I had a few more issues.
It seems QGIS 3 deals with the icon slightly differently.
icon_rc.py is no longer needed, and it seems was not used on my other plugin either.
So I removed the reference to it in the main python script:
from . import icon_rc
I still had some errors.
AttributeError: module ‘qgis.PyQt.QtGui’ has no attribute ‘QDialog’
It seems QDialog has moved to PyQt.QtWidgets.
So in my multi_ring_buffer_dialog.py file I needed to change some lines:
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
In the two instances in that file.
Commit the changes back to the repo. Cd to the directory in git shell.
git add -A git commit –m “Updated for QGIS 3” git push
Zip the plugin up.
Upload to https://plugins.qgis.org/plugins/
Same issue with import *
1 error with QgsMapLayerRegistry
My resources_rc file was called resource_rc so the batch script needed to be edited to:
call pyrcc5 resources.qrc -o resource_rc.py
Same issues with QtGui.QDialog
Now time for some improvements.
Finland is 100 years old today.
It has been a rich history. It is a young country, with myself being alive for almost a third of it.
In honour of #Finland100. Here is 90 years of Finnish hockey champions:
Starting with the 1927-1928 season with six teams the Finnish championship started with the SM-Sarja.
“S” for Suomen meaning Finnish.
“M” for Mestaruus meaning Championship
“Sarja” meaning series
The first year consisted of the following teams:
Viipurin Reipas – Viipuri Swift
HIFK – Sporting Society Comrades, Helsinki – Future 7 time champions
HJK – Helsinki Football Club – Future 3 time champions
KIF – Kruununhaka Sports Club (Helsinki) – Future 3 time champions
Tapa – Tampere Ballers – Future champions
HPS – Helsinki Ball Club
With ice hockey still being a very new sport in 1927 the victory went to Viipurin Reipas, primarily a football and bandy club. Located in Viipuri, a city which was lost to Russia after the Winter War.
At this stage ice hockey was purely an amateur sport, with sports clubs taking part in ice hockey as part of a larger program. Most often football in the summer and ice hockey in the winter, but also combined with other sports.
After Viipuri the championship went to Helsinki, with their football club. While no longer active in ice hockey they are still active in the highest level of Finnish football.
The Helsinki – Tampere fight for hockey championship was established early, with 1930-1930 seeing a standing of:
The next few years also saw the Helsinki Figure Skating Club (HSK) win the championship, three times in total.
1939 to 1945 were crucial years for Finnish history. The war with Russia was one for the survival of Finland as a whole.
Some sacrifices had to be made.
The 1939-1940 season was completely called of for the Winter War. During which the captain of Tampere Ilves (3 time champions at the time, and 16 time champions all time) Jussi Tiitola was killed, among others.
The 1940–1941 season was played in between hostilities as an 8 team series.
1941–1942 was cancelled for the Continuation War.
1942–1943 was played as an 8 team series. With KIF winning their third championship in a row, discluding pauses for war.
The 1943–1944 season was started but a mass bombing of the Helsinki Kaisaniemi stadium called the season short. It was agreed that if Tampere Ilves (who had 0 losses at the time) could beat Tarmo and KIF they would be awarded the championship. They beat Tarmo, but unfortunately the transport connections between Tampere and Helsinki were bombed the day before the Ilves – KIF match. Thus the championship was never awarded.
The after war period saw a domination from the Tampere. With 18 championships in 24 years. With Ilves winning 11 and TBJ/Tappara winning 6 and KOO-VEE 1.
But notably champions from other cities aside from Helsinki and Tampere emerged.
Like TPS from Turku first champions in 1956, but future 11 time champions.
Tarmo (no longer active) from Hämeenlinna winning two in a row.
Lukko from Rauma winning their only championship so far in 1963, coming close in the future; with silver: 1961, 1966, 1988, and bronze: 1965, 1969, 1994, 1996, 2011, 2014.
And Pori, with RU-38 in 1967, Porin Karhut in 1965, and together as Porin Ässät (Pori Aces) in 1971.
While the SM-Series was mainly amateur it changed into the SM-Liiga in 1975, bringing with it a move to a professional sport.
This also introduced the playoffs to determine the overall champions. Also a relegation system was introduced, with teams coming last in the SM-Liiga facing relegation to a lower division and giving lower teams and opportunity for promotion.
The first championship outside of Southern Finland went to Oulu in 1981.
1985 was the latest championship for Ilves, their 16th in total.
Kärpät won again in 2004, and 2005 with back to back championships. With two more back to back championships to come.
With JYP from Jyväskylä winning in 2008 the total of cities with victories comes to 9.
The Ilves crown of 16 championships was met by Tappara (formerly TBK) in 2016, and beat in 2017 with back-to-back victories.
Here’s to another 100 years and more of hockey in Finland.
UK postcodes are broken down/divided into 4 levels: Areas, Districts, Sectors, and Units.
For G12 8QH the breakdown is:
Area – G
District – G12
Sector – G12 8
Unit – G12 8QH
See my previous post:
UK Postcode Format Breakdown/
This is just a note of the RegEX strings to extract these, which can be used in QGIS, or PostgreSQL. These are a bit complex for most datasets, but should work independent on whether spaces and how many were used between the in and out codes. Should also work for London postcodes.
regexp_substr("postcode" , '(^[a-zA-Z][a-zA-Z]?)')
UK Postcode Area
This is actually pretty hard to do.
UK Postcode District
Sector: G12 8
regexp_substr("postcode" , '(^[a-zA-Z]+\\d\\d?[a-zA-Z]?\\s*\\d+)')
UK Postcode Sector
Unit: G12 8QH
I’ll let you figure this one out.
Ireland is bidding for the 2023 Rugby World Cup.
They have submitted 12 stadiums in their bid. They cover all four provinces and the breadth of the island.
Ranging from Europe’s third biggest stadium Croke Park in Dublin. Welcoming 1.5 million fans every year. Packing in 82,300 dedicated fans every year for the GAA (Gaelic Athletic Association) Hurling and Gaelic Football finals. An integral part of Ireland’s history through sweat, blood, and identity.
The Aviva Stadium in Dublin, the worlds oldest international rugby stadium. Venue for the 2011 Europa League Final between Portuguese sides Porto and Braga.
Ravenhill Stadium in Belfast. Home of Ulster Rugby and in 1991 venue for Japan’s first match victory in a Rugby World Cup.
Thomond Park in Limerick. Heart of the community and host to a 12 year unbeaten run for Munster rugby. Winner of the ‘Best Rugby Stadium in the World’ vote in 2013.
Storm Harvey produced some extremely high levels of rainfall. Some areas of Texas received over 50 inches of rain over 9 days.
The National Oceanic and Atmospheric Administration (NOAA) provided some really great real time datasets to map the progress of the storm.
From these we can produce a GIF of hourly precipitation:
And total precipitation:
Particularly the hurricane path was possible to create in QGIS using the Atlas Generator, and the excellent new:ish geometry generator. This can be found as an option for any layers symbology, as one of the renderers.
For my map I had a non spatial table that drove my atlas. This was a log table of all of the hours of precipitation I had loaded into my database. So I looped through each entry and showed the corresponding points of hourly precipitation for the corresponding hour. I also had hurricane path data as points for every 6 hours. So I could use the geometry generator to interpolate points in between known points.
While the query ended up being pretty long it is pretty straightforward.
It only needs to be run when the hour being generated does not end with a 00, 06, 12, or 18, because those are the positions I already know.
For the rest I need to generate two points. One for the previously known point, and one for the next known point.
Then I would create a line between those two points, measure the line, and place a point on the line x times one sixth of the way for the start of the line depending on the hour from the last known point.
Overall I am very impressed and happy with the result. With a bit of data defined rotation the storm progress looks great.
line_interpolate_point( Make_line( geometry( case when right(to_string(attribute(@atlas_feature , 'id')),2) IN ('00', '06', '12', '18') then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') ) else get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') - (attribute( @atlas_feature , 'id') % 100 % 6 )) end) , geometry( case when right(to_string(attribute(@atlas_feature , 'id')),2) IN ('00', '06', '12') then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') + 6 ) when right(to_string(attribute(@atlas_feature , 'id')),2) IN ('18') then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') + 100 - 18 ) when to_int(right(to_string(attribute(@atlas_feature , 'id')),2)) > 18 then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') - ((attribute( @atlas_feature , 'id') % 100 % 6) ) + 100 - 18) else get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') - ((attribute( @atlas_feature , 'id') % 100 % 6) ) + 6) end) ), length(Make_line(geometry( case when right(to_string(attribute(@atlas_feature , 'id')),2) IN ('00', '06', '12', '18') then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') ) else get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') - (attribute( @atlas_feature , 'id') % 100 % 6 )) end ) , geometry( case when right(to_string(attribute(@atlas_feature , 'id')),2) IN ('00', '06', '12') then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') + 6 ) when right(to_string(attribute(@atlas_feature , 'id')),2) IN ('18') then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') + 100 - 18 ) when to_int(right(to_string(attribute(@atlas_feature , 'id')),2)) > 18 then get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') - ((attribute( @atlas_feature , 'id') % 100 % 6) ) + 100 - 18) else get_feature( @layer_name , 'dtg', attribute( @atlas_feature , 'id') - ((attribute( @atlas_feature , 'id') % 100 % 6) ) + 6) end))) * ((attribute( @atlas_feature , 'id') % 100 % 6) * 0.16666666666666666))