Quantcast
Channel: QGIS Planet
Viewing all 1090 articles
Browse latest View live

Info Geo Blog: Re-Projecting Vector Layers in QGIS

$
0
0

QGIS can re-project a layer using both on-the-fly re-projection for the current session; and by saving a copy of the layer with a new Co-ordinate Reference System (CRS) defined.

On the fly

This is useful when a layer only needs to be re-projected for the current session.

Add the layer. If the CRS is known, QGIS will re-project it if necessary.

To check which CRS has been specified for the layer, right click on the layer in the Layers Panel, select Properties, and then select the General tab.

QGIS Layers Property

QGIS Layers Property

 

To save a new copy

It is a good practice to save a copy of a layer once it has been re-projected. This is to ensure the new CRS and transformations are permanently assigned to it. This avoids transformation errors when it is added to later map documents.

To save a copy:-

  1. Right click on the layer in the Layers Panel , select Save As.
  2. In the Save Vector layer as dialog, specify the filename, plus the new Co-ordinate Reference System. It is possible to add a symbology reference scale and new attributes. It is a good idea to add the new layer to the map to check it is correctly projected.
QGIS Save Vector Layer Dialog

QGIS Save Vector Layer Dialog



Nathans QGIS and GIS blog: What are all these QGIS file type. And why do I need them

$
0
0

After I added the new QGIS Layer Definition feature in QGIS I have noticed some indirect feedback regarding its use. I thought I would do this post in order to clear things up regarding the new feature so that we are all on the same page.

Some of this feedback, or I could say confusion, was mainly "Why not use the qml format?" or "How is it different from a project file". I can understand this confusion because they do kind of look and act the same however they are a little different.

I'm going to work my way up from the bottom up in terms of file levels and their use.

The QML file (.qml)

It contains: Style information

The QML (.qml) file in QGIS is a style file. It contains an export of the style information, including labels, from a layer. The .qml file however has no reference to the layer. This means I can share a .qml file with you and you can apply it to your own data without needing the data I exported it from. QML files are handy if you have one, or more, layers but have a collection of different style that you want to apply to them.

Style files can only be only be applied to a layer once it is opened. The recent Ordance Survey release of styles is a prefect QML use case.

The Layer Definition file (.qlr)

It contains: Layer source pointer + Style information

This newest feature, also in plugin form for 2.0 and 2.2, is a Layer Definition file. This file contains the reference - or pointer - to the data source plus any style information. This is like a the ArcGIS .lyr file, although maybe not as fully feature rich just yet. The use case for this file is simple: To have a single file to can open a data source bringing in all the related style information. These files also allow you to mask the underlying datasource in a easy to open file.

One of my use cases is to open MS SQL layers. Rather then having to go to the MS SQL connection dialog, connect, select and load, then style. I can simply add a .qlr file that points to the correct MS SQL layer pre styled.

In the future a .qlr file may hold a reference to more then one layer. The Ordance Survey or Natural Earth stuff could also be done with a QLR in order too allow just opening a single file.

The Project file (.qgs)

It contains: Layer source pointer + Style information + Composers + a whole heap of other stuff

The Project file is the highest level file that QGIS has. This holds more then just a list of layers, it also holds order, groups, composers, marcos, etc. I don't really need to explain any of this because you already know.

Why not just extend QML (style file) or QGS (project file)?

In software development we have this thing called SRP (Single Responsibility Principle), and while it can be tricky to follow at times I think it can also apply in cases like this. Sometimes have a single file meaning many different things can be worse then having a many different files with one use case each.

Could I have extended QML to support datasource too? Sure. Easy. However I don't think it made any sense. The use case of the QML is to store only the style and to be applied after the layer is loaded. Who says I have the datasource you used in the first place? In this case the QML is the most portable format because it doesn't point to a data source. I could have just stored the layer reference and ignored it in the normal places we import QML, yes but now you start to muddy the water on what a QML is. If your answer to "What is a QML file?" is "Well sometimes it opens a layer, and sometimes it's just the style" that to me is a smell.

The project file stores a lot of different things and I could have used that as a base, but again I think it starts to muddy the waters. The project file also contains a lot of other things that we just don't need, composers, etc. I have started working on a Import from Project function, just like the plugin of the same function, however I don't think this process is a smooth as using something like a QLR file to bring in layers. Giving someone a full project just so then can import a single layer from it feels like giving someone a full toolbox when all they want is a screwdriver. Just give me the screwdriver, I don't care for the other stuff.

nyalldawson.net: Two book recommendations

$
0
0

I recently finished reading two books which may be of interest to open-source GIS users – “PostGIS Cookbook” and “The PyQGIS Programmer’s Guide“, both of which I highly recommend:

PostGIS Cookbook

PostGIS CookbookI’ve been a fan of Stephen Mather’s blog for a while now, and have consistently found it to be a great source of trustworthy information and creative solutions to GIS problems. So when I first saw mention of his work on the PostGIS Cookbook I knew it would be a must-read for me. PostGIS is an essential part of my daily toolkit, and I’ll quickly devour any tutorial or guide which can lead me to better ways to put it to use. And that’s exactly what this book is! It’s full of tips and guides which has inspired me in a lot of techniques I’d never tried or even thought possible in PostGIS.

It’s important to point out that this book isn’t a training manual or beginner’s guide to PostGIS. It assumes readers are already familiar with using PostGIS and have a good understanding of GIS software in general. (If you’re looking for a book to start from scratch with PostGIS, PostGIS in Action is a better fit). I think that’s really what makes this book stand out though. There’s currently not a lot of books available covering PostGIS, and as far as I’m aware the PostGIS Cookbook is the only book available which is targeted to experienced PostGIS users.

Highlights for me are:

  • A great explanation and write up on optimised KNN filtering in PostGIS (something which often trips me up)
  • The detailed guide to topologically correct simplification of features
  • The exploration of PgRouting, which is a great introduction to PostGIS’ routing abilities
  • The “PostGIS and the web” chapter – I really wasn’t expecting this, but it’s quite eye opening (I’m going to have to do some digging into GeoDjango sometime)

The only criticism I have with this book is that it jumps around a lot between operating systems. While most of the code is provided for both Linux/OSX and Windows, there’s occasional examples which only have code for one specific operating system. It’s a little jarring and assumes the user is well versed in their particular operating system to workaround these omissions.

Overall, I strongly recommend the PostGIS Cookbook, and would consider it a must have for anyone serious about expanding their PostGIS abilities. (Also, looks like the publisher, Packt, have a two-for-one sale going at the moment, so it’s a good time to grab this title).

The PyQGIS Programmer’s Guide

The PyQGIS Programmer's GuideThe second book I’ve just finished reading is Gary Sherman’s “The PyQGIS Programmer’s Guide“. For those who are unaware, Gary was the original founder of QGIS back in 2002, so you can be confident that he knows exactly what he’s writing about. In The PyQGIS Programmer’s Guide  Gary has created an in-depth guide on how to get started with programming for QGIS using python. It takes readers all the way from simple scripts right through to developing QGIS plugins and standalone applications based on the QGIS API.

This book fills an important void in the literature available for QGIS. Previously, the PyQGIS Developer Cookbook was the only available guide for QGIS python scripting, and unfortunately it’s a little out-of-date now. PyQGIS scripting can be a steep learning curve and that’s why this book is so appreciated.

It would be valuable to have some python knowledge and experience prior to reading this book. While the “Python Basics” chapter quickly runs through an introduction to the language, the book makes no claims to be a comprehensive python tutorial. But if you’ve dabbled in the language before and have familiarity with the python way of doing things you’ll easily be able to follow along.

Highlights are:

  • The “Tips and Techniques” chapter, which is a great mini-reference for performing a range of common tasks in PyQGIS (including loading layers, changing symbol styles, editing feature attributes, etc).
  • A complete tutorial for creating a QGIS plugin
  • A guide to debugging PyQGIS code and plugins

I’d definitely recommend that anyone who wants to get started with PyQGIS start with Gary’s work – you’ll find it the perfect place to begin.

Sourcepole: FOSSGIS 2014 slides

$
0
0

Neues in QGIS 2.2

Nach dem lange erwarteten Release von QGIS 2.0 im September 2013, sind ab diesem Jahr neue Versionen im Viermonatszyklus geplant. Es werden die neuen Funktionen in QGIS 2.2, wie z.B. DB-Relationen mit verschachtelten Formularen, die erweiterten Methoden zur Transformierung geographischer Koordinatensysteme, zahlreiche Verbesserungen im Print Composer und ein komplett überarbeiteter DXF Export vorgestellt. Zusätzlich wird eine Vorschau auf das multithreaded Rendering gegeben und die neuen Mitglieder im Project Steering Committee vorgestellt

Links:

Mobile Kartenviewer mit Openlayers 3

Mit OpenLayers 3 steht eine komplette Neuentwicklung der funktionsreichen OpenLayers-Bibliothek zur Verfügung. Die verbesserte Unterstützung mobiler Geräte war ein primäres Ziel der neuen Version. Dieser Vortrag stellt den JQuery Mobile basierten OL3 Mobile Viewer vor, der erweiterte Funktionen wie automatische Kartenausrichtung oder Positionsnachführung bietet. Es wird auch ein Vergleich mit anderen Viewern, wie der auf Bootstrap und AngularJS aufbauenden Neuentwicklung von Swisstopo angestellt.

Links:

QGIS UK: Scottish QGIS User Group Overview

$
0
0

Scottish QGIS User Group
Stirling, 19th March 2014

It was a long time coming but the wait was worth it. Forty two excited QGIS users and open-source GIS enthusiasts arrived at the Stirling Management Centre on a brilliantly sunny March day.  People had traveled from all over the UK to make the day happen: Charley Glynn from OS in Southampton, Pete Wells, Martin Dobias and Saber Razmjooei from Brighton as well as others from Aberdeen, Inverness, Dundee, Edinburgh, Glasgow, Cumbria and most places inbetween. The event was supported by thinkWhere, based in Stirling, and Neil Benny and Heikki Vesanto provided suitably geeky geo entertainment.

Neil Benny, QGIS EvangelistFirst up was Neil Benny (thinkWhere) who provided us with an overview of QGIS through the years to the current top features available in version 2.2 “Valmiera”. The questions on everyone’s minds were answered when he presented a series of slides outlining the benefits of using open source software, highlighting the savings and investments and the importance of investing in training. His top 10 feature comparison of proprietary v open source desktop GIS provoked much discussion.

After a coffee break I presented a short talk on how Angus Council is moving to a mixed hybrid GIS environment to take advantage of the flexibility of the open source licence and the variety of tools available to deliver results. Available here http://vimeo.com/89959143

Martin Dobias of Lutra Consulting and core QGIS developer revealed some of the performance enhancements available in the development version of QGIS. The multi-threaded multi-core rendering impressed everyone and will prove a huge draw card to seasoned GIS’ers used to single threaded applications.Martin Dobias, Core Developer

Saber Razmjooei (Lutra) filled in an open slot talking about the autoTrace plugin they developed for a group of Local Authorities across the UK. Modeled on the MapInfo trace tool it forms a key part of a lot of Council workflows and is a good example of how future plugin development work can deliver savings.

Pete Wells, plugin developerPete Wells (Lutra) delivered a very comprehensive overview of Python and QGIS and how they interact at different levels through the python bindings. There was a lot of interest in this and this was reflected in the feedback forms we collected where Python, plugins, hands-on workshops and tutorials feature high on the list of wants.

Charley Glynn (OS) unveiled some fantastic cartography using the OS vector products of MasterMap, VectorMap Local and District. He also revealed the work OS has been doing to make corporate styles available to the public and the Ordnance Survey’s bias towards open source software. Again the feedback forms revealed a desire to get hands on with QGIS to create good looking custom cartography. The next Scottish user group meeting will definitely be having some hands-on workshops.Charley Glynn, OS CartographerIMG_20140319_152620

Heikki Vesanto (thinkWhere) bravely ventured into live demos of how to connect to just about any spatial data format available. Local files, local databases, WMS feeds, WFS feeds, text files, CSV and URLs with images and custom map templates using the Atlas generator. An excellent overview of just how flexible QGIS is when it comes to consuming data and converting data to almost every format supported by OGR and GDAL.

Thanks must go to the generosity of thinkWhere in supporting a feature filled programme of presentations and keeping us topped up with coffee. As a result the first Scottish QGIS user group meeting was a success and there is definitely a desire for more events like this.

Slides and videos of the presentations will be available here shortly.


QGIS UK: Programme: Scottish QGIS User Group

$
0
0

The programme of events for the Scottish QGIS user group meeting in Stirling is now available:

Time

Event

Speaker

9:30

Registration

10:00

WelcomeRoss McDonald / Alan Moore

10:30

QGIS EvangelismNeil Benny

11:00

Break

11:30

Data auditing in PostGISMike Saunt

12:00

QGIS performance enhancementsPeter Wells

12:30

Lunch

13:30

Land Terrier ManagementMike Saunt
Developing QGISMartin Dobias
User Group, eh?Ross McDonald

14:30

Break

15:00

Cartography in QGISCharley Glynn
Data Connections in QGISHeikki Vesanto

16:00

Close
Geobeers

You can download the ScottishQGISUserGroupAgenda here.


QGIS UK: Scottish QGIS User Group

$
0
0

scottish flagThe inaugural Scottish QGIS user group meeting is being planned and organised for mid-March next year.  If you would like to participate, I am looking for user presentations, case studies, map displays and practical demos and tutorials.

The event will be held in Stirling and will be a full day of networking and open-source geo-goodness.  Full details will go out in the new year and will be available through Eventbrite, this blog, the Google+ group, Twitter and probably a heap of other channels.  After the success of the English and the Welsh events we are hoping the Scottish event will raise the bar even higher.  Please use the contact form to get in touch with me, Ross McDonald.


QGIS UK: How the West was Won (or QGIS rocks!)

$
0
0

gazetteer search list!<tl><dr>

Local Authorities work with people and assets. Most people have an address and assets are mostly located somewhere. As my old geography teacher used to say, “everything has geography, geography is everything”. For people who work in Local Authorities being able to find an accurate and up-to-date address easily is key to being able to deliver a service quickly and efficiently. If GIS officers had their way even more of the Council back office systems across the country would hook up to the corporate GI database and do cool stuff with spatial information.

At the recent AGI GeoCom and FOSS4G conferences in Nottingham during Maptember QGIS 2.0 was launched and garnered a lot of attention from people interested in finding solutions to save money and time and still deliver great results. I came away with a resolution to push for the use of QGIS at work in an attempt to get a desktop GIS onto more desktops while not breaking the bank. I had also met Simon Miles (@geosmiles) and eagerly followed his talk of creating a hybrid GI infrastructure using a mix of open-source and proprietary software.

QGIS fitted the bill with its extensive range of functionality, growing list of available plugins, super easy connectivity to a range of data sources including Oracle, SQL Server and PostGIS, all of which we use. The one thing it was lacking was a search plugin to let the users search the corporate address gazetteer for postal address and street names. Our existing GIS has such a plugin and it works well but not with the imminent upgrades. There had to be something that could connect to the gazetteer table in our PostGIS database, search and display an address.

qgis gazetteer pluginEnter the QGIS Gazetteer Plugin developed by Astun Technology, Nathan Woodrow and Matt Walker. Add some keen peeps from the UK QGIS User Group and some social networking and stuff begins to happen.

After downloading and installing the plugin I soon hit a brick wall – or rather a firewall – the security at work wouldn’t let the Yahoo and Geonames gazetteers work and we don’t have Astun’s iShareGIS software stack. I delved into the code to see if I could work out what was happening and hit another wall – how does this Python stuff work? Nought for two after one over.

After some chat on the UK QGIS Google+ group I found some people in Local Government across the UK who have managed to get the plugin to work and work well.  Simon Miles (Royal Borough of Windsor and Maidenhead), Kevin Williams (Neath-Port Talbot) and Matt Travis (Dartmoor National Park) rallied to my call and soon I had some code in my grubby mitts.  An hour after that I had a working plugin searching our address and street gazetteers, postcodes and planning applications.  Listed buildings, building warrants and others soon followed.  I shared the plugin with some of our power users and they were very impressed and have even started asking for enhancements.

This whole process is a great example of how a User Group can work when coupled with FOSS4G fans, social media, open-source software and a common problem to solve.  Being able to present a working solution to users and managers in just a few days certainly strengthens the case for using QGIS alongside the traditional GIS tools and maybe, in time, replacing them.

What follows is a rather more technical description of the installation and configuration of just about the single most useful application a Council officer could ask for. If you want the short version and can do the tech stuff then go to https://github.com/mixedbredie/qgis-gazetteer-search and get it, otherwise hang in there to the end…

What you need:

1. QGIS 2.0 installed

2. the QGIS Gazetteer plugin installed

3. a PostGIS database with some gazetteer tables

4. an Apache2 web server

how-it-works

1. QGIS

Install QGIS 2.0 – I used the standalone installer from http://www.qgis.org/en/site/forusers/download.html

2. QGIS Gazetteer Plugin

Install the QGIS Gazetteer plugin from https://github.com/AstunTechnology/QGIS-Gazetteer-Plugin by downloading the zip file and extracting into your .qgis2 folder. This is located at

C:\Documents and Settings\<Username>\.qgis2\python\plugins\ (Windows XP) or 
C:\Users\<Username>\.qgis2\python\plugins\ (Windows 7+).

Make sure that the extracted directory is called “gazetteersearch”. Matt Walker (@_walkermatt) has upgraded the plugin to work with QGIS 2.0 and added a few enhancements like an OpenStreetMap search.

In the “gazetteers” sub directory there a “config.ini” file which needs to be edited to list the datasets we want to search. I’ll show how to connect to the address and street gazetteers and a table of postcode areas.

I deleted the GeoNames, Yahoo and AstunTechnology lines and inserted the following:

[LLPG]
gazetteer:llpg
[LSG]
gazetteer:lsg
[Postcode]
gazetteer:postcodes

Create three files in the gazetteers folder – llpg.py, lsg.py and postcodes.py

In the llpg.py file put:

import json
import collections
url = "http://10.135.1.69/cgi-bin/llpg_pg.py"
params = {
    'address': '##searchstring##'
}
def parseRequestResults (data):
json_result = json.loads (data)
    for item in json_result:
        result = collections.namedtuple ('Result', ['description','x','y','zoom', 'epsg'])
        result.description = item['address']
        result.x = float (item['easting'])
        result.y = float (item['northing'])
        result.zoom = 1250
        result.epsg = 27700
        yield result

In the lsg.py file put:

import json
import collections
url = "http://10.12.345.678/cgi-bin/lsg_pg.py"
params = {
    'address': '##searchstring##'
}
def parseRequestResults (data):
json_result = json.loads (data)
for item in json_result:
        result = collections.namedtuple ('Result', ['description','x','y','zoom', 'epsg'])
        result.description = item['address']
        result.x = float (item['easting'])
        result.y = float (item['northing'])
        result.zoom = 2500
        result.epsg = 27700
        yield result

In the postcodes.py file put:

import json
import collections
url = "http://10.12.345.678/cgi-bin/postcodes_pg.py"
params = {
    'postcode': '##searchstring##'
}
def parseRequestResults (data):
    json_result = json.loads (data)
    for item in json_result:
        result = collections.namedtuple ('Result', ['description','x','y','zoom', 'epsg'])
        result.description = item['postcode']
        result.x = float (item['easting'])
        result.y = float (item['northing'])
        result.zoom = 2500
        result.epsg = 27700
        yield result

You need to set the correct server IP address in the URL and link to the correct file in the cgi-bin. You can also set the zoom scale for the results and I use ESPG:27700 as everything we have is in British National Grid.

If you restart QGIS and enable the plugin you’ll see there are now four search options in the drop-down list. Right, now to make sure PostGIS has the correct information.

3. PostGIS Database

The installation and configuration of PostgreSQL and PostGIS is more than this post is going to address but you’ll need to have one. With some tables in it with some data that can be searched. We load our address and street gazetteers into PostGIS on a daily basis and these tables are used by the plugin for searching and displaying records. Our tables have a UPRN (Unique Property Reference Number) field and an ADDRESS field with a full address in it (name number street town locality postcode). The address gazetteer has a point geometry. The street gazetteer has a USRN (Unique Street Reference Number) and a NAME field with the full descriptive name of the street in it. It has a line geometry. Almost any table can be searched as long as it has a unique id, a text field for searching, and some geometry.

Our address gazetteer already had the correct fields in so nothing had to be done but the street gazetteer needed some changes. I created a view of the streets to change the name of the fields to fit with what the plugin was expecting:

CREATE OR REPLACE VIEW angusdata.search_lsg_streets AS
SELECT a.usrn AS uprn,
btrim(pg_catalog.concat('usrn:', btrim(a.usrn::text), ' ', btrim(a.street::text), ' ', btrim(a.locality::text), ' ', btrim(a.town::text))) AS address,a.geometry
FROM lsg_streets a;

This changes the USRN field to UPRN and concatenates USRN, STREET, LOCALITY and TOWN to create an ADDRESS field and then adds the geometry.

The Postcodes table has polygon geometry and a postcode field and the python script that creates the web service has been tweaked to work with this. The next section will explain how to create the web services on Apache2.

4. Apache

I have a local Apache2 webserver running on my PC but it’s pretty easy to get one set up on server if you chat to the right people :-) so get one installed (http://www.apachehaus.com/cgi-bin/download.plx). The plugin uses the web services running in the Apache2 cgi-bin to connect to the PostGIS database to query the gazetteers. You’ll also need to have Python (http://www.python.org/download/releases/2.7.5/) installed on the same machine. And the Python psycopg2 module (http://www.stickpeople.com/projects/python/win-psycopg/).

First up, the Apache2 server needs to be configured to allow use of the cgi-bin. Edit the httpd.conf file and make the following changes.

Uncomment the following lines to enable the modules:

LoadModule access_compat_module modules/mod_access_compat.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule rewrite_module modules/mod_rewrite.so

Set the server name to its IP address:

ServerName 10.12.345.678:80

Allow access to the server:

<Directory />
  Options Indexes FollowSymLinks ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
</Directory>

Set the file that Apache will serve if a directory is requested:

<IfModule dir_module>
  DirectoryIndex index.html index.htm index.php index.php3
</IfModule>

Allow access to the CGI directory and enable it to handle python scripts:

<Directory "${SRVROOT}/cgi-bin">
  Options Indexes FollowSymLinks ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
  AddHandler cgi-script .cgi .py
</Directory>

This is a pretty basic configuration and it could probably be improved but it works on my system.

Then in the CGI-BIN directory create some files, one for each web service and to match the gazetteers listed in the config file. I created three files called llpg_pg.py, lsg_pg.py and postcodes_pg.py.

In the llpg_pg.py file the SQL query selects the records that match the search string and uses the point geometry of the records to return to the plugin.

#!D:/Python27/python.exe
# -*- coding: UTF-8 -*-
import cgi
import json
import psycopg2
sql = """select a.uprn, a.address, ST_X(a.geometry), ST_Y(a.geometry)
from angusdata.address_gazetteer a
where a.address ilike '%%' || (%(p_address)s) || '%%'
order by address"""
form = cgi.FieldStorage ()
connection = psycopg2.connect ("host='10.12.345.678' port='5432' dbname='postgisdb' user='username' password='password'")
cursor = connection.cursor ()
cursor.execute (sql, {"p_address": form["address"].value})
list = []
for record in cursor:
    data = dict (zip (["uprn", "address", "easting", "northing"], record))
    list.append (data)
print "Content-Type: application/json\n"
print json.dumps (list, indent = 4)

In the lsg_pg.py file the SQL query selects the records from the view and converts the line geometry to a centroid point.

#!D:/Python27/python.exe
# -*- coding: UTF-8 -*-
import cgi
import json
import psycopg2
sql = """select a.uprn, a.address, ST_X(ST_Centroid(a.geometry)), ST_Y(ST_Centroid(a.geometry))
from angusdata.search_lsg_streets a
where a.address ilike '%%' || (%(p_address)s) || '%%'
order by address"""
form = cgi.FieldStorage ()
connection = psycopg2.connect ("host='10.12.345.678' port='5432' dbname='postgisdb' user='username' password='password'")
cursor = connection.cursor ()
cursor.execute (sql, {"p_address": form["address"].value})
list = []
for record in cursor:
    data = dict (zip (["uprn", "address", "easting", "northing"], record))
    list.append (data)
print "Content-Type: application/json\n"
print json.dumps (list, indent = 4)

In the postcodes_pg.py file the SQL query turns the polygon geometry into a point geometry using the PostGIS ST_PointOnSurface function. The psycopg2 parameters have been tweaked to use the postcode tables fields.

#!D:/Python27/python.exe
# -*- coding: UTF-8 -*-
import cgi
import json
import psycopg2
sql = """select a.postcode, ST_X(ST_Pointonsurface(a.geometry)), ST_Y(ST_Pointonsurface(a.geometry))
from thirdparty.os_codepointpoly a
where a.postcode ilike '%%' || (%(p_postcode)s) || '%%'
order by postcode"""
form = cgi.FieldStorage ()
connection = psycopg2.connect ("host='10.12.345.678' port='5432' dbname='postgisdb' user='username' password='password'")
cursor = connection.cursor ()
cursor.execute (sql, {"p_postcode": form["postcode"].value})
list = []
for record in cursor:
    data = dict (zip (["postcode", "easting", "northing"], record))
    list.append (data)
print "Content-Type: application/json\n"
print json.dumps (list, indent = 4)

Make sure the #!shebang at the top of the python script has the correct path to your Python installation.

Check the Apache2 log files if there are any errors.

Right, we have QGIS installed with the gazetteer search plugin configured to use the new gazetteers.  The PostGIS tables and views are presenting the data in format required by the web services. The Apache2 server is configure to allow access and the python scripts are in the cgi-bin. Fire up QGIS, refresh the plugin and enter a search term and hit GO!  Awesome!  Mine works, at least.

None of this would have been possible without the UK QGIS group and the input from Matt, Kevin and Simon.  Big thanks to Matt Walker and Jo Cook for recent updates to the plugin.  Use the comments to tell us how to do it better.



QGIS UK: User Poll

$
0
0

In the last blog I said that I’d pull together the results of a survey, to get a feel for UK qgis users. Unfortunately the number of responses was a bit disappointing with only 28 filling out the survey. However here is what was said….

ExpertiseDonation

workshopsLocations

I’m no statistician and the low return rate makes it harder to make concrete statements but a few things can be generalised upon.

Two-Thirds said that they would be willing to donate to the QGIS project. This is great news; so hypothetically speaking if all those that said yes (21 of you) gave a tenner, that would be £210 we could donate to the QGIS project. I can’t remember the static on the number of pizza’s consumed at the QGIS developer meeting held in Brighton earlier this year was, but i should imagine that £200 worth of pizza could fuel a lot of developers to write a lot of cool qgis code!

On the workshop side of things, there seemed to be a great interest in Plugins, Python and Databases. This has certainly given me some ideas on the kind of workshop that the QGIS User group could hold next year.

Thanks to everyone that took part in the survey.


QGIS UK: OSGeo Code Sprint, Vienna

$
0
0

This is how OSGeo happens.  These are the folk who bring us a lot of that open-source geo-spatial goodness. You can follow the code sprint on Twitter using the hashtags #csprint and #viennacodesprint14

 


QGIS UK: Programme: South-East QGIS User Group

$
0
0

The agenda for the South-East user group meeting, being held at Imperial College, on the 2nd April is here! We’ve got a mixture of speakers, two workshops and a ‘its your floor’ feature where by you can stand up and let people know what your up to with QGIS! If you haven’t got a ticket, there are still some available.

Time

9.30 – 10

Arrive / teas & coffee / networking

10 – 10.15

Simon Miles: Introductions etc

10.15 – 10.45

David McDermott: QGIS and Atlas: automatic map generation

10.45 – 11.15

Mike Saunt: QGIS and PostGIS: The perfect marriage!

11.15 – 11.30

Break

11.30 – 12.00

Jerry Clough: QGIS and OSM: All you needed to know!

12.00 – 12.30

Andrew Bell: QGIS and PostGIS: TBA

12.30 – 1.00

Lunch: Provided by the Ordnance Survey

Stream 1

Stream 2

1.00 – 2.45

Introduction to QGIS:

Based on the Ordnance Survey 2013 Masterclass tour. Ordnance Survey will give an introduction to QGIS and getting started with OS Opendata.

Python & QGIS:

Lutra Consultancy Pete Wells will demonstrate how you can introduce python into QGIS.

2.45 – 3.00

Break

3.00 – 3.30

Its your floor!

Your chance to share what you’ve been up to with QGIS

3.30 – 4.00

Round up / Discussion / User Poll / Geo-beers?


QGIS UK: OS OpenData Workshop – QGIS in the Classroom

$
0
0

Last week I attended an Ordnance Survey OpenData MasterClass in Exeter. This was one of a series of seven masterclasses that the Ordnance Survey were running across the country. They were aimed at letting people know how to get the best of the  OpenData products that they provide.

The workshop was delivered in a format of combining theory and practical sessions. They were aimed at people of various experience; from those new to working with location data to the more advanced users wanting to brush up on their skills.

What was encouraging from a QGIS point of view was that a lot of the course was taught using QGIS 2.0.  After an interesting introduction to the history and current standing of OpenData by Ian Holt we were given our first taste of QGIS. Ably led by Steve Kingston we were shown:

  • How to navigate around QGIS;

  • Import a range of vector and raster datasets (thankfully pre-downloaded);

  • Build virtual rasters (very useful if you’re dealing with lots of OS tiles);

  • Merge shapefiles into one layer

  • Create thematic maps from LSOA boundaries and ONS data (like the one below)  - here I learnt  you can now load non-geographic data from a csv straight into QGIS without using a csvt file, yay!

imd_compressed

After Lunch and a quick insight by Chris Parker  into the next Geovation Challenge , Chris Wesson from the Carto Design team at the OS gave a cartographic design workshop. This started off with a talk about the basic design principles behind cartography and how you should bear these in mind when making a map.

He then showed us how to import vector map district vector data and then style these in a various ways –  I particularly found his tips on creating road casing useful. Some of the maps being were produced were of a really good standard, especially when you this was many people’s first time using a GIS of any sort.

I thought that this was a really worthwhile experience and would recommend going to one if you get the chance in the future (according to their website there are still masterclasses to come in York and Nottingham). I learnt a fair bit myself as I always think it’s useful to watch someone else use a product that you’ve used in isolation. They might do something that you’ve never seen before that’s loads quicker or show you a hidden feature you’ve not come across.

It was encouraging to see people of various backgrounds present, parish councils in particular. As someone who works for a local authority that has many Parishes i’m very keen to promote the use of open data by parishes and local groups and get them using QGIS, etc

In the New Year I’m going to look into having a QGIS South West event and hope to reach out to all  types of QGIS users across the region. I’ll keep you posted on the exact details via the Google+ group but if you read this and are in or around the South West and want to share your experiences of using QGIS (no matter how big or small) then please get in touch.

That’s it for now. Just leaves me to thank all the people that made the OS Masterclasses possible I’m sure they’ve been a success so hopefully they’ll be even more next year to look forward to!
Matt


QGIS UK: Scottish QGIS User Group 19th March 2014

$
0
0

scottish thistleThe Scottish QGIS user group meeting is happening on 19th March 2014 in Stirling at the Stirling Management Centre.  Doors open at 9:30 with a 10:00 start and a planned finish of 16:00.  Registration is through Eventbrite and there are 50 places available working on a first come, first served basis.

Details on how to get to the Stirling Management Centre are available here.

The agenda will be published a bit closer to the time once speakers have been finalised.  If you would like to present let me (Ross McDonald) know as it would be good to have a mix of input to the day.  There are both 20 minute and “lightning talk” 5-10 minute slots available.

A big thank-you to thinkWhere for hosting this first QGIS user group event in Scotland.

If you want two days of geo discussion then think about attending the AGI Scotland – Future Cities event in Glasgow the day before.  Check the AGI Scotland website for more details.


QGIS UK: 1st UK QGIS user group meeting -Wales

$
0
0

This is just an interim post, the full blog is being written up by Kevin Williams and You Tube videos are being put together by Shaun Lewis. To wet your appetite, you can see the introduction presentation and agenda on SlideShare.

Update 27th January 2014 :-

A long overdue update.

Cymru am byth!

The event was a big success!  We had around 50 people attend from various organisations throughout Wales.  The event was kindly sponsored by Exegesis (http://www.esdm.co.uk/) and Astun Technology (www.http://astuntechnology.com/)  both of which gave excellent presentations.

Huge thanks to Shaun Lewis and his manager, Paul Funnell for hosting the event in such a professional manner.  The venue and technology were second to none.

There’s been lots of feedback via email and phonecalls, together with a survey carried out by Shaun Lewis of Brecon Beacons National Park.

From all of the comments, the future is bright for QGIS in Wales.  There is an ever-increasing interest and numbers of users, not just in QGIS but in the full SDI provided by QGIS, postgis, geoserver etc.  I can see the group incorporating elements of the open source stack to give a more detailed advice, collaboration and guidance, but let’s walk before we can run!

-Kevin

Watch this space for more news from around Wales in the QGIS arena!


anitagraser.com: Reporting back from the Vienna Code Sprint


Spatial Galaxy: Why QGIS Class Names Start with Qgs

$
0
0

If you’re a developer, or have looked at the QGIS source code, you’ve likely noticed that most C++ classes in the project start with Qgs.

Back before the dark ages of QGIS, Trolltech (now Digia) allowed you to reserve name prefixes for classes that used the Qt framework.

Shortly afterwards, I reserved the gs prefix for my use, resulting in class names that start with Qgs.

You might think this is based on some mangling of words like QGIS or perhaps GIS, but it was purely egocentric:

/images/qgs_prefix.png

As far as I can tell, reservation of prefix names is no longer possible. For a view into what it was like back then, take a look at the Internet Archive:

http://web.archive.org/web/20030303075955/http://www.trolltech.com/documentation/naming.html

Although the choice of prefix wasn’t based on technology or discipline, years later it seems to fit…

Faunalia: Formação em SIG Open Source com QGIS (Quantum GIS) em Moura, 28-29-30 Maio 2014

$
0
0
A Faunalia, em colaboração com a ENCPB (Escola Nacional de Caça, Pesca e Biodiversidade), Comoiprel e Câmara Municipal de Moura, organiza um curso de SIG Open Source com QGIS (Quantum GIS) nos dias 28-29-30 Maio 2014. Para informações e inscrições contactar: ENCPB (Escola Nacional de Caça, Pesca e Biodiversidade) E-Mail: encpb.moura@gmail.com Telefone: 285251354   Programa […]

Info Geo Blog: Topology in QGIS

$
0
0

Introduction

Topology rules define the permissible relationships of features within a given GIS layer or between features in two different GIS layers. An example is that features in a road dataset must be connected to other roads at both ends, unless the road is specified as a dead end street.

Advantage of topology over queries

A lot of the checks that topology rules carry out could be achieved using spatial queries. You may have to use queries if the GIS software you’re using doesn’t have a topology feature.

Topology rules have the advantage that they only need be created once and then they can check your work as you go.

Queries would need to be re-created each time they are run. They can be saved, depending on the GIS being used, but this is still more time consuming and it is a task that must be carried out separately at the end of a work session.

Rules

QGIS 2.2 topology tool has the following rules pre-defined:-

  • End points must be covered by (e.g. a railway line usually begins and ends at a station)
  • Must contain (e.g. a building polygon must contain at least one address point seed)
  • Must not have dangles (a line must begin and end at another line)
  • Must not have duplicates (each feature should be unique, e.g. postcode areas)
  • Must not have gaps (e.g. administrative area polygons cannot have gaps)
  • Must not have invalid geometries
  • Must not have multi-part geometries (each feature should be a separate entry)
  • Must not overlap (e.g. administrative area polygons cannot overlap each other)
  • Must not overlap with (a feature from layer must not overlap with another layer)

Example 1 – Roads must not have dangles

The following example uses the “Must not have dangles” rule to identify polylines from a roads dataset that are not snapped to other lines. Roads usually begin and end at a junction with another road, so this is a useful rule to identify where lines were not correctly snapped together.

To create and validate a Topology Rule

  • Open the Topology Panel, by selecting Vector menu, Topology Checker, Topology Checker
  • The Topology Panel appears in the lower right corner of the QGIS desktop window

Image

  • Press the Configure button to open the Topology Rule Settings dialog
  • The top of the box will have 2 or 3 pull down boxes depending on the layer and rule that is chosen. Use these to build the rule and then press the Add Rule button.

Image

  • Press OK when done, the dialog box closes and the window returns to the QGIS Desktop.
  • Press either the Validate All or Validate extent, depending on whether you wish to validate the entire dataset or just the current view extent.
  • The errors will be listed. Double click on a row will make the map window zoom and pan to the error.

Image

 


anitagraser.com: Using OSM POIs in QGIS

$
0
0

Extracting POIs from OpenStreetMap is reasonably simple using Overpass API. A very convenient way to construct the query is to use a query builder which allows you to select the area of interest and builds queries for different servers.

xapi_query_builder

Of course you can fine-tune the query further. For example, you can add multiple key-value pairs to the query. I used the following query to select all Billa supermarkets:

http://www.overpass-api.de/api/xapi?*[shop=supermarket][name=Billa][bbox=15.96725,48.0432,16.79947,48.40915]

Note to * in the query? It means that I’m querying all kinds of features: nodes, ways, and relations.

Save the server response to a .osm file. This file can be loaded into QGIS using simple drag-and-drop or Add Vector Layer. A dialog will open where you can select the type of features you want to load from the file. You can simply use Select All and OK to load everything.

add_osm_file

My supermarket POIs came in two types: points and multipolygons. To style them both with nice supermarket SVG icons, I decided to use a Centroid fill with the SVG marker for the polygon layer:

osm_pois_billa

Open data and open source GIS … nice :-)


Faunalia: QGIS PT users group: Portuguese speaking community

$
0
0
It’s with an enormous pleasure that we announce what we believe to be a very important step for the QGIS Portuguese speaking community, the creation of the QGIS PT users group. The QGIS PT users group arise from the notorious growth of QGIS usage  in Portugal, with the objective of become a platform for sharing […]
Viewing all 1090 articles
Browse latest View live