Pages

Showing posts with label GIS. Show all posts
Showing posts with label GIS. Show all posts

Wednesday, 8 October 2014

eCognition tutorial: Exporting eCognition features as images with array functionalities

There are instances when one would like to export different features from eCognition as a images to perform some tasks outside eCognition. eCognition doesn't provide a way to export many object features as images but it is only possible to export as a thematic raster in which each object has a unique ID, and features values are stored in a separated CSV file. To convert it into images, one has to mapped ID raster tiff file and data from CSV file.

If you want to get eCogntion features as images in an automatic way that can export any numbers of features as images in one go, then here is a way. For the purpose, we are going to utilize array handing capabilities of eCogntion and export each feature as separate tiff (My_1.tiff, My_2.tiff …. and so on) file. The rule set can be downloaded here. The rule set is flexible in the sense that you just have to update an array to store your feature list of interest. Number features can be any number (10, 20 or even 100 features). We will merge it afterwards in open source QGIS.

  • Perform a segmentation
  • Create a array and store features you want to export as images
  • Loop over the array
    1. For each feature, create a temporary image file
    2. Export the temporary file as a unique name
    3. Repeat until all features in the array are executed
  • Now in QGIS, we use GDAL to stack individual images into one single image. We will use merge function of GDAL (Raster>Miscellaneous> Merge).
    Complete ruleset within eCognition
Ruleset  for exporting features as images 
GDALmerge function within QGIS
Color composite of three merge features
Thus produced merge features image now can be used for classification  in ENVI, ERDAS IMAGINE or writing custom script in Python or MATAB. Personally I use such images within Python using scikit-learn library.

Friday, 30 August 2013

Neighborhood analysis in QGIS.


QGIS is an open source software which anyone can download for free. The community is growing each day and it is completely capable of doing common basic GIS tasks as well as more advance stuff. In this tutorial, I will show you how to do some neighbourhood analysis in QGIS with the help of sextante graphical modeler. If you guys are more ArcGIS person then you might be familiar with ArcGIS modeler. QGIS provides similar graphical interface as ArcGIS through which all the available algorithms in QGIS are accessible. On top of that you can combine algorithms from different other providers such as GDAL, Grass, OrfeoToolbox, R and SagaGIS. So it can be really powerful tool to automate your daily GIS task. Go check it out. Scour help file of QGIS, you will find plenty of readings.

Different programs that are available with QGIS

So the task is: There is a polygon shape file of my country Nepal which is shown in green. Each polygon represents a district. There is a point shp file which represent point of interest (assume it to be major infrastructures such as big hospitals or airports or universities etc). Each point of interest is represented by unique ID. Now the task is to assign each district to closest point of interest based on how far the district is from point of interest
Input shpfiles: 
The graphical model in QGIS.


The model is basically doing following main task.
  • ·         Convert shp file districts to its centroid
  • ·         Calculate nearest point of interest from each district centroid.

After creating the model one could just hit the run button and you are good to go. The model can be saved and used it for later purpose. As you can see in the modeller, the first algorithm is coming from SAGA GIS whereas second algorithms is coming from core QGIS. This is also a good illustration to show how algorithms can be combined from different source.

After running the model, you will get a point file. Let’s examine its attribute table. As you can see, each district is associated with @HubName which in our case is point of interest. It also has distance information. I forgot to converts projection EPSG: 4632 to a projected one so the distance is in terms of latitude and longitude. If you want distance in m or km then use a projected EPSG and you will be fine.



Now we will join this information to the original district shp file based on the column @Name. To do that do the following:

Right click the polygon shp file and click properties. Click join tab and following figure pops up. Click green + button to define a join as shown in next figure. The join column is @Name which is common is both polygon shp files as well point shp files that we calculated from our graphical modeler

Join attribute interface
.
Defining join layer and columns

After the join, the attribute of districts polygon has additional information. Now it’s the matter of applying colour symbology to differentiate which districts are closer to which one of the point of interest based on fourth column.

Attribute table after join

The final result is :

I have not shown each and every step in this tutorial. My main purpose is to show how you can use powerful QGIS and sextante modeler to perform complex GIS task such as neighborhood analysis without using ArcGIS which costs a lot and stimulate you to try QGIS. If any questions, just ask and I will reply. Of course, if I am not busy with my shits J