QGIS Planet

Over the last couple of weeks, Karolina has been very busy improving and expanding Time Manager. This post is to announce the 1.6 release of Time Manager which brings you many fixes and exciting new features.

What’s this feature interpolation you’re talking about?

Interpolation is really helpful if you have multiple observations of the same (moving) real-world object at different points in time and you want to visualize the movement between the observations. This can be used to visualize animal paths, vehicle tracks, or any other movement in space.

The following example shows a simple layer which contains 12 point features (3 for each id value).

Using Time Manager interpolation, it is easy to create animations with interpolated positions between observations:

How is it done?

When you open the Time Manager 1.6 Settings | Add layer dialog, you will find a new option for interpolation settings. This first version supports linear interpolation of point features but more options might be added in the future. Note how the id attribute is specified to let Time Manager know which features belong to the same real-world object.

For the interpolation, Time Manager creates a new layer which contains the interpolated features. You can see this layer in the layer list.

I’m really looking forward to seeing all the great animations this feature will enable. Thanks Karolina for making this possible!

Thanks to the work of Devrim Gündüz, Volker Fröhlich, Dave Johansen, Rex Dieter and other Fedora/EPEL packagers I had an easy going to prepare RPM packages of QGIS 2.8 Wien for Fedora 20 and 21, Centos 7, and Scientific Linux 7.

The base SRPM package I copied from Fedora’s koji server, modified the SPEC file in order to remove the now outdated PyQwt bindings (see bugzilla) and compiled QGIS 2.8 via the great COPR platform.

The data accessed includes daily, 8 day, monthly and yearly composites, all of which can be saved to disk while downloading. Future plans for the plugin include additional access to other datasets such as ocean Net Primary Production, selection by bounding box, the ability to save in other formats, a progress bar etc.

I used the plugin to download global Sea Surface Temperatures for the 13th Jan 2015. I then used shapefiles from Natural Earth to create a simple basemap. I finally chose the IBCAO Polar Stereographic projection (EPSG: 3996) to create a map centred on the North Pole.

Here’s a nice looking map I created using QGIS 2.3, the testing version of QGIS. I downloaded free OpenStreetMap data and I styled it to look just like Google Maps, as per instructions published by Anita Graser. I also outlined county boundaries using the new “Shape Burst” effect, which creates a pleasing graduated colour pattern that faithfully follows polygon outlines (it’s also applied to the Sea, though it’s quite subtle). I used Data Defined Properties to restrict the effect to all counties except Dublin City, this also created a Mask.

Lastly, there’s also a subtle “Coastal Vignette” effect, these are fine lines that trace the coastline and were typical of old style hand drawn maps. Must have taken a tremendous amount of patience. I developed a simple method of reproducing the effect and I’ll let you know how I did it in my next blog post. Oh and by the way, the scale relates to a map printed at A3 size.

ESRI’s ArcGIS Online World Imagery is a high resolution satellite and aerial imagery base map for use in Google Earth, ArcMap and ArcGIS Explorer. The same excellent imagery is used by the Bing Maps Aerial layer. Somewhat surprisingly, World Imagery can also be accessed by QGIS, as it supports ESRI’s map servers that use Representational State Transfer (REST) and Simple Object Assess Protocol (SOAP) standards.

Simply copy and past the following code into the Python Console in QGIS and press return (Plugins – Console):

The code adds an ESRI Online World Imagery base map to QGIS. It has a number of advantages over the popular OpenLayers Plugin that adds various Google, Bing and OpenStreetMap image layers to QGIS. Unlike images downloaded by the OpenLayers plugin the ESRI World Imagery base map is a true Raster who’s attributes are fully editable e.g. brightness, blending mode and transparency can be adjusted. World Imagery can also be printed at a very high resolution with other QGIS layers on a map and without it shifting relative to other layers; a conspicuous problem with OpenLayers that does not use “On the Fly” re-projection and only prints Google, Bing layers at a low resolution. It is an ideal aerial base map.

Before the advent of shipborne satellite navigation systems, navigation at sea required three precise measurements – Solar or Stellar Declination for Latitude, Time at Greenwich for Longitude and True North that determined the ship’s heading. True North was obtained from the ship’s Magnetic Compass, an instrument who’s name indicates at an additional complication.

A magnetic compass does not point towards True North. Magnetic North is 100s km from the Geographic North Pole and the Earth’s magnetic field is uneven, it is distorted by magnetic irregularities within the Outer Core and intrinsically magnetic Mantle and Crustal rock. Additionally, the position of Magnetic North is not fixed, it is presently drifting from Arctic Canada towards Russia at 15 km per year. Therefore True North has to be derived from Magnetic North using a correction called Magnetic Declination (or Magnetic Variation), the angular difference between Magnetic North and True North. Magnetic Declination varies from location to location and over time.

Nautical navigation charts typically contain one or more Compass Roses, also called a Windrose, these consist of two circles – an outer circle that displays the cardinal directions of North, East, South and West and a inner circle that displays the direction of Magnetic North. The Magnetic Declination and its annual rate of change is typically printed within the Compass Rose, it is therefore possible to calculate the Magnetic Declination several years after a map is printed.

In this tutorial I will show you a process that to create a Compass Rose with the correct Magnetic Declination and Annual Rate of Change for any terrestrial location for use in QGIS. First we need to obtain a suitable Compass Rose graphic. Conveniently the United States National Oceanic and Atmospheric Administration (NOAA) published a Compass Rose in the Public Domain i.e. it is free to use without limitation. I downloaded a version of the NOAA Compass Rose from Wikimedia (or you can right click and save the Compass Rose below). Additionally, the background of this Compass Rose is transparent, this allows a map (or indeed a web page) to show though (note the Magnetic Declination in 1985 was 4 degrees 15 minutes west of True North and it had an annual decrease of 8 minutes of a degree per year).

There are several handy on-line utilities that can calculate Magnetic Declination and the Annual Rate of Change but we shall use Charles F. F. Karney’s excellent cross-platform GeographicLib in this case. GeographicLib is a suite of command line utilities for solving solving various geodesic problems such as conversions between geographic, UTM, UPS, MGRS, geocentric and local cartesian coordinates, gravity calculations, determining geoid height, and magnetic field calculations. The latest version can be obtained as a pre-compiled binary from Sourceforge or as source code.

The other essential step is to measure the precise map location in WGS84 coordinates. This can be done using the Coordinated Capture plug-in provided as standard with QGIS. To select the WGS84 coordinate reference system (CRS) click the sphere symbol in Coordinated Capture panel to open the Coordinate Reference System Selector. After setting the CRS to WGS84 (EPSG: 4326), click the icon left of the “Copy to Clipboard” button (this toggles real time display of captured coordinates) and then click “Start Capture”. The position in Decimal Degrees will be updated in the upper window as you move the cursor across the map, the lower window will display projected coordinates (in my case Pseudo Mercator EPSG: 3857). Clicking the map will select a coordinate point and the real time display will cease updating.

The MagneticField utility of GeographicLib is then used to calculate the Magnetic Declination and Annual Rate of Change for the captured coordinate, in this case a location east of Howth, Ireland.

The results are: Magnetic Declination in degrees (-3.57); the inclination of the Magnetic Field in degrees (67.81); the horizontal strength of the magnetic field in nanotesla (18572.9 nT); the north component of the field (18536.9 nT); the east component of the field in (-1152.2 nT); the vertical component of the field in nT (45528.7 nT) and the total field (49171.3 nT). The numbers on the second line are the annual rate of change of these values, the first number is. We only need the first numbers on each line; the Magnetic Declination (-3.57) and Annual Rate of Change of Magnetic Declination (0.17). We can convert these to Degrees Minutes Seconds if required.

After calculating the Magnetic Declination and Annual Rate of Change, edit the NOAA Compass Rose in a graphics program such as GIMP or Photoshop. In my case I copied the inner circle to a separate layer and I rotated it 3.57 degrees anticlockwise. I then added text to the Compass Rose stating the Magnetic Declination (Var.) and the Annual Rate of Change (Annual Decrease). After editing the Compass Rose graphic I finally added it to my Nautical Chart as a Image in Map Composer of QGIS.

Continuing with a nautical theme, here is a nautical chart I creating using QGIS 2.4. It includes a Graticule in decimal degrees, a Compass Rose and a scale bar in Nautical Miles. A magnetic declination of 3º 35′ was determined using the MagneticField utility of GeographicLib, an advanced software library for solving geodesic problems. I will post a full tutorial shortly.

Occasionally on old maps you may see a pleasing decorative effect on bodies of water called a “Coastal Vignette”, these are fine lines that highlight coastlines and lake shores. The example seen above is from a ca. 100 year old “6-inch map” of Lough Nafooey in County Galway, Ireland. I presume the Coastal Vignette effect in this example was hand drawn, it required considerable skill and patience.

These is no plugin for creating Coastal Vignettes in QGIS just yet, so I developed a simple technique to recreate the effect using the raster ‘Proximity (Raster Distance)’ algorithm accessible in the Processing Toolbox.

In order to use the Proximity Analysis tool I first converted a Shapefile polygon depicting the sea off Dublin into a 10 by 10 metre resolution Raster using the menu command ‘Raster – Conversion – Rasterize (Vector to raster)’.

This generated a Raster that coded the Sea as ‘1’ (white) and ‘0’ (black) for Land.

Next, I selected ‘Proximity(raster distance)’ from the Processing Toolbox – (GDAL/OGR) – [GDAL] Analysis – Proximity(raster distance). You can quickly find the command by typing the algorithm’s name in the box above the Processing Toolbox.

I entered 0 in the ‘Values’ box, this tells the Proximity algorithm to measure the distance away from land (a value of 0). The resulting Raster contains cell values that correspond to the distance away from the coast in metres, which I styled below.

The final step is to create Contours Lines from the Proximity analysis result using the menu item Raster – Contour. In my case I used an “interval between the contour lines” of 200 metres and I added an Attribute name called “DIST”.

The resulting contour lines have distance attributes attached to them can be used to create a Graduated colour style if needed, though in my cause I manually edited the attributes of 10 contour lines nearest the coast and I gradually increased the transparency of the mid-grey contour lines from opaque at the coast to fully transparent out at sea. I made the remaining contour lines transparent.

And here is the finished result, with the Sea and an OpenStreetMap base map styled to look just like Google Maps.

A very handy plugin for QGIS I use day to day is go2streetview by Enrico Ferreguti. The plugin adds an icon to the tool bar in QGIS and when selected I can click a road or street on a base map and a window will open that displays the Google Street or a Bing Maps Bird’s Eye view of the location. The camera’s direction and location is highlighted by a blue marker. I use the plugin when tracing boundaries of parks, open spaces and foot paths from aerial imagery. If the imagery is blurred or the view is obscured by trees, I click a point on a nearby street to see the location up close. The plugin works wherever Google Street view and Bing Birds Eye has coverage.

For example, in the screen-shot below notice there is a footpath leading to a bus shelter that’s not mapped by OpenStreetMap. I know where it is now, I will add it to my map.

Someone wrote to me asking if it would be possible to generate an XYZ ASCII file from a single band raster layer in QGIS. No doubt there are more efficient ways (this approach is pretty slow but it works), but I thought it would be fun to show how you can iterate over a raster, writing out the value of each cell into a text file (along with the centroid coordinates for that cell).

To use the script, you should save it to your local machine, then open the python console and load the script in the python editor. Next select a single band raster and then run the script in the editor. If your raster is quite large, it will take some time to run. I have spent zero time trying to optimise the script – if someone has an idea for doing it faster, send me a patch and I will update the example above.

What’s an LTR

LTR stands for “Long Term Release”. This means that QGIS now has a system in place to provide a one-year stable release with backported bug fixes. The idea behind LTR is to have a stable platform for enterprises and organizations that don’t want to update their software and training materials more often than once a year. To make the LTR a success, users and developers alike should be aware that bug fixes should be applied to both the LTR branch as well as the normal development branch. If you are interested in the details, you can find more info in the corresponding QGIS Enhancement Proposal.

Users who enjoy working with the cutting-edge version will be able to follow the regular four-monthly release cycle like last year.

What’s new?

This new version comes with many great new features which you can explore in the official visual changelog. It’s really hard to pick but my personal favorites are:

Sometimes you want to automatically generate a report to reflect the latest state of your data. For example you may be capturing spatial data into a PostGIS database and want a snapshot of that every few hours expressed as a pdf report. This example shows you how you can quickly generate a pdf based on a QGIS project (.qgs file) and a QGIS template (.qpt file).

Using this approach you can generate all kinds of useful outputs without ever needing to open QGIS each time you generate the report. Simply create the needed project and template files and then run it like this:

Now and then I get too many map symbols (points) in the same place, and I thought how nice it would be if we could drag n’ drop them around without messing with their geometries position, just like we do with labels. That thought gave me an idea for a cool hack.

Choose your point layer and start by creating two new fields called symbX and symbY (Type: Decimal number; Size: 20; Precision: 5). Now go the layer properties and in the Style tab edit your symbol. For each level of your symbol select “map units” as the offset units, and set the following expression in the offset data define properties option:

CASE WHEN symbX IS NOT NULL AND symbY IS NOT NULL THEN
tostring($x - symbX) + ',' + tostring($y - symbY)
ELSE
'0,0'
END

Kartoza has just wrapped up a three-day Introduction to QGIS course that we gave pro bono at The African Quaternary: Environments, Ecology and Humans conference in Cape Town (AfQUA2015). Thank you to Kelly Kirsten from the local organising committee at the University of Cape Town for inviting us. Admire Nyakudya presented to about fifteen conference delegates from around the world. Attendees ran QGIS 2.6.1 on their own notebooks on the operating system of their choice. Some already use QGIS, some were experiencing QGIS for the first time and some some wanted to compare it with ArcGIS. The course content was guided largely by the QGIS training manual but as we usually do, adapted for the requirements, interests and pace of the class.

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

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

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.

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.

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:

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!

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:

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.

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

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.

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.