Related Plugins and Tags

QGIS Planet

OSM Reporter Update for Open Data Day 2013

Today is Open Data Day 2013. I did't have much time to hack, but I made a few tweaks to my 'just for fun' osm-reporter project to provide average, min and max counts per active day for each user. I also did a bunch of code cleanups under the hood which probably nobody except me will care about :-) Here is what the new goodies look like.

New stats added to report

The new stats (shown in the green, blue and orance dots in the last row of the report) give you an idea of what kind of capture rate a person is able to sustain and what they peak at when really 'going for it'. Only active days (where 1 or more ways were captured) are considered. I still have plans to add a bunch of different badges / achievements based on different metrics - something for the next time I have a day of fun hacking available to me. Head over to http://osm.linfiniti.com and zoom to your area to see what your your stats look like.

Adding ECW support in Quantum GIS

Perth QGIS User Forum/Group

I have a feeling this year is going to be a interesting one for QGIS in Australia. What's a better way then to start the year of with two great events on the same day in Perth, Australia. A QGIS User Forum/Group, and the regular Perth GeoRabble

Here is the official invitation to the upcoming QGIS User Group/Forum in Perth, Australia.

Inaugural Australian QGIS Forum

Digital Mapping Solutions is pleased to support, what will hopefully be, the first of many inspiring QGIS user forums. The goal for this event is to provide a casual environment where people can see QGIS in action as well as discuss and share their QGIS experiences and thoughts. The event will feature a variety of real-world demonstrations by QGIS users from a cross-section of industries.  There will also be a presentation by Nathan Woodrow, an active member of the open source GIS community, developer on the QGIS project and an OSGeo advocate.  Finally, there will be plenty of time for discussion during the presentations and networking over lunch. Whether you are already a QGIS user who is looking for an opportunity to share your experiences with others or if you are a potential user who is curious as to how QGIS can enhance your GIS toolkit, this is the event for you.

Event Details
Date and Times
Thursday  March 14th 2013

10.00am - Registration
10.20am - Welcome and  introduction
10.30am - Presentations commence
12.00pm - Open discussion
12.30pm - Lunch
1.30pm - Finish
Location
Kailis Bros Fish Market & Cafe
Function Room
101 Oxford Street 
LEEDERVILLE WA  6007
RSVP
To register please email joanne.smith@mapsolutions.com.au
on or before Friday March 8th 2013

Please let us know if you have any access issues or specific dietary requirements when you register.
Places are limited so please register your interest today.

and the invitation to the GeoRabble event:

Announcing GeoRabble Perth #5  - Return to Yesteryear -
Thursday, March 14, 2013
Venue: Upstairs at the Leederville Hotel
Time: Door @ 5:30pm for a 6:00pm start of presentations
Speakers:
Mike Bradford
Tom Gardner
More Speakers and the event sponsor to be announced very soon

As you can see from the QGIS Perth User Group invitation I will be attending and presenting - practice makes prefect - so I'm really looking forward to the event. Still not sure what I'm going to cover yet though.

Perth QGIS User Forum/Group

I have a feeling this year is going to be a interesting one for QGIS in Australia. What's a better way then to start the year of with two great events on the same day in Perth, Australia. A QGIS User Forum/Group, and the regular Perth GeoRabble

Here is the official invitation to the upcoming QGIS User Group/Forum in Perth, Australia.

Inaugural Australian QGIS Forum

Digital Mapping Solutions is pleased to support, what will hopefully be, the first of many inspiring QGIS user forums. The goal for this event is to provide a casual environment where people can see QGIS in action as well as discuss and share their QGIS experiences and thoughts. The event will feature a variety of real-world demonstrations by QGIS users from a cross-section of industries.  There will also be a presentation by Nathan Woodrow, an active member of the open source GIS community, developer on the QGIS project and an OSGeo advocate.  Finally, there will be plenty of time for discussion during the presentations and networking over lunch. Whether you are already a QGIS user who is looking for an opportunity to share your experiences with others or if you are a potential user who is curious as to how QGIS can enhance your GIS toolkit, this is the event for you.

Event Details
Date and Times
Thursday  March 14th 2013

10.00am - Registration
10.20am - Welcome and  introduction
10.30am - Presentations commence
12.00pm - Open discussion
12.30pm - Lunch
1.30pm - Finish
Location
Kailis Bros Fish Market & Cafe
Function Room
101 Oxford Street 
LEEDERVILLE WA  6007
RSVP
To register please email joanne.smith@mapsolutions.com.au
on or before Friday March 8th 2013

Please let us know if you have any access issues or specific dietary requirements when you register.
Places are limited so please register your interest today.

and the invitation to the GeoRabble event:

Announcing GeoRabble Perth #5  - Return to Yesteryear -
Thursday, March 14, 2013
Venue: Upstairs at the Leederville Hotel
Time: Door @ 5:30pm for a 6:00pm start of presentations
Speakers:
Mike Bradford
Tom Gardner
More Speakers and the event sponsor to be announced very soon

As you can see from the QGIS Perth User Group invitation I will be attending and presenting - practice makes prefect - so I'm really looking forward to the event. Still not sure what I'm going to cover yet though.

Perth QGIS User Forum/Group

I have a feeling this year is going to be a interesting one for QGIS in Australia. What's a better way then to start the year of with two great events on the same day in Perth, Australia. A QGIS User Forum/Group, and the regular Perth GeoRabble

Here is the official invitation to the upcoming QGIS User Group/Forum in Perth, Australia.

Inaugural Australian QGIS Forum

Digital Mapping Solutions is pleased to support, what will hopefully be, the first of many inspiring QGIS user forums. The goal for this event is to provide a casual environment where people can see QGIS in action as well as discuss and share their QGIS experiences and thoughts. The event will feature a variety of real-world demonstrations by QGIS users from a cross-section of industries.  There will also be a presentation by Nathan Woodrow, an active member of the open source GIS community, developer on the QGIS project and an OSGeo advocate.  Finally, there will be plenty of time for discussion during the presentations and networking over lunch. Whether you are already a QGIS user who is looking for an opportunity to share your experiences with others or if you are a potential user who is curious as to how QGIS can enhance your GIS toolkit, this is the event for you.

Event Details
Date and Times
Thursday  March 14th 2013

10.00am - Registration
10.20am - Welcome and  introduction
10.30am - Presentations commence
12.00pm - Open discussion
12.30pm - Lunch
1.30pm - Finish
Location
Kailis Bros Fish Market & Cafe
Function Room
101 Oxford Street 
LEEDERVILLE WA  6007
RSVP
To register please email [email protected]
on or before Friday March 8th 2013

Please let us know if you have any access issues or specific dietary requirements when you register.
Places are limited so please register your interest today.

and the invitation to the GeoRabble event:

Announcing GeoRabble Perth #5  - Return to Yesteryear -
Thursday, March 14, 2013
Venue: Upstairs at the Leederville Hotel
Time: Door @ 5:30pm for a 6:00pm start of presentations
Speakers:
Mike Bradford
Tom Gardner
More Speakers and the event sponsor to be announced very soon

As you can see from the QGIS Perth User Group invitation I will be attending and presenting - practice makes prefect - so I'm really looking forward to the event. Still not sure what I'm going to cover yet though.

Joining Layers in QGIS

Joining tables allows a layer with the attributes of both source layers to be created. Joins can be based on common attributes or common location (spatial join).

The joined fields are displayed as a new view rather than actually added to the layer. However the join is saved with the project and it will be reloaded each time the project is opened. To permanently add the joined fields to the layer, it must be saved as a new file. To do this, right click on the layer in the Layer Panel and select Save As.

This is because databases are generally designed to be more permanent data repositories than spreadsheets. Therefore their structure shouldn’t be changed for short term projects. Queries can be run and saved without affecting the underlying data.

Join on Common Attributes:-

This method is similar to ArcGIS’ Joins and Relates function. This is done by creating a Vector Join in the layer’s Properties box:-

  1. Right click on the layer in the Layer Panel
  2. Select Properties to open the Properties dialogue box
  3. Select the Join tab
  4. Press the + button to create a new Vector Join:-
Add Vector Join in QGIS

Add Vector Join in QGIS

The Add Vector Join dialogue box opens:-

  • Join Layer – the layer that the join will be to
  • Join Field – the layer in the Join Layer that contains the common attribute
  • Target Field – the field in the currently selected layer that contains the common attribute

Join By Location (Spatial Join)

This function creates a new shapefile containing the geometry of the target layer and the attributes of both layers. The join is based on the Joining layer overlapping or intersecting the target layer:-

  1. Use the menus to select Vector, Data Management Tools; Join Attributes by Location
  2. The Join Attributes by Location box opens, select:-
  • Select the Target vector Layer (the layer to update)
  • Select Join Vector Layer (the layer that will provide the new data)
  • Attribute Summary. This determines the action when a target feature is overlapped by multiple join features:-Take the attributes of the first located feature.
  • Take a summary of intersecting features
  • Output Shapefile – the file that will contain the new data.
Join By Location (Spatial Join) in QGIS

Join By Location (Spatial Join) in QGIS


Installing python GDAL into a python virtualenv in OSX

Yes I know its a bit wierd to see the word ‘OSX’ in an article by me…I recently bought a Mac for testing InaSAFE and fooling around with FOSSGIS software on OSX. Besides the 2 or three days it took to get it set up as a development machine for FOSSGIS stuff (as compared to... Read more »

Installing python GDAL into a python virtualenv in OSX

Yes I know its a bit wierd to see the word 'OSX' in an article by me...I recently bought a Mac for testing InaSAFE and fooling around with FOSSGIS software on OSX. Besides the 2 or three days it took to get it set up as a development machine for FOSSGIS stuff (as compared to a few hours - limited mainly by internet speed - on Linux) it hasnt been too bad an experience.

I used William Kyngesburye's excellent packages for installing all the FOSSGIS dependencies (barring QGIS which of course I wanted to build myself). I've been trying to see if I can use OSX as a usable platform for doing GeoDjango work and ran into a few problems:

  • GDAL python package needs compilation when used in a python virtualenv (which of course I use)
  • William's packages provide PostGIS 2.0 whereas GeoDjango really only works out of the box with 1.5 still

In this post I am outlining how I got GDAL to build in my venv. Note that I assume you have Williams frameworks and xcode / compilation toolchain in place.

source venv/bin/activate
pip install --no-install GDAL
cd venv/build/GDAL
python setup.py build_ext \
  --gdal-config=/usr/local/gdal/1.9/bin/gdal-config \
  --library-dirs=/Library/Frameworks/GDAL.framework/Versions/1.9/unix/lib/ \
  --include-dirs=/Library/Frameworks/GDAL.framework/Versions/1.9/Headers/
pip install --no-download GDAL

Now verify it is installed:

pip freeze

You should see GDAL listed. Another check:

>>> from osgeo import gdal
>>> gdal.__version__
'1.9.2'

Confirm it is really using your module in your venv:

>>> gdal.__file__
'/Users/timlinux/dev/python/catalogue/venv/lib/python2.7/site-packages/osgeo/gdal.pyc'

Howto shrink a remote root ext3 filesystem on Debian wheezy

This howto describes how to resize a root ext3 filesystem on a remote Debian wheezy server.

This howto is not an original work but only an update of an older howto by Stefan @ https://thunked.org/. This version is specifically adapted to a server running Debian wheezy.

DISCLAIMER:

THERE IS A DECENT CHANCE THAT IF YOU FUCK THIS UP YOUR
REMOTE SYSTEM SIMPLY WONT BOOT AT ALL.  I URGE YOU TO TEST
THIS LOCALLY BEFORE USING THIS METHOD ON A PRODUCTION
SYSTEM. ESPECIALLY IF YOUR SYSTEM IS NOT DEBIAN WHEEZY,
SINCE THAT'S THE ONLY ONE I HAVE TESTED.

THE QUICK WAY:

If you don't want to read the whole thing you can only
execute the commands I run and probably skip the
explanations.

I’ve only done this on Debian Wheezy. If you’re using another distro the initrd layout and init scripts may be a bit different. However, I suspect it looks very similar on almost every distro out there. On Debian my root partition is an ext3 partition.

The general idea is pretty simple: you can’t shrink a mounted partition and it’s impossible to unmount or replace your root partition in a live system, so we have to resize the partition before it is mounted. What we’ll do to accomplish this is change the initrd image to make the init scripts resize the root partition before mounting it. This is by far the most flexible and easy method to resize your root partition I could think of. Most suggestions I found on google required you to create separate OS on a new root partition and boot into that, but I did not have any space to create a new root partition on my remote machine.

Unpacking the initrd image is fairly straight forward:

$ mkdir ~/initrd; cd ~/initrd
$ gunzip -c /boot/initrd.img-3.2.0-3-amd64 | cpio -i --make-directories
62631 blocks
$ ls -l
total 40
drwxr-xr-x 2 root root 4096 Sep 11 20:23 bin
drwxr-xr-x 3 root root 4096 Sep 11 20:23 conf
drwxr-xr-x 6 root root 4096 Sep 11 20:23 etc
-rwxr-xr-x 1 root root 6797 Sep 11 20:23 init
drwxr-xr-x 7 root root 4096 Sep 11 20:23 lib
drwxr-xr-x 2 root root 4096 Sep 11 20:23 lib64
drwxr-xr-x 2 root root 4096 Sep 11 20:23 run
drwxr-xr-x 2 root root 4096 Sep 11 20:23 sbin
drwxr-xr-x 6 root root 4096 Sep 11 20:23 scripts

First, we have to copy all the programs we need to resize our partition onto the initial ram disk. For my ext3 file system I need e2fsck and resize2fs. The programs are depending on a few libraries, so you’ll need to copy those to the new initrd image too. Libraries can also depend on other libraries, make sure you recursively check dependencies until you don’t have any missing dependencies anymore.

$ ldd /sbin/e2fsck
    linux-vdso.so.1 =>  (0x00007fff3594c000)
    libext2fs.so.2 => /lib/x86_64-linux-gnu/libext2fs.so.2 (0x00007f7cdddd5000)
    libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f7cddbd1000)
    libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f7cdd9a9000)
    libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f7cdd7a4000)
    libe2p.so.2 => /lib/x86_64-linux-gnu/libe2p.so.2 (0x00007f7cdd59c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7cdd214000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7cdcff8000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7cde01e000)
$ ldd /sbin/resize2fs
    linux-vdso.so.1 =>  (0x00007fffa216a000)
    libe2p.so.2 => /lib/x86_64-linux-gnu/libe2p.so.2 (0x00007fa01f7a2000)
    libext2fs.so.2 => /lib/x86_64-linux-gnu/libext2fs.so.2 (0x00007fa01f55f000)
    libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007fa01f35a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa01efd3000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa01edb7000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fa01f9b0000)

We only copy the libraries that are not yet present in the initramfs. Fortunately in our case there are no recursive dependencies of those libraries.

$ for i in libext2fs.so.2.4 libcom_err.so.2.1 libe2p.so.2.3; do \
     cp -i /lib/x86_64-linux-gnu/$i lib/x86_64-linux-gnu/; \
  done
$ cd lib/x86_64-linux-gnu/
$ ln -s libcom_err.so.2.1 libcom_err.so.2
$ ln -s libext2fs.so.2.4 libext2fs.so.2
$ ln -s libe2p.so.2.3 libe2p.so.2
$ cd ~/initrd/

$ cp /sbin/e2fsck ~/initrd/bin/
$ cp /sbin/resize2fs ~/initrd/bin/

Next, we need to edit the init script. Debian uses busybox in its initrd image so the init script will be interpreted by a bourne shell. If you look through the init script file you’ll find the moment where the script mounts the root file system:

$ cat scripts/local
...
    # FIXME This has no error checking
    # Mount root
    if [ "${FSTYPE}" != "unknown" ]; then
            mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
    else
            mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
    fi
...

Simply add in the commands to resize the file system right before the the file system is mounted. Resize2fs in Debian does not want to resize the file system before it is forcefully checked. It may be wise to add the -p or -y flag to e2fsck. -y will answer yes to all questions, this could prevent a hung system but may cause more damage to your files or filesystem. The -p flag will only automatically answer yes to safe operations. resize2fs takes two parameters, the first is the block device that has the ext2 or ext3 file system and the second is the new size you want to give it. By default the size is in blocks, but you can append a unit to change that. ‘K’ for kilobytes, ‘M’ for megabytes, ‘G’ for gigabytes and ‘T’ for terabytes. If you don’t specify a size, it will enlarge the file system to the total size of the partition or logical volume. After adding the commands the init script will look something like this:

    #RESIZEROOTFS MODIFIED!!! DONT RUN MORE THAN ONCE
    _log_msg "Starting e2fsck"
    /bin/e2fsck -p -f -C 0 /dev/sda4 || true
    _log_msg "Starting resize2fs"
    /bin/resize2fs /dev/sda4 100G || true

    # FIXME This has no error checking
    # Mount root
    if [ "${FSTYPE}" != "unknown" ]; then
            mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
    else
            mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
    fi

If you have access to the system’s console, you might want to add a “-C 0” to e2fsck’s parameters. That will show you the progress of the fscheck.

There’s one last thing we have to do before re-packing the initrd image. e2fsck and resize2fs will fail if there is no /etc/mtab file available so we’ll have to make sure /etc/mtab exists.

$ touch ~/initrd/etc/mtab
$ cd ~/initrd/
$ find ./ | cpio -H newc -o > /tmp/initrd.cpio
64097 blocks
$ gzip -c /tmp/initrd.cpio > /boot/initrd-resize.img

And lastly, we need to add a new default boot option in grub. In Debian grub’s configuration file is constructed from various bits under /etc/grub.d. The resulting total configuration file is put under /boot/grub/grub.cfg. Open up the grub.cfg file in your favorite text editor and look for the default entry. It’s usually the first one, but may vary. Add a copy of the original entry to /etc/grub.d/40_custom and change the initrd image to the one we just created.

$ cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry 'resize' --class debian --class gnu-linux --class gnu --class os {
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='(hd0,gpt1)'
        search --no-floppy --fs-uuid --set=root 0aa8bc27-17e3-4ae2-a9cf-497ab444970b
        echo    'Loading Linux 3.2.0-3-amd64 ...'
        linux   /vmlinuz-3.2.0-3-amd64 root=UUID=660f79dc-c152-4e15-ad61-7075b42de609 ro  quiet
        echo    'Loading initial ramdisk ...'
        initrd  /initrd-resize.img
}

Now make sure that it’s this entry that will be booted into by default. Set GRUB_DEFAULT in /etc/default/grub to the name of the entry you’ve just created:

$ cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

#GRUB_DEFAULT=0
GRUB_DEFAULT="resize"
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX=""
...

Finally, you can reboot the system. When it comes back online (if it comes back grin) your file system will be resized. Be aware that e2fsck and resizefs take a long time on big disks. On my system the two took 2 hours for a 1.5T filesystem. Thus don’t prematurely reboot your system if it doesn’t come up again quickly.

Don’t forget to remove the new grub entry, so your file system doesn’t get resized every time you boot.

Original howto at https://thunked.org/general/howto-shrink-a-remote-root-ext3-filesystem-t96.html

Original howto Written by Stefan @ https://thunked.org/

This version for Debian wheezy by Tomáš Pospíšek

Creating png8 images with QGIS server

For providing maps via WMS over the internet, it is important to generate image files with a small size. Because normally, most of the perceived WMS delay comes from transfering large images files over the internet (and not from map rendering itself). Therefore, QGIS server supports the conversion of png24 and png32 images into png8, therefore generating a file with only 1/3 resp. 1/4 of the original size (but with lower quality). However, until recently, QGIS server was using the default algorithm from the Qt library for conversion to png8, resulting in very ugly png8 images if used with a transparent background and sometimes with shifted colors. Therefore, I decided to implement a better conversion algorithm: the median cut algorithm, which was first described by Heckbert in 1982 ( Paul S. Heckbert, Color Image Quantization for Frame Buffer Display. ACM SIGGRAPH ‘82 Proceedings). This algorithm creates color boxes in 4-dimensional colour space and subdivides at the mean of the largest dimension. It stops if the number of boxes equals the requested number of colors (256 in the case of png8 conversion). First tests show the quality of the converted images are quite good for vector maps. So a performant configuration for a webmap means probably to fetch background rasters as jpg and to overlay vectors as png8 with transparent background.

Let’s see with an example what the conversion from png24 to png8 means in terms of image quality. The first file is a png24 image, 590 KB size:

And this one is the conversion to png8, only 190 KB size.

To test the png8 conversion, you need to have the latest QGIS version from git (or a nightly build tomorrow). Then simply replace the FORMAT paramter in the url with ‘&FORMAT=image/png; mode=8bit’.

New configuration options in QGIS server

In QGIS server, it is now possible to selectively exclude layers from WMS publication. These layers will be available only on the desktop and hidden from WMS clients. Similarly, print layouts can be excluded from WMS publication. Of course, these settings are conveniently accessible from the project properties dialog of QGIS (but you need to have a nightly build or a recent compile):

Additionally, attributes per layer can be excluded from WMS or WFS publication in the vector properties dialog:

There is also a new request type called ‘GetProjectSettings’. The output of this request is similar to the GetCapabilities output, but with more details and more specific to QGIS:

  • Initial visibility of layers
  • Information about vector attributes and their edit types
  • Information about layer order and drawing order
  • List of layers published in WFS

These new features have been developed in collaboration and with funding from the city of Uster. More details are available on the QGIS server / webclient wiki page

The state of QGIS Globe

The Region of Umbria, Italy, sponsored 4 days of work to update QGIS Globe for current QGIS versions. Most of the functionality is working again and the globe is now compatible with osgEarth 1.0 up to 1.3. The bad news is, that the globe plugin is not working on Windows with OSGeo4W. It seems that one of the OSGeo4W libraries (GDAL?) is compiled with an incompatible MS compiler version. Christmas holidays are coming…

At least it gives Linux users the possibility to play with the globe using the current development version and do exciting stuff like Oslandia does:

PostGIS 3D demo

Imagine someone would sponsor four weeks of QGIS Globe work!

Kursprogramm Frühjahr 2013

Sourcepole bietet Grundlagen- und Aufbau-Kurse für den Betrieb von Geodaten-Infrastrukturen auf der Basis von PostgreSQL/PostGIS und Quantum GIS an. Detaillierte Informationen zu den Kursen, die im Frühjahr 2013 stattfinden, entnehmen Sie bitte http://www.sourcepole.ch/kurse Die Anmeldung ist ab sofort online möglich. Wir freuen uns darauf Sie in Zürich begüssen zu können.

Identify feature on map

A very awaited feature is now available in the master version of QGIS: identifying features in the map!

You can define the class of the map tool as follows:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

class IdentifyGeometry(QgsMapToolIdentify):
 def __init__(self, canvas):
  self.canvas = canvas
  QgsMapToolIdentify.__init__(self, canvas)

 def canvasReleaseEvent(self, mouseEvent):
  results = self.identify(mouseEvent.x(),mouseEvent.y(), self.TopDownStopAtFirst, self.VectorLayer)
  if len(results) > 0:
   self.emit( SIGNAL( "geomIdentified" ), results[0].mLayer, results[0].mFeature)

This class will try to identify a feature of any visible vector layer and returning the first found feature (using layer order). Then, it will emit the signal with the layer and the feature identified.
To customize this, you can use the identify method with different arguments:

  • type of layer
  • type of identification (current layer, top-down, top-down stop at first or the QGIS setting)
  • list of layers

There is two ways of calling the identify methods:

  • identify (x, y, layerList=[], IdentifyMode mode=self.DefaultQgsSetting)
  • identify (x, y, identifyMode, layerType=AllLayers)

Identify mode and layer types are defined here. Mainly the options can be:

  • Identify mode: self.DefaultQgsSetting, self.ActiveLayer, self.TopDownStopAtFirst, self.TopDownAll
  • Layer type: self.AllLayers, self.VectorLayer, self.RasterLayer

Both methods return a structure IdentifyResult defined in the API. Mainly, it contains:

  • the feature (mFeature) if the identified layer is a vector layer
  • the corresponding layer (mLayer)
  • the derived attributes (mDerivedAttributes): the raster value for raster layers

In your plugin main code, you can define a toolbox button to enable your map tool:

class myPlugin():
 def initGui(self):
  self.mapToolAction = QAction(QIcon(":/plugins/myPlugin/icons/myIcon.png"), "My Plugin", self.iface.mainWindow())
  self.mapToolAction.setCheckable(True)
  QObject.connect(self.mapToolAction, SIGNAL("triggered()"), self.mapToolInit)
  self.iface.addToolBarIcon(self.mapToolAction)
  self.iface.addPluginToMenu("&My Plugin", self.mapToolAction)

 def mapToolInit(self):
  canvas = self.iface.mapCanvas()
  if self.mapToolAction.isChecked() is False:
   canvas.unsetMapTool(self.mapTool)
   return
  self.mapToolAction.setChecked( True )
  self.mapTool = IdentifyGeometry(canvas)
  QObject.connect(self.mapTool , SIGNAL("geomIdentified") , self.doSometing )
  canvas.setMapTool(self.mapTool)
  QObject.connect( canvas, SIGNAL( "mapToolSet(QgsMapTool *)" ), self.mapToolChanged)</em>

 def doSomething(self, layer, feature):
  # do something

If you want your plugin to be back compatible with version before 1.9, you can select the features at the clicked point using a given tolerance and using the current layer:

try:
 from qgis.gui import QgsMapToolIdentify
except:
 from qgis.gui import QgsMapTool as QgsMapToolIdentify

class IdentifyGeometry(QgsMapToolIdentify):
 def __init__(self, canvas):
  self.canvas = canvas
  QgsMapToolIdentify.__init__(self, canvas)

 def canvasReleaseEvent(self, mouseEvent):
  try:
  results = self.identify(mouseEvent.x(),mouseEvent.y(), self.TopDownStopAtFirst, self.VectorLayer)
  if len(results) > 0:
   self.emit( SIGNAL( "geomIdentified" ), results[0].mLayer, results[0].mFeature)
  except: # qgis <1.9
   point = self.toMapCoordinates( mouseEvent.pos() )
   layer = self.canvas.currentLayer()
   if layer == None:
    return
   if layer.type() != QgsMapLayer.VectorLayer:
    return
   point = self.canvas.mapRenderer().mapToLayerCoordinates(layer, point)
   pixTolerance = 6
   mapTolerance = pixTolerance * self.canvas.mapUnitsPerPixel()
   rect = QgsRectangle(point.x()-mapTolerance,point.y()-mapTolerance,point.x()+mapTolerance,point.y()+mapTolerance)
   provider = layer.dataProvider()
   provider.select([], rect, True, True)
   subset = []
   f = QgsFeature()
   while (provider.nextFeature(f)):
    subset.append(f)
    if len(subset) == 0:
     return
    if len(subset) > 1:
     idx = QgsSpatialIndex()
    for f in subset:
     idx.insertFeature(f)
     nearest = idx.nearestNeighbor( point, 1 )
     layer.featureAtId(nearest[0],f, True, False)
    self.emit( SIGNAL( "geomIdentified" ), layer, f)

Note, that this last code (for version <1.9) does not consider scale dependent visibility and can therefore return a feature which is not visible in the map!

Back home from heart surgery

Disclaimer: strictly offtopic :) Just a personal health state report, nutshell version…

Maybe some have noted my temporal “disappearance” from email and such in January. The reason was that I spent almost 50 days in hospital since beginning of December. So, what happened?

On 10th December I went to the “Centro Gallucci” of the Padua University Hospital for “routine” examinations in preparation for a future surgery (I know of my heart problems for years; they did not have much effect on my life since I was asymptomatic). But after the initial examinations they scheduled me for an emergency surgery. Err, little shock…

Eventually, I got the open heart surgery on 3rd January (“Bentall-De Bono” method, 7hs of surgery in total, 2hs heart in standstill). During the surgery they realized that the heart state was even worse than known before, with an estimated life expectancy of perhaps months only not having it done immediately (they got me from the cliff). Anyway, the surgery went well, I have now a mechanical valve + ascending aorta (so, you can hear me now :p). BTW: you go in awake, the Padua staff was really nice. And interesting to see how they prepare the surgery, a busy moment (then send make you sleep in no time).

On 10th January I was send to the rehabilitation center (Codivilla-Putti hospital, Cortina d’Ampezzo). However, I got a complication which is not uncommon: inner bleedings with a starting cardiac tamponade as discovered some days later. On 14th January, during heavy snowfall at Cortina, high speed ambulance ride back to Padua, with immediate drainage surgery (lung area and heart, removing more than 2l of liquid). Not really fun… (this little surgery also on a Monday, same time, same room, same staff!). But after some days I got way better. Just 10% of my body weight was meanwhile gone.

On 23rd January I was brought back again to the Cortina rehabilitation center where I spend two nice weeks – no more issues so far :-)

Since 5th February I am back home – and will stay here for a longer while. Various odds and ends need to be resolved first – the recovery is long but steady!

D6JJYVCDUD7M

Creating a simple habitat selection model in Sextante.

My QGIS git workflow

I thought it might be handy to post the git workflow that I use when working on QGIS, or any project for that matter.

In the following examples upstream = https://github.com/qgis/Quantum-GIS.git. If you have cloned from your github fork of QGIS you can add upstream using:

$ git remote add upstream https://github.com/qgis/Quantum-GIS.git

The first thing we need to do is pull down the latest changes from the main QGIS repo aka upstream

$ git fetch upstream
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 7 (delta 6), reused 7 (delta 6)
Unpacking objects: 100% (7/7), done.
From github.com:qgis/Quantum-GIS
   18cd145..89bdb10  master     -> upstream/master

Now that we have the changes in our local repo we need to bring our master branch up to date with the latest changes from upstream. I use rebase here because I don't want to see merge master into master etc etc each time I want to bring my master branch up to date. In the end I want my local master branch to reflect upstream/master exactly

$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master.

Note: You can combine the two into one call using: git pull upstream master --rebase

In order to do any work in git you should really be using branches. We can check a new one out using:

$ git checkout -b working
Switched to a new branch 'working'

This will checkout a new working branch off my local master branch and switch to it.

Lets do some work.

$ git commit -a -m "Add some feature"
[working 8cd2f4b] Add some feature

$ git commit -a -m "More feature stuff"
[working 72d30ad] More feature stuff

$ git commit -a -m "bug fix"
[working 25b10e5] bug fix

$ git commit -a -m "bug fix"
[working 211e387] bug fix

Note: The -a means add any changed files to the commit. You can also use git add. I'm trusting you already understand how to add files to a commit.

Now at this point I could merge my changes into the master branch and push it up, or if you don't have commit rights you can issue a pull request. However having heaps of "fix this", "fix that" commits is pretty ugly. This is where git rebase can come in handy.

We can check which commits we have added that are not in master by doing:

$ git log --oneline master..
211e387 bug fix
25b10e5 bug fix
72d30ad More feature stuff
8cd2f4b Add some feature

git2.png

There we can see we have four commits that differ and that 8cd2f4b is the first commit we made. I really want to merge all the commits into one to make this a little cleaner.

$ git rebase -i 8cd2f4b^

Note: ^ means go back one commit from the one listed. git rebase doesn't include the commit that you list so you have to go back one before it.

pick 8cd2f4b Add some feature
f 72d30ad More feature stuff
f 25b10e5 bug fix
f 211e387 bug fix

# Rebase 89bdb10..7d02daf onto 89bdb10
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

I have changed all but the first commit to f this will merge all the commits into the first one. The latest commit is at the bottom so you should read the rebase screen from bottom up.

[detached HEAD d5620a5] Add some feature
 1 file changed, 3 insertions(+)
 create mode 100644 test.txt
Successfully rebased and updated refs/heads/working.

git1.png

At this point I normally merge it into master and push it upstream, but if you don't have commit rights then you can push it up to your github repo and open a pull request.

# Push them up for review
$ git push myrepo working

Important Note:

git rebase -i will change the commit hash for anything that is included in the range of commits. Make sure you only rebase commits that are not public yet. Only rebase commits that in your local repo.

My QGIS git workflow

I thought it might be handy to post the git workflow that I use when working on QGIS, or any project for that matter.

In the following examples upstream = https://github.com/qgis/Quantum-GIS.git. If you have cloned from your github fork of QGIS you can add upstream using:

$ git remote add upstream https://github.com/qgis/Quantum-GIS.git

The first thing we need to do is pull down the latest changes from the main QGIS repo aka upstream

$ git fetch upstream
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 7 (delta 6), reused 7 (delta 6)
Unpacking objects: 100% (7/7), done.
From github.com:qgis/Quantum-GIS
   18cd145..89bdb10  master     -> upstream/master

Now that we have the changes in our local repo we need to bring our master branch up to date with the latest changes from upstream. I use rebase here because I don't want to see merge master into master etc etc each time I want to bring my master branch up to date. In the end I want my local master branch to reflect upstream/master exactly

$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master.

Note: You can combine the two into one call using: git pull upstream master --rebase

In order to do any work in git you should really be using branches. We can check a new one out using:

$ git checkout -b working
Switched to a new branch 'working'

This will checkout a new working branch off my local master branch and switch to it.

Lets do some work.

$ git commit -a -m "Add some feature"
[working 8cd2f4b] Add some feature

$ git commit -a -m "More feature stuff"
[working 72d30ad] More feature stuff

$ git commit -a -m "bug fix"
[working 25b10e5] bug fix

$ git commit -a -m "bug fix"
[working 211e387] bug fix

Note: The -a means add any changed files to the commit. You can also use git add. I'm trusting you already understand how to add files to a commit.

Now at this point I could merge my changes into the master branch and push it up, or if you don't have commit rights you can issue a pull request. However having heaps of "fix this", "fix that" commits is pretty ugly. This is where git rebase can come in handy.

We can check which commits we have added that are not in master by doing:

$ git log --oneline master..
211e387 bug fix
25b10e5 bug fix
72d30ad More feature stuff
8cd2f4b Add some feature

Alt Text

There we can see we have four commits that differ and that 8cd2f4b is the first commit we made. I really want to merge all the commits into one to make this a little cleaner.

$ git rebase -i 8cd2f4b^

Note: ^ means go back one commit from the one listed. git rebase doesn't include the commit that you list so you have to go back one before it.

pick 8cd2f4b Add some feature
f 72d30ad More feature stuff
f 25b10e5 bug fix
f 211e387 bug fix

# Rebase 89bdb10..7d02daf onto 89bdb10
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

I have changed all but the first commit to f this will merge all the commits into the first one. The latest commit is at the bottom so you should read the rebase screen from bottom up.

[detached HEAD d5620a5] Add some feature
 1 file changed, 3 insertions(+)
 create mode 100644 test.txt
Successfully rebased and updated refs/heads/working.

Alt Text

At this point I normally merge it into master and push it upstream, but if you don't have commit rights then you can push it up to your github repo and open a pull request.

# Push them up for review
$ git push myrepo working

Important Note:

git rebase -i will change the commit hash for anything that is included in the range of commits. Make sure you only rebase commits that are not public yet. Only rebase commits that in your local repo.

My QGIS git workflow

I thought it might be handy to post the git workflow that I use when working on QGIS, or any project for that matter.

In the following examples upstream = https://github.com/qgis/Quantum-GIS.git. If you have cloned from your github fork of QGIS you can add upstream using:

$ git remote add upstream https://github.com/qgis/Quantum-GIS.git

The first thing we need to do is pull down the latest changes from the main QGIS repo aka upstream

$ git fetch upstream
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 7 (delta 6), reused 7 (delta 6)
Unpacking objects: 100% (7/7), done.
From github.com:qgis/Quantum-GIS
   18cd145..89bdb10  master     -> upstream/master

Now that we have the changes in our local repo we need to bring our master branch up to date with the latest changes from upstream. I use rebase here because I don't want to see merge master into master etc etc each time I want to bring my master branch up to date. In the end I want my local master branch to reflect upstream/master exactly

$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master.

Note: You can combine the two into one call using: git pull upstream master --rebase

In order to do any work in git you should really be using branches. We can check a new one out using:

$ git checkout -b working
Switched to a new branch 'working'

This will checkout a new working branch off my local master branch and switch to it.

Lets do some work.

$ git commit -a -m "Add some feature"
[working 8cd2f4b] Add some feature

$ git commit -a -m "More feature stuff"
[working 72d30ad] More feature stuff

$ git commit -a -m "bug fix"
[working 25b10e5] bug fix

$ git commit -a -m "bug fix"
[working 211e387] bug fix

Note: The -a means add any changed files to the commit. You can also use git add. I'm trusting you already understand how to add files to a commit.

Now at this point I could merge my changes into the master branch and push it up, or if you don't have commit rights you can issue a pull request. However having heaps of "fix this", "fix that" commits is pretty ugly. This is where git rebase can come in handy.

We can check which commits we have added that are not in master by doing:

$ git log --oneline master..
211e387 bug fix
25b10e5 bug fix
72d30ad More feature stuff
8cd2f4b Add some feature

Alt Text

There we can see we have four commits that differ and that 8cd2f4b is the first commit we made. I really want to merge all the commits into one to make this a little cleaner.

$ git rebase -i 8cd2f4b^

Note: ^ means go back one commit from the one listed. git rebase doesn't include the commit that you list so you have to go back one before it.

pick 8cd2f4b Add some feature
f 72d30ad More feature stuff
f 25b10e5 bug fix
f 211e387 bug fix

# Rebase 89bdb10..7d02daf onto 89bdb10
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

I have changed all but the first commit to f this will merge all the commits into the first one. The latest commit is at the bottom so you should read the rebase screen from bottom up.

[detached HEAD d5620a5] Add some feature
 1 file changed, 3 insertions(+)
 create mode 100644 test.txt
Successfully rebased and updated refs/heads/working.

Alt Text

At this point I normally merge it into master and push it upstream, but if you don't have commit rights then you can push it up to your github repo and open a pull request.

# Push them up for review
$ git push myrepo working

Important Note:

git rebase -i will change the commit hash for anything that is included in the range of commits. Make sure you only rebase commits that are not public yet. Only rebase commits that in your local repo.

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:     Here is another one showing a few charts together:   I added the feature because I wanted to see how many... Read more »

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

Back to Top

Sustaining Members