Land cover analysis for QGIS

As mentioned before i coded a new plugin for QGIS. Yesterday i decided to release a first version because i will start a new job on monday which will also include a lot of gis analysis and coding. I will further develop the plugin whenever i have time.

The Plugin is downloadable from the QGIS plugin hub. It is of course still marked as experimental, so please check for any bugs or missing things. You have to put the LecoS folder into your qgis plugin folder (~/.qgis/python/plugins/ on my machine)

You can find more information and a first use case about the plugin here:

LecoS – Land cover analytics

I also included another little gui which allows the user to calculate diversity indexes (used for a heterogeneity analysis of the landscape). I also wanted to include more metrics (especially total edge length), however the calculation of the patch perimeter has driven me crazy (perimeter is the basis of a lot of more advanced metrics) over the last days and i couldn’t get it to work. Interested coders wanting to help can write me a comment or an email.

best wishes

Curlew

Advertisements

Tags: , , ,

About Martin Jung

PhD researcher at the University of Sussex. Interested in nature conservation, ecology and biodiversity as well as statistics, GIS and 'big data'

36 responses to “Land cover analysis for QGIS”

  1. pvanb says :

    Great, I’ll test it out

  2. ecol_for says :

    I tried with qgis 1.7.2 following what suggested by you. The icon LecoS appears in the QGIS plugin manager as “incompatible” … have you any clues please? does it work on Wroclaw?

    • Curlew says :

      ahh, sorry. I coded the plugin based on the current stable QGIS version (1.8) and set this as standard as i believed that most people will use the newest software (i am using 1.9). Nevertheless if you have all necessary python libraries installed you should still be able to run lecos by going to your qgis plugin folder -> open lecos dir -> open __init__.py and metadata.txt with wordpad or something else and change the Minimum QGIS version parameter to 1.7. Afterwards restart qgis and the plugin should appear in the raster/plugins menu

  3. Mattia, Padua says :

    Sorry, I try to start the Lecos plugin but Qgis give me an error message: . What does it mean? I think I already have numpy and scipy libraries, so I don’t really know which problem I have.
    Thanks

    • Mattia, Padua says :

      the message is: Couldn’t load plugin LecoS due an error when calling its classFactory() method

      • Curlew says :

        strange. I just downloaded the current version via the plugin downloader and it runs without problems. Can you please make a screenshot of the error? The classFactory error usually comes if classes or depencies couldn’t be loaded. Maybe something else is missing.

        EDIT:
        Upload the image to a fileserver such as rapidshare, imageshack or similar. Just search the net for Imagehoster

      • Mattia, Padua says :

        How can I send You the image?
        To an e-mail address?

      • Mattia, Padua says :

        Here the link to the error immage. Thank you a lot

      • m.p says :

        I had the same problem. Try downloading scipy in this path: C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages (because when you install scipy it is installed by default in this path:C:\Python27\Lib\site-packages ). And make sure you download the correct version for Python 2.7.

  4. Curlew says :

    Look at the end of your error output. It reports an “ImportError” and the name of the library “scipy”. You need to install Scipy properly.

  5. dstath says :

    What is the best way to use a raster that also has NULL values when calculating diversity indexes (so that these pixels are excluded)? I am using an .img UInt16 where NULL is some very large negative value and get this message:

    ————

    An error has occured while executing Python code:

    Traceback (most recent call last):
    File “/home/demetris/.qgis//python/plugins/LecoS/lecos_dlg.py”, line 336, in go
    r = lcs.f_returnDiversity( array, classes, nodata, “shannon”)
    File “/home/demetris/.qgis//python/plugins/LecoS/landscape_statistics.py”, line 199, in f_returnDiversity
    cl_array[cl_array==int(no_data_value)] = 0
    TypeError: int() argument must be a string or a number, not ‘NoneType’

    Python version:
    2.7.3 (default, Aug 1 2012, 05:27:35)
    [GCC 4.6.3]

    ———-

  6. Curlew says :

    uhh, normally the no data value should be noted in the raster header. The plugins reads this value and assigns zeros to all no data values. Maybe you could reclassifiy your raster and change the null data value to something like -999 or 255 or similar. I will include a integer-converter in follow-up versions of the plugins.

  7. dstath says :

    did you use GeoTIFF for your tests?

    • Curlew says :

      yeah, i developed the plugin, because i needed a fast open source solution to calculate surfaces from classified land cover raster files such as Corine. Those files usually come as geoTIFFs and unfortunately i must say that i don’t have much experience with other formats.

  8. Mattia, Padua says :

    I have this problem calculating some index:
    -AttributeError: ‘module’ object has no attribute ‘count_nonzero’-
    How can I resolve? I try many ways to generate a grid file with “no data” values, but anything seems to work.
    Thank you

    • Curlew says :

      Uhh, this error should not exist 😦 . The count_nonzero function belongs to all numpy arrays. Therefore it fails to convert your array to a numpy array. It would help me a lot to understand your situation, if you send me a small sub-sample of your raster file. (ergo clip the raster to a very small bounding-box and upload it to a file-hoster). Maybe i can reproduce your error and try to fix it. Post the link here or send me an email (the address is in the plugins metadata file)

    • Curlew says :

      Hi Mattia,
      i received your files (in the future make a zip archive 😉 ) and tried them out. However both raster files work well on my machine (i am using qgis 1.9 trunk). However the A01_2012nz.tif file has no cell size value (or a very small one). See the screenshots here (http://imgur.com/vrYfs and http://imgur.com/0CcBQ )
      I will build in a textfield for nodata-value selection in case QGIS fails to recognize it. Expect an update in your plugin downloader soon.

    • jcguarneri says :

      I’m getting the same issue on my test dataset, a small patch of NLCD reclassed to 8 types, 30m pixels, NoData = -128. File is a GeoTIFF, and I’m using plugin v1.5.1 on QGIS 1.8, Windows 7 64 bit. I’ll be trying this out at home on my Linux machine as well. Thanks for developing this, though. It looks really quite promising!

      • jcguarneri says :

        Just saw you uploaded v1.6. Works great on Ubuntu 12.04 64-bit, QGIS 1.8. I’ll see if 1.6 works in Win7. Keep up the good work!

  9. Anonymous says :

    Hi Curlew,
    I have a problem calculating “Diversity Indicies” (Shannon, Simpson end Eveness). This is the error message:
    – Python Error
    An error has occured while executing Python code:
    Traceback (most recent call last):
    File “/usr/share/qgis/python/plugins/LecoS/lecos_dlg.py”, line 350, in go classes, array = lcs.f_landcover(rasterPath)
    File “/usr/share/qgis/python/plugins/LecoS/landscape_statistics.py”, line 87, in f_landcover
    classes.remove(nodata)
    ValueError: list.remove(x): x not in list

    Python version:
    2.7.3 (default, Aug 1 2012, 05:27:35)
    [GCC 4.6.3]

    QGIS version:
    1.8.0-Lisboa Lisboa, exported –

    • Curlew says :

      that’s strange. The error pops up because the script fails to recognize your no-data value (and remove it). It works for me (http://i.imgur.com/R7rm1.png) therefore i assume that you have some strange landcover classes. Maybe try to reclass your nodata-value to something like ‘0’ or ‘255’

      • Mattia, Padua says :

        I forgot to sign my message before, I’m Mattia, from Padua (Italy). I’ve got the same kind of problem with the “Land Cover Statistics”, remember? 🙂
        My raster files have no-data values = 0
        I will try with “255”.

        But I have another problem running Land Cover Statistics in my Windows-machine. With the ‘No data field’, I solved my problems in my Ubuntu environement (Thank you a lot).
        Unfortunatly the plugin doesn’t run in windows systems.
        This is the error message:

        – Error executing Phython code

        Traceback (most recent call last):
        File “C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_dlg.py”, line 103, in setNoData
        self.NoDataVal.setValidator(QDoubleValidator(-999999,999999,5))
        TypeError: arguments did not match any overloaded call:
        QDoubleValidator(QObject parent=None): argument 1 has unexpected type ‘int’
        QDoubleValidator(float, float, int, QObject): not enough arguments

        Versione Python:
        2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]

        Versione di QGIS:
        1.8.0-Lisboa Lisboa, 6416f38 –

        Can you tell me why?
        Thanks again for your help.

  10. Mattia, Padua says :

    and:

    Traceback (most recent call last):
    File “C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_dlg.py”, line 231, in accept
    nodata = float(self.NoDataVal.text())
    ValueError: could not convert string to float:

    • Curlew says :

      What did you provide as input for the NoDataTextedit field? The one in the topleft of the gui? Remember to use only numeric values and “.” as decimal seperators.

  11. Maurizio Marrese says :

    QGIS tells me he has found an error. missing “scipy”

    • Curlew says :

      than most likely you didn’t install it correctly. see comments above. I can give no support for that as it is operating system specific.

  12. Anonymous says :

    Hi Curlew

    thanks for taking the time to come up with this plug-in. I experience the same problem as Mattia in my windows environment. The nodata value is 0 in all settings, but I still receive the error message:

    Traceback (most recent call last):
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_dlg.py”, line 105, in setNoData
    self.NoDataVal.setValidator(QDoubleValidator(-999999,999999,5))
    TypeError: arguments did not match any overloaded call:
    QDoubleValidator(QObject parent=None): argument 1 has unexpected type ‘int’
    QDoubleValidator(float, float, int, QObject): not enough arguments

    Any suggestion for a solution would really be appreciated.

    cheers

    • Curlew says :

      Yeah, this is a bug coming from different versions of QT and extraordinary small no-data values. Will try to fix it as soon as i have time. You can work around this bug by reclassifying your no-data value to something more casual like “255” or another positive integer value.

  13. Anonymous says :

    Thanks for the quick answer. I have to confess that I am rather clueless about how to reclassify no-data. I use the Corine 2006 data and cropped an area, which I wanted to analyse with LecoS. Do I have to reclassify null values in the Corine data, before I crop an area? What is the easiest way to do this? Thanks for any help.

    • Curlew says :

      now, thats strange. Corine usually comes with a no-data value of zero and the plugin should recognize this correctly. You can set a new nodata-value for example with the QGis Raster clipper tool, but you should stick to zero. Try out the development version of QGis and report if this works. Otherwise i should go on looking for bugs. By the way you can report bugs here: http://hub.qgis.org/projects/lecos Try to include your system configuration and so on

      EDIT: I quickly implemented some quick error-catching routines. Try out, if they help

  14. Anonymous says :

    Sorry, but I was away for some days. I still receive an error message after selecting “Land cover statistics” from the Landscape Ecology menu:

    Traceback (most recent call last):
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_dlg.py”, line 105, in setNoData
    self.NoDataVal.setValidator(QDoubleValidator(-999999,999999,5))
    TypeError: arguments did not match any overloaded call:
    QDoubleValidator(QObject parent=None): argument 1 has unexpected type ‘int’
    QDoubleValidator(float, float, int, QObject): not enough arguments

    However, the menu opens and after selecting the correct grid and entering the no data value (0), the follwoing error pops-up:

    Traceback (most recent call last):
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_dlg.py”, line 240, in accept
    classes, array = lcs.f_landcover(rasterPath,nodata)
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\landscape_statistics.py”, line 87, in f_landcover
    classes.remove(nodata)
    ValueError: list.remove(x): x not in list

    Any idea what’s wrong? Thanks

    • Curlew says :

      Things to try out:
      – Reclassify your rasters no-data value.
      – Try out the development version of QGIS
      – If everything above fails, send me a small clipped subset of the raster and i can try it out myself.
      You can find tutorials and explanations for the things above at gis.stackexchange or google

  15. Anonymous says :

    The plug-in does not load on the start of QGIS anymore

    Traceback (most recent call last):
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py”, line 164, in startPlugin
    plugins[packageName] = package.classFactory(iface)
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\__init__.py”, line 35, in classFactory
    from lecos_main import LecoS
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py”, line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_main.py”, line 29, in
    from lecos_dlg import LecosDialog
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py”, line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\lecos_dlg.py”, line 36, in
    import landscape_statistics as lcs
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py”, line 309, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
    File “C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python/plugins\LecoS\landscape_statistics.py”, line 33, in
    gdal.AllRegister() # register all gdal drivers
    AttributeError: ‘module’ object has no attribute ‘AllRegister’

    I am absolutley clueless?

    • Curlew says :

      phhhh, really people. The plugin works without any(!) issues for me. See if you have a different setup on your computer (see mine here: http://i.imgur.com/ddoxYvd.png ). I don’t use/like/have access to any Windows Systems and therefore i can’t test the plugin for all situations. I’ll build in some quick try-catch exceptions for those gdal errors, but there is a chance that new problems will come up. I would prefer that new problems are posted on the bug-tracker ( http://hub.qgis.org/projects/lecos ) instead rather than in the form of blog comments.

      EDIT:
      You can download a update (1.5.1) with some implemented try-catch routines. If they also don’t help than please have a look at the code yourself. Furthermore please post further issues in the bug-tracker mentioned above.

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

nexus

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

marionpfeifer

Environmental Change - Understand, Predict, Adapt

Dynamic Ecology

Multa novit vulpes

metvurst

METeorological Visualisation Utilities using R for Science and Teaching

A Birder´s Blog

"Everybody loves what they know"

BIOFRAG

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

%d bloggers like this: