Tag Archive | lecos

New publication: LecoS now with own reference

As I can see my QGIS plugin LecoS is still widely used and downloaded from the QGIS plugin hub. I have noticed that some people already started referencing ether my blog or the QGIS repository in their outputs, which is fine, but after thinking about it for a while I thought why not make a little descriptive article out of it (being an upstart PhD scholar and scientist an’ all). I am now happy to announce that this article has passed scientific peer-review and is now been published in early view in the Journal of Ecological Informatics.

LecoS — A python plugin for automated landscape ecology analysis

The quantification of landscape structures from remote-sensing products is an important part of many analyses in landscape ecology studies. This paper introduces a new free and open-source tool for conducting landscape ecology analysis. LecoS is able to compute a variety of basic and advanced landscape metrics in an automatized way. The calculation can furthermore be partitioned by iterating through an optional provided polygon layer. The new tool is integrated into the QGIS processing framework and can thus be used as a stand-alone tool or within bigger complex models. For illustration a potential case-study is presented, which tries to quantify pollinator responses on landscape derived metrics at various scales.

The following link provided by Elsevier is still active until the 23 of January 2016. If you need a copy later on and don’t have access to the journal (sorry, I didn’t have the money to pay for open-access fees), then feel free to ether contact me or you can read an earlier prePrint of the manuscript on PeerJ.

So if you are using LecoS in any way for your work, it would be nice if you could reference it using the citation below. That shows me that people are actively using it and gives me incentives to keep on developing it in the future.

Martin Jung, LecoS — A python plugin for automated landscape ecology analysis, Ecological Informatics, Volume 31, January 2016, Pages 18-21, ISSN 1574-9541, http://dx.doi.org/10.1016/j.ecoinf.2015.11.006.

The full sourcecode of LecoS is released on github.

Neutral Landscape model generation with QGIS

There are many interesting things to calculate in relation to landscape ecology and its statistical metrics. However many (if not the majority) of the published toolsets are not reproducible, their algorithm code not published or open-source. Obviously this makes the easy implementation of underlying algorithms even harder for independent developers (scientists) if you don’t have the time to reproduce their work (not to mention the danger of making stupid mistakes, we are all human).

I recently found this new article in Methods in Ecology and Evolution by Etherington et al., who didn’t really present any novel techniques or methods, but instead provided a new python library that is capable of calculating Neutral Landscape Models (NLMs). NLMs are often used as nullmodel counterpart to real remote-sensing derived maps (land-cover or altitude) to test the effect of landscape structure or heterogeneity on a species (-community). Many NLM algorithms are based on cluster techniques, cellular automata or calculating randomly distributed numbers in a given 2d space. There have been critical and considerate voices stating that existing NLMS are often misused and better null-models are needed for specific hypothesis, such as a species perception of landscape structures. Nevertheless NLMs are still actively used and new papers published with it.


Figure by Etherington et al. showing a number of different NLMs


The new library, called NLMpy, is open source and published under the MIT licence. Thus I can easily use and integrate into QGIS and its processing framework. Their NLMpy library only depends on numpy and scipy and thus doesn’t add any other dependency to your python setup, if you already are able to run LecoS in your QGIS installation. The NLM functions are visible in the new LecoS 1.9.6 version, but only if you have NLMpy installed and it is available in your python path. Otherwise they won’t show up! Please don’t ask me here how to install additional python libraries on your machine, but rather consult google or some of the Q&A sites. I installed it following the instructions on this page.

Midpoint displacement algorithm in QGIS

Midpoint displacement algorithm in QGIS

NLM with randomly clustered landcover patches

NLM with randomly clustered landcover patches

After you have installed it and upgraded your LecoS version within QGIS, you should be able to spot a new processing group and a number of new algorithms. Here are some screenshots that show the new algorithms and two NLMs that I calculated. The first one is based on a Midpoint displacement algorithm and could be for instance used to test against an altitude raster layer (need to reclassify to real altitude values first). The second one is aimed at emulating a random classified land-cover map. Here I first calculated a proportional NLM using a random cluster nearest-neighbour algorithm. Second I used the libraries reclassify function (“Classify proportional Raster”) to convert the proportional values (range 0-1) into a relative number of landcover classes with exactly 6 different land-cover classes. Both null model look rather realistic, don’t they 😉

This is a quick and dirty implementation, so there could occur some errors. You should use a meter-based projection as extent (such as UTM) as negative values (common in degree-based projections like WGS84 latitude-longitude) sometimes result in strange error messages. You also have to change the CRS of the generated result to the one of your project manually, otherwise you likely won’t see the result. Instead of the number of rows and columns as in the original implementation, the functions in LecoS are based on a selected extent and the desired output cellsize.

For more complex modelling tasks I would suggest that you use the library directly. To give you a good start Etherington et al. also appended some example code and data in their article´s supporting information. Furthermore a few days ago they even had a spatial MEE blog post with some youtube video demonstrations how to use their library. So it shouldn’t be that hard even for python beginners. Or you could just use the processing interface within LecoS.

In any way, if you use the library in your research, I guess the authors would really appreciate it if you could cite them 🙂


In addition I also temporarily removed LecoS ability to calculate the mean patch distance metric due to some unknown errors in the calculation. I’m kinda stuck here and anyone who can spot the (maybe obvious) bug gets a virtual hug from me!


Happy new year!

ZonalStatistics, Neighbourhood analysis and more for LecoS

Since QGIS 2.0 stable was released just a while ago, i thought that it would be time to enhance my plugin LecoS a bit more.  Furthermore i also missed some functions, for instance i found no appropriate function to compute ZonalStatistics for a set of rasters of mine.  SAGA has a function to calculate some stats using a categorical and a zone raster layer. However it is lacking a raster output and specific stats. So i added  a new ZonalStatistics function to LecoS and i am sure that it will be of some use to Landscape ecologists and other GIS users out there. See a usecase below!

Furthermore i regularly use a lot of short python scripts to generate and query raster layers using a gdal+numpy backbone. Those custom functions of mine are a lot faster than any other plugin (all hail to numpy), which is why i also implemented some functions that are already available in QGIS through other plugins.

Here is the total changelog from the last LecoS version 1.8.2 to the new 1.9 (note that QGIS 1.8 won’t be supported anymore):

# Version 1.9
### Major Update: ###
- Added new tools to the Processing toolbox for use in complex models
    - Function to count Raster cells -> Output as table
    - Function to query raster values below a point layer
    - Function to intersect two landscape (raster) layers -> Output clipped raster
    - Function to creates a new random raster based on values from a statistical distribution -> Output raster
    - Function to conduct a Neighborhood analysis (analogous to r.neighbors. or Focal Statistics in ArcGis)
    - Function to conduct a connected component labeling of connected patches
    - Function to conduct ZonalStatistics based on two landscapes (ZonalStatistics with raster layers in ArcGIS)
- Improved the overall documentation for the Processing Toolbox and created new simple icons
- Fixed Bug: http://hub.qgis.org/issues/8810

I didn’t create any new graphical interfaces as i believe that sextante aka processing is the future. All new functions were therefore only added to the processing toolbox and not as seperate GUI. This also has the cool advantage that you could use all LecoS tools within more complex multi-algorithms models. The most visible difference to older LecoS versions is that i created a new icon for every function (make them distinguishable) and wrote documentary information.

All currently available processing functions

All currently available processing functions. Notice the new icons

The new function help

The new function help. Was a hell of work writing all this stuff

Click more to see a short tutorial demonstrating the functions using real data.

Read More…

LecoS and QGIS 2.0

And another short update:
Due to recent API-changes my QGIS plugin LecoS was not running anymore under current development versions of QGIS. To make the plugin ready for the upcoming release of QGIS 2.0, i separated the development between a stable version and a development version. The stable version (v. 1.7.5) runs only with QGIS 1.8 Lisboa, while the current development version (v. 1.8) is only supported by QGIS master and the upcoming QGIS 2.0 release.

Get them here or via the Plugin downloader.

In the future i will most likely only extend the development version as the QGIS 2.0 is to be expected soon this year.

Sextante support

Hey folks,

just a quick update as i am really busy with studying right now. I just added SEXTANTE support to LecoS and although it isn’t as powerful as the original LecoS Gui (only allows you to calculate a single metric at once) you can now address most of the functions (vector analysis excluded) from within the SEXTANTE toolbox.  Simply enable it in the options first to see it in the toolbox.

What is it good for?

Well, you can now batch-process the LecoS functions for multiple rasters and also include the landscape analysis tools in the SEXTANTE modeller. Below is a simple example of a model i just created. It takes a raster (Satellite landcover image) and a polygon (Training Data) as input and then automatically performs a maximum likelihood supervised classification. Afterwards it uses the landscape modifier function “Clean small pixels” to clean up the result and then calculates the total sum of all newly classified landscape pixels with the landscape analysis tool.


Sextante – Supervised classification model

I think this is it for now with new features for LecoS. Unless me or someone else needs a new fancy technique, i will make a feature freeze for now. Please report any bugs and blockers on the bugtracker. Maybe i can mark the whole plugin as stable as soon as QGIS 2.0 will be released.

Another LecoS update (and more to follow in the near future)


i just pushed another update to my Landcover analysis plugin LecoS. Besides fixing various bugs for Linux and Windows it now contains a remodeled BatchOverlay-Tool (the tool which allows you to compute statistics for overlaying vector grids on raster layers). It is now capable of calculating multiple metrics landscape wide and per class. The output can be displayed directly on the screen, saved in a temporary/given file or in the vector tables attribute table (Enabled in ver. 1.7.1)

Now capable of calculating landscape-wide metrics (zonal statistics + diversity indices) and class metrics

Now capable of calculating landscape-wide metrics (zonal statistics + diversity indices) and class metrics

I tested the Plugin under Linux (Debian Testing) and Windows (XP SP3). On both System the plugin should at least be able to start and calculate some metrics. However remember that this plugin is still marked as experimental and therefore bugs and strange python error messages might occur.

There is a known bug under Windows, when trying to add a generated table to the QGIS table of contents. If you try to this on Windows systems it will crash QGIS 1.8 and results in an Error message for QGIS dev.  –> Fixed in recent update 1.7.1

Changelog for current Version 1.7.2:

– Enabled the calculation of landscape statistics for vector layers
– Replaced QMessageBoxes with QMessageBar messages if a newer QGIS version (>= 10900) is used
– Removed the landscape diversity tool and merged options to calculate landscape diversity into the other toolset
– Bug fixing


  • The plugin needs the python libraries scipy, numpy and pil (imaging) to run. If you don’t install them (default is “no” on Windows), than you’ll likely see error messages after startup. To install the libraries on Linux systems, just download them with your package manager (python-scipy, python-imaging) or compile them system wide.  To install them on Windows download the OSGEO4W Installer , select advanced Install, search for the libraries python-numpy, python-scipy and python-imaging and check them all (besides checking the qgis binaries). If you do this correctly LecoS should run out of the box
  • If you stumble upon any errors PLEASE don’t report them in this blog as i really lose track of those comments. Use the official bug-tracker to report any bugs while using LecoS and try to give me as much information about your system and QGIS setup (including package versions and maybe a small data subset for testing).

The development of this plugin has been supported by the University of Évora and future version will include the options to analyse landscape vector layers, additional metrics and post-hoc result grouping.

Introducing the Landscape modifier to LecoS


i just pushed a new update to my QGis-plugin LecoS called the “Landscape Modifier“. At first it sounds strange by name, but i believe that it can be really useful even in cases that don’t involve any ecological expertise. In fact the desire to add these functions has been one of many reasons i even started coding this plugin. I am fascinated by the possibilities the scientific python library Scipy and also scikits offers in matters of image analysis. With just a few lines of code one could easily filter, denoise and improve images as demonstrated on this very good tutorial site. This can be useful in GIS-applications as well as raster layers are in fact very similar to image files. In essence both consist of multiple rows and columns containing data values. So moving from images to raster layers in GIS-systems isn’t so hard at all. But now about the plugin update.

I added the following functions:

  • Extract Landscape patch edges (Returns a raster with only the outer borders of raster patches)
  • Isolate greatest/smallest patch (Returns only the smallest or biggest patches of landscape class)
  • Increase or decrease landscape patches (Returns a raster with landscape patches inc./dec. x times)
  • Fill Holes inside landscape patches (Closes inner holes of landscape patches)
  • Cleans landscape of small border pixels (Removes all pixels smaller than x times a taxicab structure)



Here is a practical use-case. I performed a supervised landscape classification using training polygons to extract tree cover from a study location in western Africa. There are a lot of errors, small pixels and holes in the woodland and i will try to improve that a little. My previous landscape classification looks like this:

Extracted and classified tree cover

Extracted and classified tree cover

After executing “Fill holes“, a “small pixel cleanup” and an “increase” of all woodland pictures the result looks like the picture below. Of course the question if one should perform those operations should always be cleared first. Think about your classification critically and if it can be improved. In my case i only wanted the major trees and i am not interested in any artifacts or smaller shrubs.

Looks after cleanup.

Looks after cleanup. Ready to polygonize or process in LecoS to get the amount of tree cover.

Download the new update via the QGis plugin downloader or here. Please contact me only in case you found a bug and not about operating system specific questions (like how do i install scipy). I probably won’t answer to those question anymore!

The next mayor milestone for LecoS will probably be SEXTANTE toolbox support ! Furthermore i would really want to see a plugin using all the various available scipy.ndimage functions. I believe that it is just a matter of time before such a plugin shows up. Many of the various methods could really be useful in QGis, for example for DEM smoothing as demonstrated in this or this gis.stackexchange answers.

Sussex Research Hive

Supporting the research community at the University of Sussex

Small Pond Science

Research, teaching, and mentorship in the sciences

Landscape Ecology 2.0

intersecting landscape ecology, open science, and R


The Research Blog of IIASA

Jörg Steinkamps Blog

Mainly things about R, Linux and vegetation modeling

Amy Whitehead's Research

the ecological musings of a conservation biologist

Michael McCarthy's Research

School of BioSciences, The University of Melbourne

The Rostrum

science, statistics, policy and more


Environmental Change - Understand, Predict, Adapt

Dynamic Ecology

Multa novit vulpes


METeorological Visualisation Utilities using R for Science and Teaching

A Birder´s Blog

"Everybody loves what they know"


A new metric to quantify biodiversity response to fragmentation

Trust Me, I'm a Geographer

Using Technology to Explore Our World

Duncan Golicher's weblog

Research, scripts and life in Chiapas