Page 1 of 72 (1421 posts)

  • talks about »


Last update:
Sun Feb 1 15:05:09 2015

A Django site.

QGIS Planet

Publishing interactive web maps using QGIS

We all know that QGIS is great for designing maps but did you know that QGIS is also great for interactive we maps? It is! Just check out qgis2leaf and qgis2threejs.

To give these two plugins a test run and try to learn some responsive web design, I developed a small concept page presenting cycle routes in 3D.

Screenshot 2015-01-31 22.20.15

Qgis2leaf makes it possible to generate Leaflet maps from QGIS layers. It provides access to different background maps and it’s easy to replace them in the final HTML file in case you need something more exotic. I also added another layer with custom popups with images but that was done manually.

Daten CC-BY-3.0: Land Kärnten -

The web maps use data CC-BY-3.0: Land Kärnten –

Qgis2threejs on the other hand creates 3D visualizations based on three.js which uses WebGL. (If you follow my blog you might remember a post a while back which showcased Qgis2threejs rendering OSM buildings.)

This is a great way to explore elevation data. I also think that the labeling capabilities add an interesting touch. Controlling the 3D environment takes some getting used to, but if you can handle Google Earth in your browser, this is no different.

Image of Heiligenblut by Angie (Self-photographed) (GFDL ( or CC BY 3.0 (, via Wikimedia Commons

Image of Heiligenblut by Angie (Self-photographed) (GFDL ( or CC BY 3.0 (, via Wikimedia Commons

How to load a QGIS project in python

Today in a project we are working on we wanted to load a QGIS project. It takes  surprisingly few lines of code to make a small standalone application that loads a project and then shows it as a map in a window like this:

QGIS project in a standalone app


Here is the code I wrote to produce this:

The main bit of magic is the QgsLayerTreeMapCanvasBridge class which will convert your project into a layer tree so that the layers appear in the canvas. If you ever need to make a standalone python application with a nice map in it, consider using the QGIS API to do it!

New addition

Stace and I would like to welcome Matilda Anne Woodrow, born 5/1/15 at 10:36am.


She is a nice way to start 2015.

After the pretty crappy year that was 2014 it was finally nice to see Matilda in the flesh. The relief of seeing her alive and well is hard to put in words after losing Ellie in 2013.

People always ask about the lack of sleep, but it feels like we have more energy now then we did before. The emotional and physical toll that the pregancy took on our family had pretty much run us into the ground and it felt like it was never ending.

The toll of the pregancy had lead me to massive lack of motivation towards QGIS and pretty much everything else in life, which isn't healthy when you have a family to look after. Pro Tip: Get help if you find yourself in this spot, it be hard to recover if you go over the edge.

Anyway. Here is to a new year. A better year.

Function editor for QGIS expressions

A new feature for QGIS 2.8 is a function editor for expressions. Being able to define your own custom functions has be possible for a while now, over a year, I even have a plugin (Expressions+) that adds some extra ones, however it wasn't easy for new users and required you to create files that lived on python path while also editing the file for QGIS so that functions got registed at start up. Way too much effort for my liking.

This feature is now exposed via the expression builder on the Function Editor tab. The function editor will create new Python files in qgis2\python\expressions and will auto load all functions defined when starting QGIS. I remember Sean Gillies saying that Python support in a field calculator should be a gateway to full Python programming, can't get any more Python then full Python modules.

The best way to show this feature is a quick video so here it is

The play button in the editor will run the current editor file in the QGIS session and register any functions it finds, it will also save the file in the expressions folder.

You can make a new file by pressing the new file button which will add the basic function template, changing the name in the combobox and hitting save will save the file.

The function editor allows you have to define reuseable functions for your QGIS. If you want to share a function you simply share the .py file from the expressions folder and give it to another user. In future versions of QGIS we might have a way to download other users functions.

Auto expanding values

You can also use the args="auto" keyword in place of the number of args which will let QGIS work it out and expand the arguments for you.

Here is an example

@qgsfunction(args="auto", group='Custom')
def myfunc(value1, value2 feature, parent):

and can be used like this:

myfunc('test1', 'test2')

QGIS will workout how many arguments your function takes based on what you have defined. Note: The last arguments should always be feature, parent, these are not included in the count.

Raising errors

If you need to report a error from a function simply use the raise method like normal in QGIS and raise an exception.

@qgsfunction(args="auto", group='Custom')
def myfunc(value1, value2 feature, parent):
    raise Expection("Hahah Nope!")

The function wrapper will catch the exception and raise it though the expression engine.

A couple of things to note

  • New functions are only saved in the expressions folder and not in the project file. If you have a project that uses one of your custom functions you will need to also share the .py file in the expressions folder.
  • The editor doesn't unregister any functions. If you define a function called test, hit play, change the name to test_2, hit play, both functions will exist until you reload QGIS.

A quick hack to select all multipart features in QGIS

Today we wanted to find all the multipart features in this layer:

The layer that needs multipart features identified

Here is a quick hack I did in QGIS to find them:

Just make sure that a vector layer is active in the layer list, paste the above code into the python console and all multipart features will be highlighted for you.

After running the above script, multipart features are hightlighted.

Etiquetas com guias em QGIS e Postgis | Labels leading lines with QGIS and Postgis

Recentemente tive necessidade de colocar etiquetas de texto em elementos com geometrias muito próximas, fazendo com que as mesmas colidissem umas com as outras.

Recently I had the need to add labels to features with very close geometries, resulting in their collision.


Controlando a posição das etiquetas através dos dados (para configurar rapidamente a camada usei o plugin “layer to labeled layer“) e usando a ferramenta do qgis para mover as etiquetas, foi relativamente fácil reposicioná-las de forma a que todas coubessem no mapa sem se sobreporem. Porém, em certos casos, tornou-se difícil perceber a que elemento cada uma correspondia.

Using data-defined override for label’s position (I have used layer to labeled layer plugin to set this really fast) and the QGIS tool to move labels, it was quite easy to relocate them to better places. However, in same cases, it was difficult to understand to which geometry they belonged.


Precisava de criar “linhas de guia” que, sempre que necessário, ligassem o elemento e a respectiva etiqueta. Conhecia a existência de outro excelente plugin, chamado “Easy Custom Labeling” do Regis Haubourg, que fazia o que eu pretendia, mas como criava um duplicado da camada original significava que a mesma não seria actualizada quando a camada original fosse editada.

I needed some kind of leading lines to connect, whenever necessary, label and feature. I knew another great plugin called “Easy Custom Labeling“, by Regis Haubourg, that did what I needed, but it would create a memory duplicate of the original layer, wish meant that any edition on the original layer wouldn’t be updated in the labels.

Uma vez que os dados estavam guardados numa base de dados PostgreSQL/Postgis, decidi criar uma consulta que me devolvesse uma camada com as linhas de guia. Usei a seguinte consulta no gestor de bases de dados:

Since the data were stored in a PostgreSQL/Postgis database, I have decided to create a query that would return a layer with leading lines. I used the followind query in DB manager:

  ST_Makeline(St_setSRID(ST_PointOnSurface(geom),27493), St_setSRID(St_Point(x_label::numeric, y_label::numeric),27493))
  x_label IS NOT NULL AND
  y_label IS NOT NULL AND
  NOT ST_Within(ST_Makeline(St_setSRID(ST_PointOnSurface(geom),27493), St_setSRID(St_Point(x_label::numeric, y_label::numeric),27493)),geom))

Esta consulta cria uma linha composta pelo centro (interno) do polígono e a coordenada do ponto para a qual a etiqueta foi movida. A última condição da cláusula WHERE garante que a linha só é criada se a coordenada da etiqueta não estiver dentro do polígono.

This query create a line by using the feature centroid as starting point and the label coordinate as end point. The last condition on the WHERE statement assures that the lines are only created for labels outside the feature.


Com a camada resultante carregada no meu projecto, basta-me mover as etiquetas e gravar a edição da camada original para que a respectiva linha de guia apareça.

With the resulting layer loaded in my project, all I need is to move my labels and save the edition (and press refresh) to show a nice leading line.


A line gradient style hack

Today’s post was motivated by a question over on gis.stackexchange, basically: How to draw a line with a gradient?

The issue we have to deal with is there is no gradient line style yet … But there are polygon gradient fills. So we can buffer the line and style the buffers. It’s a bit of an exercise in data-defined styling though:

Screenshot 2015-01-11 22.49.41

Before creating the buffer layer, we need to add the coordinates of the line start and end node to the line attributes. This is easy to do using the Field Calculator functions xat and yat, for example xat(0) for the x coordinate of the start node and yat(-1) for the y coordinate of the end node.

Screenshot 2015-01-11 22.41.37

Then we can buffer the lines and start styling the buffers. As mentioned, we’ll use the Gradient fill Symbol layer type.

Screenshot 2015-01-11 22.49.54

The interesting part happens in the Data-defined properties. The start and end colors are computed from the measurement values from_m and to_m. Next, it’s important to use the feature coordinate mode because this will ensure that the coordinate system for the color gradient is based on the feature extent (with [0,0] in the upper left corner of the feature bbox).

Once that’s set up, we can compute the gradient start and end positions based on the line start and end node locations which we added to the attribute table in the beginning. If you’re wondering why Reference point 1 y is based on to_y (y coordinate of the line end point) rather than from_y, it’s due to the difference in coordinate origins in the geometry and the color gradient coordinate space: [0,0] is the lower left corner for the geometries but the upper left corner for the color gradient.

Screenshot 2015-01-11 22.42.35

As the title suggests, this is a really hackish solution for gradient line symbols. It will only provide reasonable results for straight – or close to straight – lines. But I’m very confident that we’ll have a real gradient line style in QGIS sooner or later.

QGIS Mobile 0.2 Demo

QField (formerly known as QGIS Mobile) is a touch optimized interface for field work developed by It is with great pleasure the we want to share with you the demo video of version 0.2.

Since the project is going to be one of our core projects, we set up a dedicated page here.

The QGIS mobile 0.2 video demonstrates some basic functionality like navigation, feature identification and attribute editing.

The performance is affected by android’s video recording software. In reality animaitons look fluent and the interface feels snappy.

Demo performed on a Galaxy Note 8.0 with Android 4.4.4 (CM11).

QGIS – live layer effects Kickstarter update

Here’s another quick video demonstration of the latest developments in layer effects – effects on polygon and polyline layers, and outer glow effects:

Time is running out to fund this campaign and make this work happen… Please donate via Kickstarter!

I’ve also been asked what will happen if funding exceeds the Kickstarter goal? Well, if this happens, the extra funds will be used to add additional layer effects to QGIS. Next up will be inner glow, inner shadow and color modification effects.

Use of the Flemish geographical data portal “Geopunt” in QGIS

Geopunt website Geopunt is the central portal for geographical data of the Flemish government. Beside an online viewer, a catalogue is available from where data can be downloaded. A lot of these data are free to download (e.g. orthophotos), other data is available depending on your user profile (e.g. soil map) Download through the Geopunt4Qgis […]

Happy new year to the power of two!

For the first time we at can celebrate with 2 people, Marco Bernasocchi and Matthias Kuhn both experienced QGIS developers and holders of a Master degree in GIScience.
After having worked individually in the last years, we have realized that there is a huge potential for us to join our knowledge – because the whole is greater than the sum of its parts. This is why starting from January 1st, 2015 we are working together as LLC.

Marco is the creator of QGIS for Android, has a strong background in python and web applications development and is core committer of the the award-winning InaSafe project.

Matthias is an active QGIS core committer with a long history in developing in a wide variety of programming languages and areas from embedded systems to server services.

We both are strong believers in open source software and are convinced that developing in the public is a big win for everybody.

Among other projects, we are currently working on QGIS Mobile. A touch optimized interface for field work, based on the QGIS libraries. Make sure you keep an eye on this project as it is in its infancy but growing very fast.
If you have a use-case for it and would like to support its development don’t hesitate contacting us. We will happily provide you with a preview version.

We are are also available for helping you with any idea and project you might have and to give ad-hoc courses that cover topics related to (Q)GIS and programming.

All the best

Marco and Matthias

How to: watercolor pastel style in QGIS

Today’s post is a follow-up to a recent map experiment which I published in the QGIS Flickr group. It’s basically an inverted Stamen Toner style with an image in the map composition background instead of a solid color (similar to the approach described for vintage maps):

That’s nice but with this approach we only get to enjoy the complete design in the print composer but not in the main window. So what other options do we have? – SVG fills to the rescue!

But first we need a suitable SVG with this nice pastel style. I used Gimp to create a seamless version of the pastel image and then embedded the image in an SVG using Inkscape:


In QGIS, this SVG can now be used in any SVG fill. It’s important to set the Texture width setting to a quite high value when working with SVGs containing big textures, otherwise the images will be rendered very small and the repeating patterns will be very obvious.

Screenshot 2015-01-04 17.49.11

Once the background is in place, we can add the line work and labels. The roads are white with black outlines for bridges which – together with the Lighten blending mode – produce the desired effect:

Screenshot 2015-01-04 17.37.33

Happy new year!

Thank you for a great 2014! It’s been a pleasure to see the open source GIS community grow and experience what we can create together. It’s great to see the interest for open source GIS all over the world:

In total, this blog has been visitied from 216 countries. Most visitors came from The United States. Germany & France were not far behind.

In total, this blog has been visitied from 216 countries. Most visitors came from The United States. Germany & France were not far behind.

Since my first post in 2010, the development of this blog has exceeded all expectations I might have had by far. For 2014, the WordPress blog view counter shows a staggering 330,000 views or over 900 views per day.

In case you were wondering, the most popular posts of 2014 were:

  1. 3D Viz with QGIS & three.js
  2. A guide to GoogleMaps-like maps with OSM in QGIS
  3. A QGIS 2.2 preview
  4. Getting started writing QGIS 2.x plugins
  5. and Toner-lite styles for QGIS

Thank you, your feedback has been a continuous source of motivation. All the best for 2015!

Top10 QGIS Planet posts 2014

It’s the end of December and time to recap 2014. Therefore, I decided to have a look at what this year has brought us. There were plenty of great posts for both casual and power users as well as developers. Here is my pick of the top 10 posts from the QGIS Planet blog aggregator.

  1. Tons of colour improvements! (Nyall Dawson)
  2. The QGIS Field calculator is dead. Long live the Field calculator bar (Nathan Woodrow)
  3. Why QGIS Class Names Start with Qgs (Gary Sherman)
  4. Atlas Previews (Nyall Dawson)
  5. QGIS atlas on non geometry tables (Nathan Woodrow)
  6. Gradient Fills (Nyall Dawson)
  7. What are all these QGIS file types? Why do I need them (Nathan Woodrow)
  8. Getting Started Writing QGIS Python Plugins (Peter Wells)
  9. QGIS Layer Tree API (Martin Dobias)
  10. Shapeburst fill styles (Nyall Dawson)

More great features and posts are sure to come next year. For example, Nyall is currently running a campaign on Kickstarter to add Live Layer Effects such as drop shadow effects to QGIS. Please support it if you can.

Kickstarter Alert – Live Layer Effects for QGIS

QGIS is well regarded for its fantastic cartographic abilities – it’s got a huge range of symbology styles and options which can be used to style your maps. But there’s more we can do to push this even further.

One long requested cartographic feature has been for live drop shadows on layers. Why stop there? Why not inner and outer glow effects and live blur effects? Just imagine the cartographic possibilities if this functionality was available from within a GIS, and didn’t require exporting maps to external editors…

I’ve launched a Kickstarter project to fund implementing live layer effects like this within QGIS. Please consider donating or spreading the word if you’d find this feature useful!

Setting up a Fedora 21 QGIS Workstation

I have been a long time Ubuntu user (I have actually been using it since Ubuntu 4.10 ‘Warty Warthog’) – the first official release. The advent of Ubuntu saw an end to my distro hopping whilst looking for the ‘perfect linux distro’.

Recently though, Ubuntu has been losing momentum in my opinion – especially in terms of supporting the latest Gnome desktop editions and catering for those of us who like to use a leading edge platform for our developer workstations. I was particularly curious to see if QGIS runs nicely under Wayland, the next-generation graphics environment for Linux.

I have been using docker heavily for the last year and have come to the point where I feel that the underlying Linux flavour is less important since I can fairly arbitrarily deploy applications in docker containers using whichever flavour of Linux inside the container is most convenient.

Thus I decided to try and see how easy it would be to get Fedora 21 installed on my MacBook 13″ Laptop which was running Ubuntu quite nicely until now. In the Gist below, I detail the various installation steps I took to get my standard suite of applications installed. These include:

  • docker
  • QGIS compilation build chain
  • PyCharm 4
  • Shutter
  • Skype
  • QtCreator / QtDesigner etc.
  • btsync
  • Google Chrome
  • vlc and assorted video codecs
  • keepassx
  • Elegance gnome theme (must-have if you use Gnome!)


Workspace 1_130

I will keep the above Gist updated as I tweak my configuration, but by and large the migration to Fedora has been fairly painless and I am enjoying working on the latest Gnome desktop. I was able to replicate pretty much all of the application stack I ran on Ubuntu, though in some cases the setup & installation of applications was a little more complex than on Ubuntu, and in one case (btsync-gtk-gui) I have not yet found a binary installation package.

Exploring open government population data collected by ODVIS-AT

At FOSS4G2013, I had the pleasure to attend a presentation about the ODVIS.AT project by Marius Schebella from the FH Salzburg. The goal of the project – which ended in Summer 2014 – was “to display open data (demographic, open government data) in a quick and easy way to end users” by combining it with OpenStreetMap. Even though their visualization does not work for me (“unable to get datasets” error), not all is lost because they provide an SQL dump of their PostGIS database.

Checking the data, it quickly becomes apparent that each data publisher decided to publish a slightly different dataset: some published their population counts as timelines over multiple years, others classified population by migration background, age, or gender. Also, according to the metadata table, no data from Salzburg and Burgenland were included. Most datasets’ reference date is between 2011 and 2013 but the data of the westernmost state Vorarlberg seems to be from 2001.

Based on this database, I created a dataset combining the municipalities with the Viennese districts and joined the population data from the individual state tables. The following map shows the population density based on this dataset: it is easy to recognize the densely populated regions around Vienna, Linz, Graz, and in the big Alpine valleys.


Overall, it is incredibly time-consuming to create this seemingly simple dataset. It would be very helpful if the publishers would agree on a common scheme for releasing at least the most basic information.

Considering that OpenStreetMap already contains population data, it barely seems worth all the trouble to merge these OGD datasets. Granted, the time lines of population development would be interesting but they are not available for each state.

P.S. If anyone is interested in the edited database, I would be happy to share the SQL dump.

Shortcuts to hide/show panels in QGIS

Just a quick one to show how to assign shortcuts to hide and show for panels in QGIS. Add this to your .qgis2\python\

from functools import partial
from qgis.utils import iface

from PyQt4.QtCore import *
from PyQt4.QtGui import *

mappings = {"Layers": Qt.ALT + Qt.Key_1,
            "Browser": Qt.ALT + Qt.Key_2,
            "PythonConsole": Qt.ALT + Qt.Key_3}
shortcuts = []

def activated(dock):
    dock = iface.mainWindow().findChild(QDockWidget, dock)
    visible = dock.isVisible()
    dock.setVisible(not visible)

def bind():
    for dock, keys in mappings.iteritems():
        short = QShortcut(QKeySequence(keys), iface.mainWindow())
        short.activated.connect(partial(activated, dock))


and now you can hide and show using ALT + number

2nd edition of Learning QGIS

It’s my pleasure to announce that the updated and extended 2nd edition of Learning QGIS is available now.

I also want to take this opportunity to thank everyone who made the 1st edition such a great success!

This second edition has been updated to QGIS 2.6 and it features a completely new 6th chapter on Expanding QGIS with Python. It introduces the QGIS Python Console, shows how to create custom Processing tools, and provides a starting point for developing plugins.

Overall, the book has grown by 40 pages and the price of the print version has dropped by 3€ :-)

Happy QGISing!


GRASS GIS 7: Vector data reprojection with automated vertex densification

GRASS GIS 7 just got better: When reprojecting vector data, now automated vertex densification is applied. This reduces the reprojection error for long lines (or polygon boundaries). The needed improvement has been kindly added in v.proj by Markus Metz.

1. Example

As an (extreme?) example, we generate a box in LatLong/WGS84 (EPSG: 4326) which is of 10 degree side length (see below for screenshot and at bottom for SHAPE file download of this “box” map):

[neteler@oboe ~]$ grass70 ~/grassdata/latlong/grass7/
# for the ease of generating the box, set computational region:
g.region n=60 s=40 w=0 e=30 res=10 -p
projection: 3 (Latitude-Longitude)
zone:       0
datum:      wgs84
ellipsoid:  wgs84
north:      60N
south:      40N
west:       0
east:       30E
nsres:      10
ewres:      10
rows:       2
cols:       3
cells:      6
# generate the box according to current computational region: box_latlong_10deg

Next we start GRASS GIS in a metric projection, here the EU LAEA:

# EPSG 3035, metric EU LAEA:
grass70 ~/grassdata/europe_laea/user1/
GRASS 7.0.0svn (europe_laea): >

Now we first reproject the map the “traditional way” (no vertex densification as in most GIS, here enforced by smax=0):

v.proj box_latlong_10deg out=box_latlong_10deg_no_densification
location=latlong mapset=grass7 smax=0

Then we do a second reprojection with new automated vertex densification (here we use the default values for smax which is a 10km vertex distance in the reprojected map by default):

v.proj box_latlong_10deg out=box_latlong_10deg_yes_densification
location=latlong mapset=grass7

Eventually we can compare both reprojected maps:

g.region vect=box_latlong_10deg_no_densification

# compare:
d.mon wx0
d.vect box_latlong_10deg_no_densification color=red
d.vect box_latlong_10deg_yes_densification color=green fill_color=none
Comparison of the reprojection of a 10 degree large LatLong box to the metric EU LAEA (EPSG 3035): before in red and new in green. The grid is based on WGS84 at 5 degree spacing.

Comparison of the reprojection of a 10 degree large LatLong box to the metric EU LAEA (EPSG 3035): before in red and new in green. The grid is based on WGS84 at 5 degree spacing.

The result shows how nicely the projection is now performed in GRASS GIS 7: the red line output is old, the green color line is the new output (its area filling is not shown).

Consider to benchmark this with other GIS… the reprojected map should not become a simple trapezoid.

2. Sample dataset download

Download of box_latlong_10deg.shp for own tests (1kB).

The post GRASS GIS 7: Vector data reprojection with automated vertex densification appeared first on GFOSS Blog | GRASS GIS Courses.

  • Page 1 of 72 ( 1421 posts )
  • >>

Back to Top