Two interesting plugins for QGIS

QGIS has made its mark in FOSS4G and third party plugins make it more and more attractive. I will introduce two more plugins today which could also be useful  for you.


If you have many layers that require a similar style, you have to assign style for each layer one by one. Not any more, MultiQml can perform this tedious task for you.

First load all required layers. Second,  style any one layer and save the styling information as ‘QGIS Layer Style File’ below. You can use ‘Layer properties’ form to save styles (see below).

Screenshot from 2016-02-17 16:04:54

Start MultiQml from menu, perform the following

  1. Raster / Vector layer type
  2. Select all layers
  3. Apply style

Screenshot from 2016-02-17 16:09:32

The final operation will apply the same style (theme) to all the layers (in one go, saves a lot of time :)).

Table manager

In QGIS, if you want to change the attribute of shape file it is not possible directly. For example, you want to change the upper case character in field ‘Name’ to ‘name’, you cannot do that.

Now some one might think, why would I want to change the attributes from upper to lower characters. Well …. actually you don’t need to until you wan to upload this shape file to PostgreSQL/Postgis. If you have upper case character as attribute names (or as field names in database terms), you cannot access them (in a query) like normal attributes. For example a select on country shape file with upper character  (below) will return an error

select * from country where Name = ‘Sweden’;

one way to to correct the above query is to use quotes in field name

select * from country where “Name” = ‘Sweden’;

OR use ‘Table manager’ plugin to edit the attribute names. Start ‘Time Manager’ and it will pick the active layer and will show you all the attributes (below)

Screenshot from 2016-02-17 16:32:19

You can rename a attribute, change attribute order, clone an attribute, insert an attribute and delete an attribute.

puts, print and p in ruby

I’ve been trying to pick up Ruby and one of the things I was asking myself was the difference in the various ways you can output text.

  • puts: displays text and adds a newline character
  • print: displays text and doesn’t add a newline character (this means you must add newlines manually when using print)
  • p: while it’s similar to puts in that it adds a newline, it calls inspect instead of to_s This is why p can be more useful for debugging since it shows what class an object belongs to.

Screen Shot 2016-02-08 at 19.02.38

More references for those interested


Developing on OS X – Part 1

This multipart series will take you through how to setup a Python development environment on OS X Yosemite & El Capitan.  We will setup Python…and the various helpers I use for Django development.  We’ll also install a few other applications I make use of in my day-to-day coding activities.  For this first part, we’ll go through settings up the various helper applications we’ll end up using for our Python setup

Enabling Writing to NTFS

Install Homebrew and Homebrew Cask

For anyone new to OS X, homebrew is a package manager, and it enables you to install command-line applications and libraries that would require manual compilation.  While Homebrew Cask extends Homebrew.

To install homebrew, run this command on your terminal:

ruby -e "$(curl -fsSL"

To get Homebrew Cask run this command on your terminal:

brew tap caskroom/cask

We’re now ready to install osxfuse…El Capitan users will want to install the 3.x.x version (3.1.0 or higher would be best) to avoid System integrity Protection issues  For Yosemite, brew will suffice

brew cask install osxfuse

The final step to give you write-access to NTFS will be to install ntfs3g.

brew install homebrew/fuse/ntfs-3g

If using El Capitan, System Integrity Protection’s fs role will first need to be disabled.  This is needed to enable writing to /sbin

  • reboot and hold CMD+R to go into recovery mode
  • Run this on a terminal: $ csrutil disable
  • reboot normally

Create a symlink to mount NTFS

sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.original
sudo ln -s /usr/local/sbin/mount_ntfs /sbin/mount_ntfs

Remember to re-enable System Integrity Protection (and re-lock the system directories) if you’d previously disabled it (same steps as before), only run $ csrutil enable

After that you should now be able to read and write to your NTFS drives.


Xcode is an integrated development environment (IDE) containing a suite of software development tools developed by Apple for developing software for OS X and iOS.  While you don’t need the entire suite, you’ll want to install the command line tools.  Run this command then follow the instructions:

xcode-select --install


I always like having a good terminal at my disposal…iterm2 is my custom terminal of choice on OS X.  To get iTerm2, download and install it as a normal OS X pkg file

Version Control

It’s always recommended to have a VCS in place when you’re writing your code….this way you can always revert to a previously working version of your code if you break something along the line.  It’s a matter of personal preference which VCS you use, but I like git.  And for anyone new to VCS, this handy guide explains it all.

To install git:

brew install git


Next step is to configure git for your setup.  If you haven’t configured your SSH keys, that would be the first thing.  If you get stuck, this Github link will help

ssh-keygen -t rsa -C "<your-email-address>"
git config --global "<your-name>"
git config --global "<your-email-address>"


After this add your key to your Github account (same process for Bitbucket or any other code hosting site where you can upload your SSH keys).


  • You can never be too careful with your code so it’s always a good idea to enable two-factor authentication whenever possible.
  • For Android users, if you change phones frequently, instead of the Google Authenticator app, you can check out Authy…it’s slightly better since it has a clud backup feature, and if you’re a Chrome user, you can even register your browser as an MFA device

That’s it for the basics…in the next blog post we’ll get down and dirty with getting Python running

Time series animations using QGIS

For the past couple of months, I am working with vegetation indices (NDVI and EVI) time series data. Today, I decided to visualize some of the EVI data as an animation.

QGIS has an excellent plugin know as “TimeManager“. You can install “TimeManager” by selecting Plugins-> Manage and Install Plugins from QGIS menu. Search TimeManager in plugin window (like below)

Screenshot from 2015-12-17 15:22:50

After installation, you have to activate TimeManager plugin by clicking on it. A window (like below) will appear at the bottom of monitor screen.

Screenshot from 2015-12-17 15:21:24

Assuming that you have loaded and styled all the layers that will be used in animation, click the “setting” button on the TimeManager’s window. A new window will appear like the one below

Screenshot from 2015-12-17 16:05:45

Now add the layer, start and end time. In my case, I used “Add raster” option to add EVI layers, each layer had one second of visibility during animation. Following is an image of how my setting window looked like.

Screenshot from 2015-12-17 15:21:54

Finally, press “Export Video” button, a new window will appear like the one below.

Screenshot from 2015-12-17 15:22:14

Select the output folder and click on “Animation gif” radio button. If required, modify the “Animation frame Delay”, for my dataset, 100 millisec was too low thus I changed it to 1000 millisec.

The processing might take from few seconds to few minutes, in my case it two around 4 to 5 minutes (result below)


Some very good examples of TimeManager plugin are available on youtube, like the one below

and also this one.

GeoWebCache under GeoServer

Few months back I wrote about GeoWebCache in my post “GeoWebCache under GeoNode“. Today I noticed a strange beheaviour from GeoWebCache as some of my newly added layers were not being cached.

If GeoWebCache is working properly, when ever a layer is published in GeoServer, by default a cached layer is created with the same name (one can check this by looking in Tile Layers list under Tile Caching GeoServer menu (left side)). Plus a folder is created with similar name to hold tiles in main cache path (e.g. …./geowebcache/workspace_tree_layer). Now if some one views this layer, GeoWebCache will cache tiles generated by GeoServer (and on next request, these pre-generated tiles will be served, if you want to know more read “Tile Caching and Seeding – GeoWebCache” ). Tiles are stores in their respective folder in main cached path.

Now back to my problem, when I checked cached folder (on server), I found that individual cached folders for each newly  created layer were being generated. But all of these folders were empty (no tiles inside any of the folders). Hmmmmmmmmmmm

As my last resort, I started looking at GeoServer logs and found “no such style” error again and again (it must have been generated when I was seeding these specific layers). I looked at style descriptors (SLDs) and found that when ever I assign SLDs to a specific workspace (no matter if it is the same one of the layer to which this SLD belongs to), the SLD is not available to GeoWebCache. When I removed the workspace information, the GeoWebCache found the SLD and worked perfectly.

Although, I solved the issue but I do not understand why under the same workspace, GeoWebCacbe cannot find style information. I am using GeoServer 2.4 (under GeoNode 2.0).

Clip raster with vector and calculate mean of clipped area, revisited

Two months ago, I posted  “Clip raster with vector and calculate mean of clipped area” blog post. I mentioned in this post that extraction and cellstats were taking time. I posted this blog on as well. One of the users (REORS) responded with few suggestions (see below).

Neat, I’ve got a similar tool in my own code (though my handling of shapefiles is really basic, not got to grips with them in R yet – had other things on my to-do list). Just a few ideas:

  • The extract() function might be closer to what you’re after it bypasses the need to mask out cells, and actually has some fairly advanced settings – this is kind of another case where the raser package has a really useful tool, but keeps somewhat quiet about it.
  • You might consider adding a crop() function infront of the mask(), where the polygon is a lot smaller than the raster this reduces the number of cells R has to mask out (though my notes on the speed of this are fairly subjective).
  • The drawPoly() function is a neat little tool that lets you define a shapefile by clicking on the plot window – though that’s kind of different to what you’re doing here.

and about speed, he sad

If your computer’s as old as the one I use – then speed is really a concern…
My version’s more aimed as a spectral profiler (along the same lines as can be found in ERDAS Imagine), but the broad idea is similar. If you’re interested the code’s here. Would you mind if I borrowed your idea of adding the results to the shapefile (if I can work out how to make it work)?

You can read full comments on this link.  I applied one of the suggestion (the use of crop() function), following is the new code (with couple of changes).

# install.packages("raster") #into your R console 


# (1) I assume that raster and vector are in one EPSG + vector is overlaping raster (polygons)
# (2) Vector and raster are in in project directory

#read shape file
shp = shapefile("Africa_boundaries_4326.shp")

# load reaster
img = raster("monthlyPCP1998_1.tif");

# filter by polygon ( this will go into loop)
country <- c("Algeria","Angola","Benin","Botswana","Burkina Faso","Burundi","Cameroon","Cape Verde","Central African Republic","Chad","Comoros","Congo","Djibouti","Egypt","Equatorial Guinea","Eritrea","Ethiopia","Gabon","Gambia, The","Gaza Strip","Ghana","Guinea","Guinea-Bissau","Ivory Coast","Kenya","Lebanon","Lesotho","Liberia","Libya","Madagascar","Malawi","Mali","Mauritania","Mauritius","Morocco","Mozambique","Namibia","Niger","Nigeria","Reunion","Rwanda","Sao Tome and Principe","Senegal","Seychelles","Sierra Leone","Somalia","South Africa","Sudan","Swaziland","Tanzania, United Republic of","Togo","Tunisia","Uganda","Western Sahara","Zaire","Zambia","Zimbabwe");

output <- matrix(ncol=3, nrow=length(country))

for (i in 1:length(country))

  # now filter
  filtered = shp[match(toupper(country[i]),toupper(shp$name)),]

  #now use the mask function
  # crop() has reduced the area for mask() thus very fast.
  rr <- mask(crop(img, filtered),filtered)

  country_sum <-cellStats(rr, mean, na.rm=TRUE);

  output[i,1] <- i;
  output[i,2] <- country[i];
  output[i,3] <- country_sum;


write.csv(output, file ="data.csv")


Thanks to REORS, Crop() function is reducing the areas to be masked (clipped), thus script became super fast.

Open Source rocks🙂