Planet QGIS

May 20, 2013

Underdark

TimeManager in QGIS 2.0

Today, I updated my QGIS Time Manager plugin to version 0.8. It now works with the QGIS 2.0 API and that means that we can take advantage of all the cool new features in our animations. The following quick example uses the “multiply” blend mode with the tweet sample data which is provided by default when you install the plugin:

(The video here is a little small. Watch it on Youtube to see the details.)


by underdark at May 20, 2013 02:39 PM

May 17, 2013

GFOSS

FOSS4G-CEE 2013: Program published!

Join us at FOSS4G Central and Eastern Europe (FOSS4G-CEE) 2013 from 16th - 20th June, National Library of Romania, Bucharest, Romania.


You will meet well known Keynote Speakers (random order): Jeff McKenna, Paul C. Smits, Jáchym Čepický, Schuyler Erle, Maria Antonia Brovelli, Dirk Frigne, Markus Neteler, Alyssa Wright, and Radu Puchiu.

Check the long list of Practical Workshops and Oral Presentations at: http://2013.foss4g-cee.org/program/schedule
Check out for the additional Code Sprint, the Open GeoData Hackathon, and the Open Data Side Event.

How to arrive? See http://2013.foss4g-cee.org/venue/map

by markusN (noreply@blogger.com) at May 17, 2013 04:21 AM

May 12, 2013

Tim Sutton (Linfiniti)

How to do some quasi 3d cartographic effects in QGIS

No words for this one, just pictures! Above: What we are trying to achieve… Above: Our symbol layers Above: The roof colour is data defined A shadow Layer And a highlight layer One other hint – don’t forget to enable symbol levels!

by Tim Sutton at May 12, 2013 09:08 PM

May 10, 2013

Underdark

QGIS Flickr Group

The excitement about the upcoming 2.0 release is growing and to add some fuel to the fires, Mathieu founded the QGIS Flickr Group. Anyone can join and add their maps done with QGIS master.

nottingham_flights1 roadshields1 kathmandu_flights1

I’m looking forward to seeing what you have come up with. Please note that this group is meant for maps only (therefore no screenshots of the application please).


by underdark at May 10, 2013 09:03 PM

May 04, 2013

Underdark

Sextante Modeler Evolution 1.0.8 to 1.1

Sextante is quickly becoming the goto geoprocessing toolbox for me. I’ve been working with Sextante 1.0.8 on QGIS 1.8 and lately I’ve started looking into Sextante 1.1 for QGIS 2. This post highlights some of the main differences between the two versions. I’m sure there are many more hidden gems I have not discovered so far.

One thing you will notice if you have used previous versions of Sextante is that the new version comes with a simplified interface which groups tools into three categories: geoalgorithms, models, and scripts. If you prefer the old style grouping by algorithm source such as GDAL, GRASS, etc. you can switch to the Advanced interface.

advanced simplified

Let’s start with the bad news: Models created in 1.0.8 are not compatible with 1.1 since many of the algorithms have been rearranged in new categories and Sextante cannot find them by their old names anymore, e.g.

1.0.8 … ALGORITHM:ftools:fixeddistancebuffer
1.1 … ALGORITHM:qgis:fixeddistancebuffer

The great news is that the modeler has been improved greatly. Model representations now show the flow of input and output data through the model steps much more clearly:

Sextante 1.0.8 Modeler

Sextante 1.0.8 modeler

Sextante 1.1 Modeler

Sextante 1.1 modeler

I also found the new modeler much more stable – no crashes so far. *fingerscrossed*

Another nice new feature is Sextante commander which can be started using the shortcut Ctrl+Alt+M. It’s a quick launch solution for all Sextante algorithms:

sextante_commander

At FOSS4G, I’ll be presenting some work I did evaluation OSM using Sextante 1.0.8. I’d love to hear how you are using Sextante.


by underdark at May 04, 2013 09:10 AM

May 03, 2013

Underdark

Print Composer 2.0 – Take #7

Today’s post: More print composer overview magic!

Inverted Map Overviews

Thanks to the “Invert overview” option, we can now chose between highlighting the detail area (left example in the image) or blocking out the surrounding area (right example).

printcomposer_overviews

The “Lock layers for map item” option can come in very handy if you want to reduce the number of layers in the overview map while still keeping all layers of interest in the main map.


by underdark at May 03, 2013 03:10 PM

May 02, 2013

Sourcepole

QGIS Cloud and Sourcepole are sponsoring Öcher-Safari

QGIS Cloud and Sourcepole are proud to be official sponsors of the team Öcher-Safari, attending the Allgäu-Orient-Rallye. One of the last adventures in the world of cars. Sourcepole serves the team with know how, infrastructure and more. Information about the team and the charity ideas of this event you can find on Öcher-Safari and the official web site of the Allgäu-Orient-Rallye.

by hdus at May 02, 2013 06:22 PM

April 20, 2013

Underdark

Advanced Python Field Calculator

Advanced Python field calculator is one of the numerous tools in Sextante for QGIS. It’s extremely powerful but it doesn’t use the syntax of QGIS’ default field calculator (the one you can access via attribute table). Therefore, here comes a short introduction:

If you want to reproduce this example, I used a dataset of town areas from the new open government data site of Lower Austria.

The upper half of the Advanced Python field calculator is rather self-explanatory but the lower half is where it gets interesting: Code in the global expression section will be executed only once before the calculator starts iterating through all the features of the input layer. Therefore, this is the correct place to import necessary modules or to calculate variables that will be used in subsequent calculations. Code in the formula section will be evaluated for each feature in the input layer. As shown in the following example, this is where we can calculate new values, e.g. the area of the polygons in km²:

sextante_pythonfieldcalc_area

As you can see, the feature geometry can be accessed using $geom.

If you want to access an existing attribute, that’s possible using <attribute_name>.

Anyway, this is the resulting layer’s attribute table including the new areaKM2 field:

sextante_pythonfieldcalc_area_results

Thanks to Victor for pointing me to the documentation of FieldPyculator which Advanced Python field calculator is based on.


by underdark at April 20, 2013 07:20 PM

April 17, 2013

SpatialGalaxy

QGIS Back in the Day

Do you remember this?

QGIS of Yesteryear

If so, you’ve been using QGIS a long time…

  • OGR and PostGIS support
  • No raster support
  • Three widgets on the Symbology tab
  • No symbology in the legend

But you could use it handily on a 640x480 display.

April 17, 2013 03:50 PM

Tim Sutton (Linfiniti)

New forms related features coming in QGIS 2.0

View here on youtube: https://www.youtube.com/watch?v=rnqRAOvuJEU

by Tim Sutton at April 17, 2013 03:34 PM

April 16, 2013

Tim Sutton (Linfiniti)

QGIS 2 Annotations

View here on youtube: https://www.youtube.com/watch?v=0pDBuSbQ02o

by Tim Sutton at April 16, 2013 02:22 PM

April 10, 2013

Tim Sutton (Linfiniti)

Dynamically updating layers in QGIS with PostGIS views

View here on youtube: https://www.youtube.com/watch?v=oOhbbEkl4Kg

by Tim Sutton at April 10, 2013 02:39 PM

March 26, 2013

Underdark

Print Composer 2.0 – Take #6

The latest version of Print composer features new

Rulers and guide lines or “alignments”

Rulers are a well-known feature in graphics programs such as Gimp and Photoshop. Now you can also find them in QGIS Print Composer. Click onto the ruler, hold the mouse key down and move the cursor to position guide lines for map feature alignment.

printcomposer_grid

Of course, there’s also the handy “Snap to grid” functionality.


by underdark at March 26, 2013 09:01 PM

March 24, 2013

Underdark

Print Composer 2.0 – Take #5

This fifth part in my series on QGIS 2.0 Print Composer presents

Map grids

There are numerous different options for map grids in the new composer but a picture is worth a thousand words:

printcomposer_grids

The upper-left map features a zebra frame style and coordinate labels aligned horizontally and vertically.

The upper-right map shows a normal frame with labels written inside the frame instead of outside. This grid shows an additional offset.

The lower-left map has no frame but customized, colored and dashed grid lines.

Finally, the lower-right map shows a cross grid with default horizontal coordinate labels.


by underdark at March 24, 2013 09:24 PM

March 20, 2013

Underdark

Print Composer 2.0 – Take #4

Today’s spotlight is on a feature which you’ll really love if you have to arrange a little more text on a print layout:

HTML labels

Regular labels are limited to one font, size and color. With the new “Render as HTML” option, you gain flexibility to use HTML tags to style your text by adding headers, lists and even images (note the QGIS logo I added by pointing to the image online):

printcomposer_html


by underdark at March 20, 2013 07:43 PM

March 19, 2013

Underdark

Print Composer 2.0 – Take #3

After guide lines and multi-column legends, today’s focus is on

Overview maps

Small overview maps are used to help the reader get an idea of where the region displayed on the main map is located. In the new Print Composer, it’s simple to add such overviews: Add the main map as usual. Then add another map object to the composition an go to the “Overview” section. There, you can specify that the second map object should be an overview map for the first one: Just specify “Map 0″ in the dropdown list:

printcomposer_overview


by underdark at March 19, 2013 09:02 PM

SpatialGalaxy

New Version of the QGIS Script Runner Plugin

The Script Runner plugin allows you to manage and execute a collection of scripts in QGIS to automate tasks and perform custom processing.

Script_Runner

Version 0.6 of Script Runner has been released and includes these changes:

  • Arguments can be passed to a script using keyword arguments
  • Script output is logged to the Script Runner window
  • Script output can be logged to disk
  • Preferences dialog allows control of output and logging options
  • Exceptions in scripts are displayed without interfering with console/logging output
  • Context menu (right-click) to access script functions
  • Edit script function uses system default editor or one you specify in preferences

For a basic introduction to Script Runner see this post: Script Runner: A Plugin to Run Python Scripts in QGIS

Working with Scripts

Adding Scripts

To run a script, you must add it to Script Runner using the Add Script tool on the toolbar. Select the script from the file dialog to add it to a list in the left panel. The list of scripts is persisted between uses of QGIS.

Running a Script

To run a script, select it from your list of scripts and click the Run tool. Output from the script will be displayed in the Script Runner console

Remove a Script

You can remove a script by selecting it from the list and clicking the Remove Script tool. This just removes it from the list; it does nothing to the script file on disk.

Script Information

Clicking the Info tool will populate the Info and Source tabs in the panel on the right. The Info tab contains the docstring from your module and then a list of the classes, methods, and functions found in the script. Having a proper docstring at the head of your script will help you determine the purpose of script.

At version 0.6 the Info tool is only needed if you have disabled automatic display of info/source (see Preferences).

Viewing the Source

You can view the source of the script on the Source tab. This allows you to quickly confirm that you are using the right script and it does what you think it will.

New Features

Version 0.6 implements a number of new features.

Passing Arguments to a Script

You can pass arguments to your script using keywords. Your run_script function must have two arguments:

1
  def run_script(iface, **args):

Running your script is done using the Run script with arguments tool. This prompts you to enter your argument(s) in a key=value format:

Argument_dialog

All strings must be quoted and multiple arguments should be separated by a comma.

When your script is run, the arguments are contained in args, which is a Python dict. In the example above, you could access them like this:

1
2
  my_path = args['path']
  my_buffer_size = args['buffer_size']

Scripts that accept keyword arguments are displayed in the list with two asterisks appended to their name:

arg_scripts

See Passing Arguments for a complete example.

Output Console

All print statements in your script will be directed to the Script Runner console. In addition, any tracebacks from exceptions will be displayed there, as well as in a popup dialog.

Printing messages to the console can be useful for both development and status updates in long running scripts. You can clear the console using the Clear Console tool. There is also an option in Preferences to clear the console each time a script is run.

Logging to Disk

You can choose to log everything that goes to the output console to disk. Use the Preferences dialog to setup the directory where the scriptrunner.log will be written.

Editing a Script

You can open the selected script in an external editor by right-clicking on it and choosing Edit script in external editor from the popup menu. The default system editor for .py files will be used to open the script. In Preferences, you can specify a different editor by entering the full path to the executable.

Preferences

The Preferences dialog allows you to set the following options:

Script_Runner_Preferences

Script Examples

Here are three script examples: a simple script that has only a run_script function, one that uses a Python class, and one that passes keyword arguments.

Simple Script

This simple script contains only a run_script function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    """ Load a layer and change the fill color to red. """
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from qgis.core import *
    from qgis.gui import *


    def run_script(iface):
        mapreg = QgsMapLayerRegistry.instance()
        mapreg.removeAllMapLayers()
        wb = QgsVectorLayer('/data/world_borders.shp', 'world_borders', 'ogr')
        mapreg.instance().addMapLayer(wb)
        renderer = wb.rendererV2()
        symb = renderer.symbol()
        symb.setColor(QColor(Qt.red))
        wb.setCacheImage(None)
        wb.triggerRepaint()
        iface.refreshLegend(wb)

When executed by Script Runner, the script removes any layers currently on the map, then loads the world_borders shapefile, sets its fill color to red, and updates the map canvas and the legend. The run_script function does all the work. You could expand this script by adding additional functions that are called from run_script.

A Script with a Class

This script uses a class that is initialized from the run_script function to load some layers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    """Load all shapefiles in a given directory.  """
    from glob import glob
    from os import path

    from qgis.core import *
    from qgis.gui import *
    import qgis.utils

    class Loader:
        def __init__(self, iface):
            """Initialize using the qgis.utils.iface
            object passed from the console.
            """

            self.iface = qgis.utils.iface

        def load_shapefiles(self, shp_path):
            """Load all shapefiles found in shp_path"""
            print "Loading shapes from %s" % path.join(shp_path, "*.shp")
            shps = glob(path.join(shp_path, "*.shp"))
            for shp in shps:
                (shpdir, shpfile) = path.split(shp)
                print "Loading %s" % shpfile
                lyr = QgsVectorLayer(shp, shpfile, 'ogr')
                QgsMapLayerRegistry.instance().addMapLayer(lyr)

    def run_script(iface):
        ldr = Loader(iface)
        print "Loading all shapefiles in /qgis_sample_data/vmap0_shapefiles"
        ldr.load_shapefiles('/qgis_sample_data/vmap0_shapefiles')

In this example, the run_script function creates an instance (ldr) of a class named Loader that is defined in the same source file. It then calls a method in the Loader class named load_shapefiles to do something useful—in this case, load all the shapefiles in a specified directory.

Passing Arguments

This script illustrates passing an argument (a path) to load all shapefiles in a directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    """Load all shapefiles in a given directory."""
    from glob import glob
    from os import path
    from qgis.core import *
    from qgis.gui import *
    import qgis.utils


    class Loader:
        def __init__(self, iface):
            """Initialize using the qgis.utils.iface 
            object passed from the console.
 
            """
            self.iface = qgis.utils.iface

        def load_shapefiles(self, shp_path):
            """Load all shapefiles found in shp_path"""
            print "Loading shapes from %s" % path.join(shp_path, "*.shp")
            shps = glob(path.join(shp_path, "*.shp"))
            for shp in shps:
                (shpdir, shpfile) = path.split(shp)
                print "Loading %s" % shpfile
                lyr = QgsVectorLayer(shp, shpfile, 'ogr')
                QgsMapLayerRegistry.instance().addMapLayer(lyr)

    def run_script(iface, **args):
        ldr = Loader(iface)
        print "Loading all shapefiles in %s" % args['path']
        ldr.load_shapefiles(args['path'])

Lines 29 and 30 illustrate using the passed argument to print a message to the console and call the method to add the shapefiles to the map.

Final Word

The script examples are minimalistic—they don’t do error checking in a number of places, such as checking to see if a QgsVectorLayer is valid or if needed arguments were actually passed to the script. Don’t take the scripts as examples of complete, solid code.

Comments on this post are welcome, as are bug reports. The link to the bug tracker for Script Runner can be found in the About box, along with the link to the code repository and my email address.

March 19, 2013 03:47 AM

March 18, 2013

Underdark

Print Composer 2.0 – Take #2

After yesterday’s first post on guide lines & snapping for user-friendly map element arrangement, we’ll have a look at another great new addition:

Multi-column legends

In the panel on the right, there is a new section called “Columns”. Here we can create multi-column legend layouts by specifying the desired number of columns. Add some spacing too. It will make the result look more balanced.

By default, Print Composer tries to keep all classes of one layer in one column. You can override this behavior – as I did in this example – by ticking “Split Layers”:

printcomposer_columns

Another useful trick is to use text wrapping for long class labels. This option can be found in the legend’s “Main properties” right at the top of the side panel. In this example, I specified wrap on the pipe “|” symbol and inserted this symbol into the longer class names to force a line break:

printcomposer_wraplegendtext


by underdark at March 18, 2013 06:23 PM

March 17, 2013

Underdark

Print Composer 2.0 – Take #1

This is the first post in a series dedicated solely to Print Composer in QGIS 2.0 which you can already admire in recent nightly builds.

Guide lines & snapping for user-friendly map element arrangement

Arranging map elements has never been easier: Elements can be moved as freely as before but now they will automatically try to align with other elements on the page or the page borders. Additional red guide lines help interpret the snapping behavior.

printcomposer_guides


by underdark at March 17, 2013 04:07 PM

March 08, 2013

Sourcepole

Serving multiple WFS-T with TinyOWS

Our favorite WFS-T server complement of UMN Mapserver is TinyOWS. We like the simplicity of it so much, that we packaged it for Ubuntu and added it to OSGeoLive. Installation is easy:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install tinyows

The simplicity is a little bit too much, when it comes to serve multiple WFS-T on the same server. There is only one configuration file, but we want a configuration for each service. There are solutions for that, but I never saw a documentation of the most elegant solution we found. It uses Apache rewrite capabilities to set the TINYOWS_CONFIG_FILE environment variable according to the called URL:

# URL rewriting
RewriteEngine On

# Forbid direct access
RewriteRule ^/cgi-bin/.*$ - [F]

# Rewrite /xxx to /cgi-bin/tinyows with TINYOWS_CONFIG_FILE=/etc/tinyows/xxx.xml
RewriteRule ^/(.+)$ /cgi-bin/tinyows [QSA,PT,L,E=TINYOWS_CONFIG_FILE:/etc/tinyows/$1.xml]

This configuration included in a virtual host declaration (wfs.example.com) serves your WFS-T on wfs.example.com/servicename.

by admin at March 08, 2013 01:26 PM