Related Plugins and Tags

QGIS Planet

User history added to osm-reporter app

This weekend I implemented a new feature for my 'just for fun' project osm-reporter. The feature implements timeline reporting for Open Street Map contributors. Its probably easiest to explain with a screenshot:

OSM-Reporter with timelines

Here is another one showing a few charts together:

OSM-Reporter with timelines

I added the feature because I wanted to see how many person days were involved in data gathering for a particular area and feature type. It does have some limitations - it ignores deletion and ownership transfer of features. It does however provide a nice quick overview of effort. Try it on your own neighbourhood and see how much work went into the OSM coverage for your area!

I've also had some really awesome contributions from Yohan Bonifiace (added leaflet support, feature type switching, extent urls) and Sun Ning (added heatmap support). Its really great making a small, simple and limited scope project and seeing it grow with random hacks of kindness from strangers! Here is a little screenshot of the heatmap feature:

Heatmaps

I hope you all enjoy the new version, and look forward to more improvements and suggestions from the community. Its all freely available from my github repository. You can test out the current version of the software by visiting http://osm.linfiniti.com.

Group Stats Tutorial

Group Stats is a plugin for QGIS which makes it easy to calculate statistics for feature groups in a vector layer. Note that the plugin is still marked “experimental” so you have to allow experimental plugins in order to install it. I tried this plugin for the first time today and decided to write this post because it didn’t seem immediately obvious how to use it.

The plugin button is added to the vector toolbar and of course you can access it via vector menu.

groupstatsicon

The example I want to show is: How to calculate the total area of of each Corine Land Cover (CLC) class per state.

corineAT

After adding state information to the CLC datasets by intersecting CLC and state geometries from Natural Earth we can get started with Group Stats.

groupstats

The big area on the left will display the results. The input fields are on the right. The general idea is to drag and drop fields and/or functions into the “columns”, “rows” and “values” sections. (Double-clicking field names does not do anything.) To remove fields again, you have to drop them back into the field list.

To calculate the total area of of each Corine Land Cover (CLC) class per state, I chose land cover classes as columns, state names as rows and sum of areas as values:

groupstatsclc

It’s also possible to add multiple functions in the columns/rows input sections to calculate different statistics at once:

groupstats_functions

Group Stats can be used in many cases that otherwise require a Spreadsheet software. The results can be exported to CSV easily. Usability could certainly be improved by allowing common interactions such as removing fields by pressing the delete key or adding fields by double-clicking.


InaSAFE wins Open Source ‘Rookie of the Year’ award

A couple of weeks ago I had the pleasure of doing an interview on behalf of the InaSAFE project as part of the selection process for the Black Duck Software ‘open source rookies of the year’ competition. A week later we heard that we had made it into the top 10! The award is based... Read more »

InaSAFE wins Open Source ‘Rookie of the Year’ award

image0

A couple of weeks ago I had the pleasure of doing an interview on behalf of the InaSAFE project as part of the selection process for the Black Duck Software 'open source rookies of the year' competition. A week later we heard that we had made it into the top 10! The award is based on a selection or projects from the popular ohlog.net web site:

"Using data on open source projects from Ohloh.net and the Black Duck® KnowledgeBase™, Black Duck reviewed thousands of open source projects that were initiated in 2012 to select the fifth annual Open Source Rookies of the Year. Using a weighted scoring system, points were awarded based on project activity, commits pace, project team attributes and other factors. Black Duck determined the top 10 Rookie projects following an audit of its findings and normalization of scores."

You can see all the winners listed at the official competition page here. We were also fortunate to be mentioned in Wired, DirectionsMag and various other places.

We have worked incredibly hard over the last year to make the InaSAFE plugin for QGIS, with a team of dedicated developers from AUSAID, WorldBank, Linfiniti, opengis.ch and a number of other developers and contributors, so it is really great to receive this acknowledgement! Here is looking to another great year of working on InaSAFE for 2013!

“We are pleased to recognize InaSAFE as one of the 2012 Open Source Rookies of the Year,” said Tim Yeaton, CEO and president, Black Duck Software. “The Rookies demonstrate how community innovation, particularly within the JavaScript and mobile projects, mirrors the need for innovation in web experiences, mobile devices and enterprise application. Being able to identify and showcase these up-and-coming open source projects is an important part of our mission at Black Duck to bring together the open source community and businesses around the world.”

Past winners of the prestigious award include Twitter Bootstrap, Cloud Foundry, Mozilla Persona (formerly known as BrowserID), Red Hat OpenShift, Eclipse Orion, Apache Rave, Salt Stack, OpenStack, Diaspora and many other notable projects.

Updating Attribute Data

Browser Window:

QGIS Browser Window

QGIS Browser Window

Buttons on the bottom from left to right are:-

  • Unselect All
  • Move Selection to Top
  • Invert Selection
  • Copy Selected Rows to Clipboard
  • Zoom Map to the Selected Rows
  • Pan Map to the Selected Rows
  • Toggle Editing
  • Save Edits
  • Delete Selected Features (rows)
  • New Column
  • Delete Column
  • Open Field Calculator
  • Look For (enter search terms) in (use the pull down to select the column to search)

The attribute table has several duplicate rows. To delete them

  1. Press the Toggle Editing to begin an Edit Session
  2. Press the Delete Columns button
  3. Select the column(s) and press OK

To add new columns:

  1. Press the New Column button
  2. Enter the details for the new column
Add column dialog

Add column dialog

Update Columns with the Field Calculator

I want to update the three new columns I’ve added. To update columns:

  1. Right click on the layer in the Layer Panel
  2. Select View Attribute Table
  3. Press the Toggle Editing button to begin an Edit Session
  4. Press the Field Calculator
QGIS Field Calculator

QGIS Field Calculator

  1. Select to either create a new field or to update an existing field. If you’re updating an existing field then use the pull down to select the field
  2. Complete the Expression builder by either double clicking functions or typing the expression.
  3. Functions include:
  • Operators e.g.+-*/ etc
  • Maths e.g. cos, sin etc
  • Conversions e.g. to integer, to string, to decimal
  • Geometry e.g. feature’s length, area, perimeter, x, y
  • Record – Row number or ID
  • Fields and Values

QGIS plugin InaSAFE wins Open Source award

How cool is this! The InaSAFE project, a QGIS plugin, has just won a Open Source Rookie Of the Year award. The award is given by Black Duck who make products such as ohloh.net.

The award also got mentioned in Wired.

Talk about some awesome publicity of QGIS and how it can be used for serious tasks.

QGIS plugin InaSAFE wins Open Source award

How cool is this! The InaSAFE project, a QGIS plugin, has just won a Open Source Rookie Of the Year award. The award is given by Black Duck who make products such as ohloh.net.

The award also got mentioned in Wired.

Talk about some awesome publicity of QGIS and how it can be used for serious tasks.

QGIS plugin InaSAFE wins Open Source award

How cool is this! The InaSAFE project, a QGIS plugin, has just won a Open Source Rookie Of the Year award. The award is given by Black Duck who make products such as ohloh.net.

The award also got mentioned in Wired.

Talk about some awesome publicity of QGIS and how it can be used for serious tasks.

New Site! WordPress to Jekyll and Amazon S3

Like a lot of other people I have decided to move my blog off WordPress and onto a static page based system, mainly Jekyll. I'm not going to go over all the reasons in detail, you can always Google It as I'm swapping for most of the same reasons that everyone else is.

In case you don't like Google, or want my spin, this is a summary of the reasons that made me switch:

  • Static site - Blogs are static content. I don't need any fancy PHP to generate dynamic content on the fly.

  • Google Analytics - I'm a sucker for stats. WordPress had them but I want more.

  • GitHub - It's just text after all. I can keep my site on GitHub and version it.

  • I really hate the WordPress blog post editor - You can't tell me that you like it. Now I just write in my posts in Vim, Sublime Text 2, or whatever, and run Jekyll-S3 to push it up. Done.

  • Theme - I have always switched around my theme on WordPress because I was never really happy. Now I can just control it how I like. (I wasn't go to pay WordPress for the ability to tweak the stylesheets) - However because I am not really good with design I'm going for a simple look. More content less flair.

  • Amazon S3 - Free Hosting! Win! (Well free for a bit then cheap as hell after that)

So that's pretty much it. Was it worth it? I guess only time will tell. Now just to get my search ranking back up.

P.S As I have said I'm not great at design so if you have any feedback let me know.

New Site! WordPress to Jekyll and Amazon S3

Like a lot of other people I have decided to move my blog off WordPress and onto a static page based system, mainly Jekyll. I'm not going to go over all the reasons in detail, you can always Google It as I'm swapping for most of the same reasons that everyone else is.

In case you don't like Google, or want my spin, this is a summary of the reasons that made me switch:

  • Static site - Blogs are static content. I don't need any fancy PHP to generate dynamic content on the fly.

  • Google Analytics - I'm a sucker for stats. WordPress had them but I want more.

  • GitHub - It's just text after all. I can keep my site on GitHub and version it.

  • I really hate the WordPress blog post editor - You can't tell me that you like it. Now I just write in my posts in Vim, Sublime Text 2, or whatever, and run Jekyll-S3 to push it up. Done.

  • Theme - I have always switched around my theme on WordPress because I was never really happy. Now I can just control it how I like. (I wasn't go to pay WordPress for the ability to tweak the stylesheets) - However because I am not really good with design I'm going for a simple look. More content less flair.

  • Amazon S3 - Free Hosting! Win! (Well free for a bit then cheap as hell after that)

So that's pretty much it. Was it worth it? I guess only time will tell. Now just to get my search ranking back up.

P.S As I have said I'm not great at design so if you have any feedback let me know.

New Site! WordPress to Jekyll and Amazon S3

Like a lot of other people I have decided to move my blog off WordPress and onto a static page based system, mainly Jekyll. I'm not going to go over all the reasons in detail, you can always Google It as I'm swapping for most of the same reasons that everyone else is.

In case you don't like Google, or want my spin, this is a summary of the reasons that made me switch:

  • Static site - Blogs are static content. I don't need any fancy PHP to generate dynamic content on the fly.

  • Google Analytics - I'm a sucker for stats. WordPress had them but I want more.

  • GitHub - It's just text after all. I can keep my site on GitHub and version it.

  • I really hate the WordPress blog post editor - You can't tell me that you like it. Now I just write in my posts in Vim, Sublime Text 2, or whatever, and run Jekyll-S3 to push it up. Done.

  • Theme - I have always switched around my theme on WordPress because I was never really happy. Now I can just control it how I like. (I wasn't go to pay WordPress for the ability to tweak the stylesheets) - However because I am not really good with design I'm going for a simple look. More content less flair.

  • Amazon S3 - Free Hosting! Win! (Well free for a bit then cheap as hell after that)

So that's pretty much it. Was it worth it? I guess only time will tell. Now just to get my search ranking back up.

P.S As I have said I'm not great at design so if you have any feedback let me know.

New Site! WordPress to Jekyll and Amazon S3

Like a lot of other people I have decided to move my blog off WordPress and onto a static page based system, mainly Jekyll. I'm not going to go over all the reasons in detail, you can always Google It as I'm swapping for most of the same reasons that everyone else is.

In case you don't like Google, or want my spin, this is a summary of the reasons that made me switch:

  • Static site - Blogs are static content. I don't need any fancy PHP to generate dynamic content on the fly.

  • Google Analytics - I'm a sucker for stats. WordPress had them but I want more.

  • GitHub - It's just text after all. I can keep my site on GitHub and version it.

  • I really hate the WordPress blog post editor - You can't tell me that you like it. Now I just write in my posts in Vim, Sublime Text 2, or whatever, and run Jekyll-S3 to push it up. Done.

  • Theme - I have always switched around my theme on WordPress because I was never really happy. Now I can just control it how I like. (I wasn't go to pay WordPress for the ability to tweak the stylesheets) - However because I am not really good with design I'm going for a simple look. More content less flair.

  • Amazon S3 - Free Hosting! Win! (Well free for a bit then cheap as hell after that)

So that's pretty much it. Was it worth it? I guess only time will tell. Now just to get my search ranking back up.

P.S As I have said I'm not great at design so if you have any feedback let me know.

New Site! WordPress to Jekyll and Amazon S3

Like a lot of other people I have decided to move my blog off WordPress and onto a static page based system, mainly Jekyll. I'm not going to go over all the reasons in detail, you can always Google It as I'm swapping for most of the same reasons that everyone else is.

In case you don't like Google, or want my spin, this is a summary of the reasons that made me switch:

  • Static site - Blogs are static content. I don't need any fancy PHP to generate dynamic content on the fly.

  • Google Analytics - I'm a sucker for stats. WordPress had them but I want more.

  • GitHub - It's just text after all. I can keep my site on GitHub and version it.

  • I really hate the WordPress blog post editor - You can't tell me that you like it. Now I just write in my posts in Vim, Sublime Text 2, or whatever, and run Jekyll-S3 to push it up. Done.

  • Theme - I have always switched around my theme on WordPress because I was never really happy. Now I can just control it how I like. (I wasn't go to pay WordPress for the ability to tweak the stylesheets) - However because I am not really good with design I'm going for a simple look. More content less flair.

  • Amazon S3 - Free Hosting! Win! (Well free for a bit then cheap as hell after that)

So that's pretty much it. Was it worth it? I guess only time will tell. Now just to get my search ranking back up.

P.S As I have said I'm not great at design so if you have any feedback let me know.

Queries in QGIS pt2 – Spatial Query

In the previous post (Queries in QGIS pt 1 – Attribute Queries), I showed how to select features based on their attribute data, e.g. select shops which have the address entered as London. Now let’s imagine there isn’t an address attribute, or alternatively, we want to select features within flood plains for example, or identify areas of woodland that have high voltage power lines running through them.

Layers for spatial query

Spatial selection selects features in one layer based on their spatial relationship to features in another layer

To begin a spatial query either:

  • Use the menu to select Vector, Spatial Query
  • Press the Spatial Query button

The spatial query dialogue box:

QGIS Spatial Query Dialogue Box

Select Source Features From – this is the table that the selection will be from.

Where the feature – the options will change depending on the exact combination of point, line or region features that are being used for the selection. They include contains (e.g. a region layer may contain points), crosses (e.g. a line layer may cross a region layer), Is Within (e.g. a point layer may be within a region layer), Touches (where one object may touch another but not actually be within it).

Reference Features Of – this is the second layer. It will be used to select features from the first layer, but its features won’t be part of the selection

The selected geometries only will only use features that have already been selected. For example if I wanted to select all the woodland within a particular county I could set up the query to read

  • Select Source Features from Farmland
  • Where the Feature is Within
  • Reference features of County Boundaries (selected features only)

Click OK, the query will run. Once it has completed, the results will appear:-

QGIS Spatial Query Dialogue Box

It is possible to run a further query based on the selection

Press the Create Layer from Selected to add the selection to the map as a new layer:-

Spatial Query Results

Combined Spatial and Attribute Query

Quite often GIS is used to select features that contain a certain attribute within a certain area (e.g. all the A roads and motorways within Greater London).

These queries are carried out by combining the above Spatial and attribute selections. They can be carried out either order depending on which is most logical.

In this example I would overlay the roads and OS Boundary Line features. I would then select all the London Boroughs by clicking on them with the Select Single Feature tool

  • Select Source Features from Roads
  • Where the Feature is Within
  • Reference features of OS Boundaryline (selected features only)
  • Press OK
  • In the Results box, press the Create Layer from Selected to create a new layer
  • Right click on the newly added Selection from Roads layer in the Layer Panel
  • Select Query
  • Use the Query Builder to enter the following SQL “Classification” = ‘A Road’ OR “Classification” = ‘Motorway’
  • Press OK

Quick Tip: Using coalesce to check for NULL or zero

Here is a quick tip that you can use in QGIS expressions, T-SQL, or even PostgresSQL.

Normally if you have a column that you need query on to find all the NULL or zeros you have to do something like this:

COLA IS NULL OR COLA = 0

Well that isn't too bad. Sure yeah it's fine for one column but what if you have three and you need to check them all together

(COLA IS NULL OR COLA = 0) AND (COLB IS NULL OR COLB = 0) AND (COLC IS NULL OR COLC = 0)

That is pretty long and gets hard to read pretty quick.

To cut this down we can use the coalesce function - T-SQL, PostgresSQL, QGIS Expression. The coalesce function returns the first non-NULL value out of an expression, or list of values. So if you do something like this:

coalesce(NULL, "A", 0)

You will get "A" because the first value is NULL. The function will just evaluate each value/expression until something turns up that isn't NULL.

Using that logic we can replace the above function with the following:

coalesce(COLA, 0) = 0 AND coalesce(COLB, 0) = 0 AND coalesce(COLC, 0) = 0

To me that is a lot clearer and readable.

Quick Tip: Using coalesce to check for NULL or zero

Here is a quick tip that you can use in QGIS expressions, T-SQL, or even PostgresSQL.

Normally if you have a column that you need query on to find all the NULL or zeros you have to do something like this:

COLA IS NULL OR COLA = 0

Well that isn’t too bad. Sure yeah it’s fine for one column but what if you have three and you need to check them all together

(COLA IS NULL OR COLA = 0) AND (COLB IS NULL OR COLB = 0) AND (COLC IS NULL OR COLC = 0)

That is pretty long and gets hard to read pretty quick.

To cut this down we can use the coalesce function – T-SQL, PostgresSQL, QGIS Expression. The coalesce function returns the first non-NULL value out of an expression, or list of values. So if you do something like this:

coalesce(NULL, "A", 0)

You will get “A” because the first value is NULL. The function will just evaluate each value/expression until something turns up that isn’t NULL.

Using that logic we can replace the above function with the following:

coalesce(COLA, 0) = 0 AND coalesce(COLB, 0) = 0 AND coalesce(COLC, 0) = 0

To me that is a lot clearer and readable.


Filed under: qgis Tagged: qgis, sql

Quick Tip: Using coalesce to check for NULL or zero

Here is a quick tip that you can use in QGIS expressions, T-SQL, or even PostgresSQL.

Normally if you have a column that you need query on to find all the NULL or zeros you have to do something like this:

COLA IS NULL OR COLA = 0

Well that isn't too bad. Sure yeah it's fine for one column but what if you have three and you need to check them all together

(COLA IS NULL OR COLA = 0) AND (COLB IS NULL OR COLB = 0) AND (COLC IS NULL OR COLC = 0)

That is pretty long and gets hard to read pretty quick.

To cut this down we can use the coalesce function - T-SQL, PostgresSQL, QGIS Expression. The coalesce function returns the first non-NULL value out of an expression, or list of values. So if you do something like this:

coalesce(NULL, "A", 0)

You will get "A" because the first value is NULL. The function will just evaluate each value/expression until something turns up that isn't NULL.

Using that logic we can replace the above function with the following:

coalesce(COLA, 0) = 0 AND coalesce(COLB, 0) = 0 AND coalesce(COLC, 0) = 0

To me that is a lot clearer and readable.

'Quick Tip: Using coalesce to check for NULL or zero'

  • qgis tags:
  • qgis
  • sql

Here is a quick tip that you can use in QGIS expressions, T-SQL, or even PostgresSQL.

Normally if you have a column that you need query on to find all the NULL or zeros you have to do something like this:

COLA IS NULL OR COLA = 0

Well that isn't too bad. Sure yeah it's fine for one column but what if you have three and you need to check them all together

(COLA IS NULL OR COLA = 0) AND (COLB IS NULL OR COLB = 0) AND (COLC IS NULL OR COLC = 0)

That is pretty long and gets hard to read pretty quick.

To cut this down we can use the coalesce function - T-SQL, PostgresSQL, QGIS Expression. The coalesce function returns the first non-NULL value out of an expression, or list of values. So if you do something like this:

coalesce(NULL, "A", 0)

You will get "A" because the first value is NULL. The function will just evaluate each value/expression until something turns up that isn't NULL.

Using that logic we can replace the above function with the following:

coalesce(COLA, 0) = 0 AND coalesce(COLB, 0) = 0 AND coalesce(COLC, 0) = 0

To me that is a lot clearer and readable.

'Quick Tip: Using coalesce to check for NULL or zero'

  • qgis tags:
  • qgis
  • sql

Here is a quick tip that you can use in QGIS expressions, T-SQL, or even PostgresSQL.

Normally if you have a column that you need query on to find all the NULL or zeros you have to do something like this:

COLA IS NULL OR COLA = 0

Well that isn't too bad. Sure yeah it's fine for one column but what if you have three and you need to check them all together

(COLA IS NULL OR COLA = 0) AND (COLB IS NULL OR COLB = 0) AND (COLC IS NULL OR COLC = 0)

That is pretty long and gets hard to read pretty quick.

To cut this down we can use the coalesce function - T-SQL, PostgresSQL, QGIS Expression. The coalesce function returns the first non-NULL value out of an expression, or list of values. So if you do something like this:

coalesce(NULL, "A", 0)

You will get "A" because the first value is NULL. The function will just evaluate each value/expression until something turns up that isn't NULL.

Using that logic we can replace the above function with the following:

coalesce(COLA, 0) = 0 AND coalesce(COLB, 0) = 0 AND coalesce(COLC, 0) = 0

To me that is a lot clearer and readable.

Queries in QGIS pt 1 – Attribute Queries

Quick Select Tools

The Select Flyout button on the Main toolbar contains tools used to quickly select features:

QGIS Quick Select Tools

QGIS Quick Select Tools

Attribute Queries

One method to select features in a layer is to select features using an attribute query:-

To query a layer by its attribute data,

  1. Right click on the layer’s name in the Layer Panel
  2. Select Query from the short cut menu to open the Query Builder box
QGIS Select by attributes box

QGIS Select by attributes box

  1. It is possible to type the SQL query into the SQL where clause box. Alternatively:-
    1. Click the Field that contains the attributes you wish to base the query on
    2. Select the operator
    3. Press the All under the values box to list all the available values
    4. Double click the value that you wish to select
    5. You will see the query being built in the SQL where clauses box.

Boolean operations (And, Or, Not)

  • And: narrows the search by requiring all the criteria to be present. It is most commonly used when the criteria are in different columns. E.g. Select Business_type = “bank” And City = “London” will select banks with London addresses.
  • Or: broadens the search criteria by requiring just one of several criteria to be true. It is most commonly used to give different options to the same column e.g. select Business_type = “bank” Or Business_type = “shop” will select all the banks and shops within the data set.
  • Not: returns records that do NOT match the criteria e.g. select Business_type = “bank” AND City NOT “London” would return all the banks that do not have a London address. Note that QGIS uses != for not equal to

It is important to be clear about when to use And Or operators.

If the first example was worded Select Business_type = “bank” OR City = “London” this would return all the banks and any property with a London address

If the second example was worded select Business_type = “bank” AND Business_type = “shop” this would return only those business which had bank and shop entered as business type. This would probably be none at all as businesses tend to either be a shop or a bank but rarely both!

Mathematical Operations

It is possible to use mathematical formulae to select from columns that are formatted in a numeric format (e.g. integer):-

>Greater than e.g. Business_type = “shop” AND floor_space > 100

< Less than e.g. Business_type = “shop” AND floor_space < 100

>= greater than or equal to

<= Less than or equal to

!= Does not equal


  • <<
  • Page 91 of 142 ( 2821 posts )
  • >>

Back to Top

Sustaining Members