QGIS Planet

QGIS Plugin of the Week: OpenLayers

This week we look at the OpenLayers plugin for QGIS. This plugin allows you to add a number of image services to your map canvas:

  • Google
    • Physical
    • Streets
    • Hybrid
    • Satellite
  • OpenStreetMap
  • Yahoo
    • Street
    • Hybrid
    • Satellite
  • Bing
    • Road
    • Aerial
    • Aerial with labels

Installing the Plugin

The OpenLayers plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter openlayers in the Filter box, then select OpenLayers Plugin from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.

Using the Plugin

The OpenLayers Plugin uses your view extent to fetch the data from the service you choose. For this reason you should load at least one of your own layers first. Since each of the services are expecting a request in latitude/longitude your layer either has to be geographic or you must enable on the fly projection.

To add one of the services you have two choices; you can pick the service from the Plugins->OpenLayers plugin menu or you can use the OpenLayers Overview. The Overview opens a new panel that allows you to choose a service from a drop-down list. Click the Enable map checkbox to enable the drop-down list and preview the service you want to add. If you are happy with what you see, you can add it to the map by clicking the Add map button.

In the screenshot below we have enabled the Overview panel, added the world boundaries layer1, zoomed to an area of interest, and added the Google terrain (physical) data:

You can add as many services as you want, previewing them using the OpenLayers Overview panel.

1 You can get the world boundaries layer from the Geospatial Desktop sample data set.

QGIS Plugin of the Week: Profile

This week we take a look at a how to plot a terrain profile using the Profile plugin. The plugin can be used with any raster format supported by QGIS. You can can display profiles from up to three rasters at once, allowing you to compare the results. To illustrate, we’ll create a simple profile using a DEM of a 1:63,360 quadrangle in Alaska.

Installing the Plugin

The Profile plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter profile in the Filter box, then select Profile from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.[1]

Using the Plugin

Here we have loaded the DEM as well as a raster (DRG) of the topography for the same quadrangle and zoomed in a bit to an area of interest:

The yellow line has been added to indicate where we will take the profile. While the Profile plugin allows you to interactively select the profile line it doesn’t display the line on the map.

To create a profile, first make sure the raster you want to profile is selected in the layer list, then activate the plugin from the Plugins toolbar by clicking on it. The cursor becomes a cross that you use to create the profile line: click at the start point, move to the end and click again. Once you have created the profile line, the plugin pops up the result:

The profile is taken from the northeast towards the southwest, based on where we clicked first. You can change the exaggeration of the profile by using the slider on the left. The X axis shows the distance along the profile line in map units and the Y axis shows the cell values from the raster—in this case, elevation in meters.

You can save the result as a PDF or SVG using the buttons at the bottom of the dialog.

The Statistics tab displays some information for the raster layer and the profile line:

If we had additional rasters loaded, we could use the Setup tab to add them to the profile analysis. This would display the results using the colors specified for each layer and we could compare them on the Profile tab.

This is just one of several QGIS plugins that deal with profiles. You can check out the rest of them using the Python Plugin installer.

[1] The Profile plugin requires the Python module for QWT5. If you don’t have this installed, a warning will be displayed during the installation process.

QGIS Plugin of the Week: Profile

This week we take a look at a how to plot a terrain profile using the Profile plugin. The plugin can be used with any raster format supported by QGIS. You can can display profiles from up to three rasters at once, allowing you to compare the results. To illustrate, we’ll create a simple profile using a DEM of a 1:63,360 quadrangle in Alaska.

Installing the Plugin

The Profile plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter profile in the Filter box, then select Profile from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.1

Using the Plugin

Here we have loaded the DEM as well as a raster (DRG) of the topography for the same quadrangle and zoomed in a bit to an area of interest:

The yellow line has been added to indicate where we will take the profile. While the Profile plugin allows you to interactively select the profile line it doesn’t display the line on the map.

To create a profile, first make sure the raster you want to profile is selected in the layer list, then activate the plugin from the Plugins toolbar by clicking on it. The cursor becomes a cross that you use to create the profile line: click at the start point, move to the end and click again. Once you have created the profile line, the plugin pops up the result:

The profile is taken from the northeast towards the southwest, based on where we clicked first. You can change the exaggeration of the profile by using the slider on the left. The X axis shows the distance along the profile line in map units and the Y axis shows the cell values from the raster—in this case, elevation in meters.

You can save the result as a PDF or SVG using the buttons at the bottom of the dialog.

The Statistics tab displays some information for the raster layer and the profile line:

If we had additional rasters loaded, we could use the Setup tab to add them to the profile analysis. This would display the results using the colors specified for each layer and we could compare them on the Profile tab.

This is just one of several QGIS plugins that deal with profiles. You can check out the rest of them using the Python Plugin installer.

1 The Profile plugin requires the Python module for QWT5. If you don’t have this installed, a warning will be displayed during the installation process.

QGIS Plugin of the Week: Points to Paths

This week we highlight the Points to Paths plugin, a handy way to convert a series of points into line features. This plugin lets you “connect the dots” based on an common attribute and a sequence field. The attribute field determines which points should be grouped together into a line. The sequence field determines the order in which the points will connected. The output from this plugin is a shapefile.

Let’s take a look at some example data. Here we have some fictional wildlife tracking data for two moose. The tracking data is in shapefile format, but you can use any vector format supported by QGIS. The tracking data is symbolized by our two animals: Moose1 and Moose2:

The moose_tracks layer has an animal tracking id field (animal_tid) and a sequence field (id). This is all we need to convert the individual observations into a line feature that represents the animals path.

Installing the Plugin

The Points to Paths plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter points to in the Filter box, then select Points to Paths from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.

Using the Plugin

Let’s convert the tracking data to paths. To get started, choose Plugins->Points to Paths from the menu or click on the Points to Paths tool on the Plugin toolbar. This brings up the PointsToPaths dialog box where we specify the paramaters needed to create the paths. Below is the completed dialog for our moose tracks:

The first drop-down box contains a list of the vector layers loaded in QGIS—in our case we have just one: moose_tracks. For the group field drop-down we chose the field that contains the tracking identifier for each animal. This determines which points will be selected and grouped to form an individual line. The point order field drop-down specifies the field that contains the ordering for the observations. In this case, the id field is incremented with each observation and can be used to construct the paths. We don’t have a date/time field in this data, but your observations may be sequenced in this way. The Python date format field allows you to specify a format string so the plugin can determine how to sequence your points based on date/time.

The last thing we need to specify is the output shapefile. You can do this by typing in the full path to a new shapefile or by using the Browse button.

With these options set, clicking the OK button will create the new shapefile containing the paths created from our point observations. Once the shapefile is created, the plugin gives you the option to add the new shapefile directly to QGIS.

The Result

The result of our simple example are shown below:

We symbolized the individual tracks using the Categorized renderer on the Style tab of the vector properties dialog. You can see we now have a track for each animal. The attribute table created by the plugin contains the following fields:

  • group - the name of the animal taken from the field we chose as the group field

  • begin - the value of the first point order field used to create the path

  • end - the value of the last point order field used to create the path

In our data, group contains the animal name, begin the value of the lowest id field for animal, and end contains the greatest id value. In a more typical data set, begin and end would contain the start and end date/time values for the observation. Labeling the observation points with our sequence field or date/time values would allow us to determine the direction of movement.

If you have point data that represent a movement of an object, this plugin is a great way to convert it into a path that can be used for visualization, analysis, or map composition.

QGIS Plugin of the Week: Points to Paths

This week we highlight the Points to Paths plugin, a handy way to convert a series of points into line features. This plugin lets you “connect the dots” based on an common attribute and a sequence field. The attribute field determines which points should be grouped together into a line. The sequence field determines the order in which the points will connected. The output from this plugin is a shapefile.

Let’s take a look at some example data. Here we have some fictional wildlife tracking data for two moose. The tracking data is in shapefile format, but you can use any vector format supported by QGIS. The tracking data is symbolized by our two animals: Moose1 and Moose2:

The moose_tracks layer has an animal tracking id field (animal_tid) and a sequence field (id). This is all we need to convert the individual observations into a line feature that represents the animals path.

Installing the Plugin

The Points to Paths plugin is installed like all other Python plugins. From the the Plugins menu in QGIS, choose Fetch Python Plugins. This brings up the plugin installer. To find the plugin, enter points to in the Filter box, then select Points to Paths from the list. Once it’s highlighted, click the Install plugin button. This will download the plugin from the repository, install it, and load it into QGIS.

Using the Plugin

Let’s convert the tracking data to paths. To get started, choose Plugins->Points to Paths from the menu or click on the Points to Paths tool on the Plugin toolbar. This brings up the PointsToPaths dialog box where we specify the paramaters needed to create the paths. Below is the completed dialog for our moose tracks:

The first drop-down box contains a list of the vector layers loaded in QGIS—in our case we have just one: moose_tracks. For the group field drop-down we chose the field that contains the tracking identifier for each animal. This determines which points will be selected and grouped to form an individual line. The point order field drop-down specifies the field that contains the ordering for the observations. In this case, the id field is incremented with each observation and can be used to construct the paths. We don’t have a date/time field in this data, but your observations may be sequenced in this way. The Python date format field allows you to specify a format string so the plugin can determine how to sequence your points based on date/time.

The last thing we need to specify is the output shapefile. You can do this by typing in the full path to a new shapefile or by using the Browse button.

With these options set, clicking the OK button will create the new shapefile containing the paths created from our point observations. Once the shapefile is created, the plugin gives you the option to add the new shapefile directly to QGIS.

The Result

The result of our simple example are shown below:

We symbolized the individual tracks using the Categorized renderer on the Style tab of the vector properties dialog. You can see we now have a track for each animal. The attribute table created by the plugin contains the following fields:

  • group – the name of the animal taken from the field we chose as the group field
  • begin – the value of the first point order field used to create the path
  • end – the value of the last point order field used to create the path

In our data, group contains the animal name, begin the value of the lowest id field for animal, and end contains the greatest id value. In a more typical data set, begin and end would contain the start and end date/time values for the observation. Labeling the observation points with our sequence field or date/time values would allow us to determine the direction of movement.

If you have point data that represent a movement of an object, this plugin is a great way to convert it into a path that can be used for visualization, analysis, or map composition.

QGIS Plugin of the Week: Time Manager

QGIS has a lot of plugins, including over 180 that have been contributed by users. If you aren’t using plugins, you are missing out on a lot that QGIS has to offer. I’m starting what I hope to be a regular feature: Plugin of the Week. This week we’ll take a look at Time Manager.


Time Manger and QGIS Users
Time Manager lets you browse spatial data that has a temporal component. Essentially this includes anything that changes location through time. Examples include:

  • Wildlife tracking
  • Vehicles
  • Storm centers
  • QGIS users

Data Preparation

Expanding on our last post about QGIS Users Around the World, we’ll use Time Manager to watch access to the QGIS Python plugin repository through time. If you refer to the previous post, you’ll see that all the IP addresses contacting the repository were extracted from the web server log and geocoded to get the approximate geographic coordinates. To use Time Manager all we need is the time for each access to the repository.

A important part (for our purpose) of the web server log entry looks like this:

66.58.228.196 - - [23/Oct/2011:21:17:54 +0000] "GET /repo/contributed HTTP/1.1" 200 256

Time Manager supports date/time in the following formats:

  • YYYY-MM-DD HH:MM:SS
  • YYYY-MM-DD HH:MM
  • YYYY-MM-DD

As you can see, this doesn’t work with the format in the web server log.

The geocoding process created a file containing IP address, country, city (where available), latitude and longitude. This file is used to create a Python dictionary to look up locations by IP address. Using this file and a bit of Python, the web server log entries were converted into a CSV file containing:

ip,date_time,country,latitude,longitude
66.58.228.196,2011-10-23 21:13:53,United States,61.2149,-149.258
66.58.228.196,2011-10-23 21:14:22,United States,61.2149,-149.258
66.58.228.196,2011-10-23 21:17:54,United States,61.2149,-149.258
66.58.228.196,2011-10-23 21:18:04,United States,61.2149,-149.258
...

The CSV file was first converted to a shapefile using the QGIS Delimited Text plugin. Performance with Time Manager was somewhat slow using a shapefile containing 134,171 locations. The shapefile was imported into a SpatiaLite database (you can do this using ogr2ogr or the SpatiaLite GUI).

Using Time Manager

To display the progression of access to the repository (and thus users of QGIS), we first have to have the Time Manager plugin installed.[1] Once installed, we enable it using the Plugin Manger.

As you can see from the screenshot above, Time Manager installs a new panel in QGIS that sits below the map canvas. You can set a number of options by clicking Settings; the most important being the layer to use in the visualization. For the QGIS users, we use the time_manager_req layer that was created from the web server logs. With the location and date/time data in the proper format, you can click the “Play” button to start the display. For each time interval, the plugin selects the appropriate entries and displays a frame for the duration specified in the settings.

You can use the time slider to move around or move the time interval forward or backward using the buttons on each end of the slider.

A really nice feature is the ability to export to video. At present this saves a PNG file and world file for each time interval. You can then use another software package to combine these to create a video animation of the time sequence. Once solution is to use mencoder[1]:

mencoder "mf://*.PNG" -mf fps=10 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4

Putting all this together gives us the following visualization of QGIS user activity from October 23 through December 19, 2011:



QGIS User Activity

You can see the “wave” of activity progress from east to west as the daylight hours come and go.

Summary

If you have spatial data with a date or time component, the Time Manager plugin provides a convenient way to visualize the temporal relationships.

[1]http://www.geofrogger.net/trac/wiki

QGIS Plugin of the Week: Time Manager

QGIS has a lot of plugins, including over 180 that have been contributed by users. If you aren’t using plugins, you are missing out on a lot that QGIS has to offer. I’m starting what I hope to be a regular feature: Plugin of the Week. This week we’ll take a look at Time Manager.

Time Manger and QGIS Users Time Manager lets you browse spatial data that has a temporal component. Essentially this includes anything that changes location through time. Examples include:

  • Wildlife tracking
  • Vehicles
  • Storm centers
  • QGIS users

Data Preparation

Expanding on our last post about QGIS Users Around the World, we’ll use Time Manager to watch access to the QGIS Python plugin repository through time. If you refer to the previous post, you’ll see that all the IP addresses contacting the repository were extracted from the web server log and geocoded to get the approximate geographic coordinates. To use Time Manager all we need is the time for each access to the repository.

A important part (for our purpose) of the web server log entry looks like this:

192.168.1.2 - - [23/Oct/2011:21:17:54 +0000] "GET /repo/contributed HTTP/1.1" 200 256

Time Manager supports date/time in the following formats:

  • YYYY-MM-DD HH:MM:SS

  • YYYY-MM-DD HH:MM

  • YYYY-MM-DD

As you can see, this doesn’t work with the format in the web server log.

The geocoding process created a file containing IP address, country, city (where available), latitude and longitude. This file is used to create a Python dictionary to look up locations by IP address. Using this file and a bit of Python, the web server log entries were converted into a CSV file containing:

ip,date_time,country,latitude,longitude
192.168.1.2,2011-10-23 21:13:53,United States,61.2149,-149.258
192.168.1.2,2011-10-23 21:14:22,United States,61.2149,-149.258
192.168.1.2,2011-10-23 21:17:54,United States,61.2149,-149.258
192.168.1.2,2011-10-23 21:18:04,United States,61.2149,-149.258
...

The CSV file was first converted to a shapefile using the QGIS Delimited Text plugin. Performance with Time Manager was somewhat slow using a shapefile containing 134,171 locations. The shapefile was imported into a SpatiaLite database (you can do this using ogr2ogr or the SpatiaLite GUI).

Using Time Manager

To display the progression of access to the repository (and thus users of QGIS), we first have to have the Time Manager plugin installed.[1] Once installed, we enable it using the Plugin Manger.

As you can see from the screenshot above, Time Manager installs a new panel in QGIS that sits below the map canvas. You can set a number of options by clicking Settings; the most important being the layer to use in the visualization. For the QGIS users, we use the time_manager_req layer that was created from the web server logs. With the location and date/time data in the proper format, you can click the “Play” button to start the display. For each time interval, the plugin selects the appropriate entries and displays a frame for the duration specified in the settings.

You can use the time slider to move around or move the time interval forward or backward using the buttons on each end of the slider.

A really nice feature is the ability to export to video. At present this saves a PNG file and world file for each time interval. You can then use another software package to combine these to create a video animation of the time sequence. Once solution is to use mencoder[1]:

mencoder "mf://*.PNG" -mf fps=10 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4

Putting all this together gives us the following visualization of QGIS user activity from October 23 through December 19, 2011:

You can see the “wave” of activity progress from east to west as the daylight hours come and go.

Summary

If you have spatial data with a date or time component, the Time Manager plugin provides a convenient way to visualize the temporal relationships.

[1] http://www.geofrogger.net/trac/wiki

QGIS Users Around the World

One of the difficult things to track in the open source world is the number of people who actually use your software. In the proprietary commercial world you have licenses, invoices, and so forth. In the case of QGIS, we can track the total number of downloads from qgis.org, but this doesn’t represent the total installed base. It is impossible to accurately determine the actual number of people using QGIS, but we can get an approximation of the number and where they are in the world.

The analysis was done using the log files from the QGIS contributed repository:

  • The IP address of each entry that retrieved the plugin list from the server represents one or more users—these IPs were collected into a unique list

  • Using a Python script, each IP address in the log was geocoded to get the approximate latitude and longitude of the user

  • The IP address, country, latitude, and longitude were written to a CSV file

  • The CSV file was converted to a Spatialite layer to create the map of users

The map represents 35,603 unique IP addresses of users that accessed the repository between October 23, 2011 and December 17, 2011.

The geocoding process varies in precision—some IPs are located to the city level while others only return a general location for the country.

Some assumptions and observations:

  • Most (maybe all) users make use of Python plugins and therefore access the contributed repository at some point

  • Country-level points (blue) on the map represent more than one user

  • Some points represent organizations that use a single IP for all users accessing the Internet. These points will represent more than one user

  • Some users may access the repository from more than one IP address

So how many people use QGIS? At the very minimum, 35,000. We know that the downloads of just the Windows version exceeded 100,000. Given that there are 7,183 IP addresses that are generalized to a country location, we can safely assume that the number of actual users is much higher than that.

Considering the number of points that represent an organization and those that represent a country location, I think we can safely assume that the number of QGIS users easily exceeds 100,000 worldwide.

QGIS Users Around the World

One of the difficult things to track in the open source world is the number of people who actually use your software. In the proprietary commercial world you have licenses, invoices, and so forth. In the case of QGIS, we can track the total number of downloads from qgis.org, but this doesn’t represent the total installed base. It is impossible to accurately determine the actual number of people using QGIS, but we can get an approximation of the number and where they are in the world.

The analysis was done using the log files from the QGIS contributed repository:

  • The IP address of each entry that retrieved the plugin list from the server represents one or more users—these IPs were collected into a unique list
  • Using a Python script, each IP address in the log was geocoded to get the approximate latitude and longitude of the user
  • The IP address, country, latitude, and longitude were written to a CSV file
  • The CSV file was converted to a Spatialite layer to create the map of users

The map represents 35,603 unique IP addresses of users that accessed the repository between October 23, 2011 and December 17, 2011.

The geocoding process varies in precision—some IPs are located to the city level while others only return a general location for the country.

Some assumptions and observations:

  • Most (maybe all) users make use of Python plugins and therefore access the contributed repository at some point
  • Country-level points (blue) on the map represent more than one user
  • Some points represent organizations that use a single IP for all users accessing the Internet. These points will represent more than one user
  • Some users may access the repository from more than one IP address

So how many people use QGIS? At the very minimum, 35,000. We know that the downloads of just the Windows version exceeded 100,000. Given that there are 7,183 IP addresses that are generalized to a country location, we can safely assume that the number of actual users is much higher than that.

Considering the number of points that represent an organization and those that represent a country location, I think we can safely assume that the number of QGIS users easily exceeds 100,000 worldwide.

Using git With Multiple QGIS Branches

This post is for those of you that build QGIS on a regular basis and want to keep up with everything going on in the current release branches (1.7.2 and 1.8) as well as the master branch that will eventually become version 2.0.

While you can do all your work in one clone, this method has a couple of advantages, at the expense of a bit of disk space:

  1. Quicker compiles compared to branch switching, especially if you are using ccache
  2. Less likelihood of making a merge mess when switching branches

The basic steps are:

  1. Login to github and clone the QGIS repository (https://github.com/qgis/Quantum-GIS)
  2. Create a working copy of your github clone on your machine
  3. Add a reference to the upstream repository
  4. Fetch and merge (if required) from the upstream repository
  5. Create a new clone for the branch by cloning the working copy created in step 2
  6. Change to the branch clone directory
  7. Add the upstream remote
  8. Fetch from upstream
  9. Create the tracking branch
  10. Checkout the branch

It’s simpler than it sounds—the following steps should work on any platform and assume you have already created your own clone of the QGIS repository on github.

First make a directory for development, change to it, and fetch a copy of your clone of QGIS from github (this will take a while):

gsherman@dork:~$ mkdir qgis_dev
gsherman@dork:~$ cd qgis_dev
gsherman@dork:~/qgis_dev$ git clone [email protected]:g-sherman/Quantum-GIS.git
Cloning into Quantum-GIS...
remote: Counting objects: 183812, done.
remote: Compressing objects: 100% (42255/42255), done.
remote: Total 183812 (delta 140627), reused 183281 (delta 140221)
Receiving objects: 100% (183812/183812), 240.80 MiB | 1.19 MiB/s, done.
Resolving deltas: 100% (140627/140627), done.

Now change to your new clone directory and add the upstream repository (the QGIS repo on github):

gsherman@dork:~/qgis_dev$ cd Quantum-GIS/
gsherman@dork:~/qgis_dev/Quantum-GIS$ git remote add upstream [email protected]:qgis/Quantum-GIS.git

We can then list our config to see that the remote was added:

gsherman@dork:~/qgis_dev/Quantum-GIS$ git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
[email protected]:g-sherman/Quantum-GIS.git
branch.master.remote=origin
branch.master.merge=refs/heads/master
[email protected]:qgis/Quantum-GIS.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*

Then we do a fetch from the QGIS repo to make sure things are up to date:

gsherman@dork:~/qgis_dev/Quantum-GIS$ git fetch upstream

If your clone of the QGIS repository on github is not brand new, you should do a merge before proceeding:

gsherman@dork:~/qgis_dev/Quantum-GIS$ git merge upstream/master

Now we can create a new clone for the 1.7.2 branch using our local master:

gsherman@dork:~/qgis_dev/Quantum-GIS$ cd ..
gsherman@dork:~/qgis_dev$ git clone ./Quantum-GIS Quantum-GIS-1_7_2
Cloning into Quantum-GIS-1_7_2...
done.

Now we need to add the remote for the main QGIS repository:

gsherman@dork:~/qgis_dev$ cd Quantum-GIS-1_7_2/
gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git remote add upstream [email protected]:qgis/Quantum-GIS.git

The next step is to fetch from upstream to make sure we have references to the branches:

gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git fetch upstream
 * [new branch]      dev-threading -> upstream/dev-threading
 * [new branch]      master     -> upstream/master
 * [new branch]      release-0_0_11 -> upstream/release-0_0_11
 * [new branch]      release-0_0_12 -> upstream/release-0_0_12
 ...
 * [new branch]      release-1_7_1 -> upstream/release-1_7_1
 * [new branch]      release-1_7_2 -> upstream/release-1_7_2
 * [new branch]      release-1_8 -> upstream/release-1_8

Now we create the branch to track the release of interest—in this case 1.7.2:

gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git branch --track release-1_7_2 upstream/release-1_7_2
Branch release-1_7_2 set up to track remote branch release-1_7_2 from upstream.

The last step is to check out the branch which should go pretty quick:

gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git checkout release-1_7_2
Checking out files: 100% (1809/1809), done.
Switched to branch 'release-1_7_2'

You are now ready to build the 1.7.2 release branch. Repeat the process for any other branches you want to track.

Using git With Multiple QGIS Branches

This post is for those of you that build QGIS on a regular basis and want to keep up with everything going on in the current release branches (1.7.2 and 1.8) as well as the master branch that will eventually become version 2.0.

While you can do all your work in one clone, this method has a couple of advantages, at the expense of a bit of disk space:

  1. Quicker compiles compared to branch switching, especially if you are using ccache
  2. Less likelihood of making a merge mess when switching branches

The basic steps are:

  1. Login to github and clone the QGIS repository (https://github.com/qgis/Quantum-GIS)
  2. Create a working copy of your github clone on your machine
  3. Add a reference to the upstream repository
  4. Fetch and merge (if required) from the upstream repository
  5. Create a new clone for the branch by cloning the working copy created in step 2
  6. Change to the branch clone directory
  7. Add the upstream remote
  8. Fetch from upstream
  9. Create the tracking branch
  10. Checkout the branch

It’s simpler than it sounds—the following steps should work on any platform and assume you have already created your own clone of the QGIS repository on github.

First make a directory for development, change to it, and fetch a copy of your clone of QGIS from github (this will take a while):

gsherman@dork:~$ mkdir qgis_dev
gsherman@dork:~$ cd qgis_dev
gsherman@dork:~/qgis_dev$ git clone [email protected]:g-sherman/Quantum-GIS.git
Cloning into Quantum-GIS...
remote: Counting objects: 183812, done.
remote: Compressing objects: 100% (42255/42255), done.
remote: Total 183812 (delta 140627), reused 183281 (delta 140221)
Receiving objects: 100% (183812/183812), 240.80 MiB | 1.19 MiB/s, done.
Resolving deltas: 100% (140627/140627), done.

Now change to your new clone directory and add the upstream repository (the QGIS repo on github):

gsherman@dork:~/qgis_dev$ cd Quantum-GIS/
gsherman@dork:~/qgis_dev/Quantum-GIS$ git remote add upstream [email protected]:qgis/Quantum-GIS.git

We can then list our config to see that the remote was added:

gsherman@dork:~/qgis_dev/Quantum-GIS$ git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
[email protected]:g-sherman/Quantum-GIS.git
branch.master.remote=origin
branch.master.merge=refs/heads/master
[email protected]:qgis/Quantum-GIS.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*

Then we do a fetch from the QGIS repo to make sure things are up to date:

gsherman@dork:~/qgis_dev/Quantum-GIS$ git fetch upstream

If your clone of the QGIS repository on github is not brand new, you should do a merge before proceeding:

gsherman@dork:~/qgis_dev/Quantum-GIS$ git merge upstream/master

Now we can create a new clone for the 1.7.2 branch using our local master:

gsherman@dork:~/qgis_dev/Quantum-GIS$ cd ..
gsherman@dork:~/qgis_dev$ git clone ./Quantum-GIS Quantum-GIS-1_7_2
Cloning into Quantum-GIS-1_7_2...
done.

Now we need to add the remote for the main QGIS repository:

gsherman@dork:~/qgis_dev$ cd Quantum-GIS-1_7_2/
gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git remote add upstream [email protected]:qgis/Quantum-GIS.git

The next step is to fetch from upstream to make sure we have references to the branches:

gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git fetch upstream
* [new branch] dev-threading -> upstream/dev-threading
* [new branch] master -> upstream/master
* [new branch] release-0_0_11 -> upstream/release-0_0_11
* [new branch] release-0_0_12 -> upstream/release-0_0_12
...
* [new branch] release-1_7_1 -> upstream/release-1_7_1
* [new branch] release-1_7_2 -> upstream/release-1_7_2
* [new branch] release-1_8 -> upstream/release-1_8

Now we create the branch to track the release of interest—in this case 1.7.2:

gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git branch --track release-1_7_2 upstream/release-1_7_2
Branch release-1_7_2 set up to track remote branch release-1_7_2 from upstream.

The last step is to check out the branch which should go pretty quick:

gsherman@dork:~/qgis_dev/Quantum-GIS-1_7_2$ git checkout release-1_7_2
Checking out files: 100% (1809/1809), done.
Switched to branch 'release-1_7_2'

You are now ready to build the 1.7.2 release branch. Repeat the process for any other branches you want to track.

Using the QGIS Plugin Builder

The Plugin Builder allows you to quickly create a skeleton Python plugin by generating all that boring boilerplate that every plugin requires.

Here is a short video showing how to create, compile, and install a new plugin.

For more information, see QGIS Workshop Documentation and the PyQGIS Cookbook.

Using the QGIS Plugin Builder

The Plugin Builder allows you to quickly create a skeleton Python plugin by generating all that boring boilerplate that every plugin requires.

Here is a short video showing how to create, compile, and install a new plugin.

For more information, see QGIS Workshop Documentation and the PyQGIS Cookbook.

Search QGIS IRC Logs

I added a simple feature that allows you to search the IRC logs from #qgis back to May 10, 2006.

The search is case sensitive and will return a list of all matches. Not too smart but it will get you close to what you want.

See the link at http://irclogs.geoapt.com/qgis

Search QGIS IRC Logs

I added a simple feature that allows you to search the IRC logs from #qgis back to May 10, 2006.

The search is case sensitive and will return a list of all matches. Not too smart but it will get you close to what you want.

See the link at http://irclogs.geoapt.com/qgis

History of QGIS Committers

Using the git log leading up to the 1.7 release (June 2011) I put together a graphic that shows the growth of committers working on the project.

QGIS Committers over Time


In 2002 we had two people (me alone up until October). You can see significant jumps in developer interest in 2004 and 2008:

  • In 2004 there were a number of releases that added significant functionality
  • Following an announcement at FOSS4G 2007 in Victoria we released 0.9 which included Python support. This opened up plugin development to a whole new group of people and contributed to growth in 2008

The graphic includes all committers including documentation writers, translators, and developers. In addition, it doesn’t cover the whole spectrum of people who have contributed code and patches that were applied by project developers. There are a lot more people involved in the care and feeding of QGIS than the 46 represented on the graph.

What does it mean? QGIS continues to see growth and interest from the development and user communities. It will be interesting to see if we get a new bump following the just concluded FOSS4G conference in Denver.

History of QGIS Committers

Using the git log leading up to the 1.7 release (June 2011) I put together a graphic that shows the growth of committers working on the project.

In 2002 we had two people (me alone up until October). You can see significant jumps in developer interest in 2004 and 2008:

  • In 2004 there were a number of releases that added significant functionality
  • Following an announcement at FOSS4G 2007 in Victoria we released 0.9 which included Python support. This opened up plugin development to a whole new group of people and contributed to growth in 2008

The graphic includes all committers including documentation writers, translators, and developers. In addition, it doesn’t cover the whole spectrum of people who have contributed code and patches that were applied by project developers. There are a lot more people involved in the care and feeding of QGIS than the 46 represented on the graph.

What does it mean? QGIS continues to see growth and interest from the development and user communities. It will be interesting to see if we get a new bump following the just concluded FOSS4G conference in Denver.

Importing a DBF containing X-Y Values into QGIS

Suppose you have a DBF (.dbf) file containing X and Y values that you want to import and save as a spatial layer.

QGIS doesn’t support direct import of a DBF file as a map layer, however, we can use some command line magic to convert it to a CSV file and then use the Delimited Text plugin to get the job done.

Your DBF file should have an id for each record and fields containing X and Y values. If it has additional fields that should be OK as well.

First convert the DBF to a comma delimited file using ogr2ogr:
ogr2ogr -f CSV my_csv my_data.dbf

If you don’t have ogr2ogr see http://www.gdal.org/index.html.

This will create my_data.csv in the my_csv directory. You are now ready to bring it into QGIS.

Here are the steps to import the CSV:

  1. Start QGIS
  2. If not already enabled, use the plugin manager to enable the Delimited Text plugin
  3. Click on the Delimited Text icon in the Plugin toolbar or choose it from the Plugins menu
  4. Browse to the location of your CSV file
  5. Enter a name for the layer
  6. Under Selected delimiters, check Comma
  7. If your X and Y fields aren’t automatically determined, set them using the drop-down boxes
  8. The sample text should show how the file is being parsed—if it looks right click OK, otherwise adjust the settings
  9. The layer is added to QGIS

Delmited Text plugin ready to import CSV

At this point the layer behaves pretty much like any other QGIS layer. To save it as a shapefile, right click on its name in the legend and choose Save as…

Importing a DBF containing X-Y Values into QGIS

Suppose you have a DBF (.dbf) file containing X and Y values that you want to import and save as a spatial layer.

QGIS doesn’t support direct import of a DBF file as a map layer, however, we can use some command line magic to convert it to a CSV file and then use the Delimited Text plugin to get the job done.

Your DBF file should have an id for each record and fields containing X and Y values. If it has additional fields that should be OK as well.

First convert the DBF to a comma delimited file using ogr2ogr:

ogr2ogr -f CSV my_csv my_data.dbf

If you don’t have ogr2ogr see http://www.gdal.org/index.html.

This will create my_data.csv in the my_csv directory. You are now ready to bring it into QGIS.

Here are the steps to import the CSV:

  1. Start QGIS

  2. If not already enabled, use the plugin manager to enable the Delimited Text plugin

  3. Click on the Delimited Text icon in the Plugin toolbar or choose it from the Plugins menu

  4. Browse to the location of your CSV file

  5. Enter a name for the layer

  6. Under Selected delimiters, check Comma

  7. If your X and Y fields aren’t automatically determined, set them using the drop-down boxes

  8. The sample text should show how the file is being parsed—if it looks right click OK, otherwise adjust the settings

  9. The layer is added to QGIS

Delmited Text plugin ready to import CSV

At this point the layer behaves pretty much like any other QGIS layer. To save it as a shapefile, right click on its name in the legend and choose Save as…

Developing QGIS Plugins with git

Writing a QGIS plugin is not overly complicated but represents a bit of work. Using
git in conjunction with your development efforts can make sure your investment in
coding time is preserved.

Development Tools

The QGIS project team has set up a central location for plugin development which includes pretty much everything you need to develop and support your plugins, including:

  • Issue tracking
  • Wiki
  • Documents
  • Repository

The repository feature allows you to create a central place to store your plugin code using git. Others can clone your repository and contribute through patches or pull requests.

Creating a Plugin

The chore of setting up the boilerplate for a plugin is made simple by using the Plugin Builder. Previously this was a web application but it has now been replaced by a QGIS plugin aptly named Plugin Builder. You can install Plugin Builder from within QGIS by selecting Fetch Python Plugins… from the Plugins menu.

Once Plugin Builder is installed you can quickly create a starter plugin that implements a simple dialog box with OK and Cancel buttons. The plugin created by Plugin Builder is fully functional—it will load in QGIS but not do anything useful until you customize it.

Setting up the Workflow

You have a couple of options for setting up your development directory and workflow:

  1. Copy your plugin template to the QGIS plugin directory, initialize the git repository, and develop from there.
  2. Work within your plugin template directory that was created by Plugin Builder (not within the QGIS plugin directory)

Option one is very convenient as long as you don’t test the uninstall feature of your plugin. This will delete your entire plugin directory and git repository—not what we really want.

Option two is safer, however to test your plugin you have to continually copy from your development area to your QGIS plugin directory. Alternatively you could make commits and pull from your development area to the copy (assuming it is a git repo) in the QGIS plugin directory. If you are on a unix based system you could also create a Makefile to deploy the plugin for you.

The best solution is to use option two and use the QGIS_PLUGINPATH environment variable to point to your development directory. When present, QGIS_PLUGINPATH tells QGIS to search additional directories for plugins. Going this route allows you to develop in the directory created by Plugin Builder and test your plugin without any copying or pulling. The upside to this is since your plugin wasn’t installed through the Plugin Installer it can’t be uninstalled accidentally. When you are ready to test the uninstall and unloading of your plugin you can copy it to the main QGIS plugin directory.

Note: If you are using Windows there was a problem specifying QGIS_PLUGINPATH with colons in the path. This issue is fixed in revision 15073 and will make it into the next release.

No matter how you implement your workflow I suggest creating a repository on the QGIS hub (http://hub.qgis.org) or github.com.

Summary

Here is a summary of the steps to get started. We’ll assume your new plugin is named zoomer:

  1. Install Plugin Builder
  2. Create a directory that will contain all your plugins, for example my_plugins
  3. Create your plugin template using Plugin Builder. Be sure to select my_plugins when Plugin Builder asks where to create your plugin.
  4. Change to your plugin directory (e.g. my_plugins/zoomer) created by Plugin Buidler and create a git repository using:
    git init
  5. Set the QGIS_PLUGINPATH evironment variable to point to the directory containing your plugin directory (my_plugins). Be sure to use the full path to my_plugins
  6. Start QGIS and use the Plugin Manager (Manage Plugins… from the Plugins menu) to enable your plugin. If it doesn’t show up in the list of plugins check to make sure you have set QGIS_PLUGINPATH correctly.
  7. Develop away, testing as you go. Make sure to commit changes regularly and push them to your repository on hub.qgis.org.

If you are new to git, take a look at the Pro Git book at http://progit.org/.

For help on developing QGIS plugins with Python, see the PyQGIS Cookbook.

Back to Top

Sustaining Members