4

I am trying to classify a shapefile based on rule set, following this tutorial.

This is the result: enter image description here

What I want to ask is: 1. How to insert the classification result (water, land etc) into the attribute table? I want to make each feature assign to a certain class in the attribute table. enter image description here

  1. How to join the vector contain same class? I tried vector-geoprocessing-dissolve, it is not working. I tried to select the polygons using same rule, then using "merge selected feature". However, the attributes value only following the first feature, meanwhile, I need the mean of each feature. Is there any way to merge the same category, and calculate the mean attributes value?
  • 2
    How do you want to assign each feature to a certain class? Do you want to take certain values from another field to equal a class? E.g. if "nbPixels" < 100 then class = water? This could be done with the Field Calculator. – Joseph Mar 22 '16 at 12:47
3
  1. you have to do it by edit your attribut table first (Field Calculator) to put value on your class column, use conditional statement CASE based on the "rule" that you used in classification. you can take a look on this to use CASE.

  2. After your Class Column is filled. Then you can run Split vector layer from processing toolbox. Input the vector layer , then input Class as Unique ID field.

Addition : To join features into one feature per Class, Dissolving based on your "class" Field also will do this logically.

  • Thank you. I run this rule CASE function and it works perfectly. However, I still cannot figure out how to calculate mean attributes value after I dissolve them. Do you know how? Sorry for so much trouble – monruw Mar 23 '16 at 19:02
  • 1
    Use experimental plugins called Dissolve with stats, make sure to check mark experimental plugins (on plugins setting) before you search this plugin name. Unfortunately this plugins does not work for me (Using Pisa 10.1). But you can give it a try. The plugins will be placed on vector menu bar after it is installed – Uje Indo Mar 24 '16 at 23:34
  • I cannot find Dissolve with stats in repository. Anyway I using saga, and it fast. but all other information (meanB0, meanB1 etc.) is gone, only the class name still there. Is there anyway to calculate the new polygon stat value based on the original image? – monruw Mar 25 '16 at 9:56
  • Found it. I tried dissolve with stat, but it sends me an error message "'QgsRasterLayer' object has no attribute 'fields' See log for more details". – monruw Mar 25 '16 at 10:16
3
  1. Based on Uje Indo suggestion, I used field calculator to edit existing field "class" with this statement. It works perfectly.

CASE

WHEN "meanB0" < 12.5 AND "meanB3" < 85 THEN 'water'

WHEN "meanB0" > 12.5 AND "meanB0" <18 THEN 'nypa'

WHEN "meanB0" >= 17 AND "meanB7" > 170 THEN 'deadtree'

WHEN "meanB0" >=17 AND "meanB7" < 100 THEN 'rhizopora'

WHEN "meanB0" >=17 AND "meanB7" >= 100 AND "meanB7" <= 180 THEN 'bruguiera'

WHEN "meanB0" <=12.5 AND "meanB3" >= 85 THEN 'land'

END

  1. Based on Jochen Schwarze plus trial and error, I finally used saga dissolve polygon by attributes, it creates a shapefile with the class name only, and all other band information is gone. Afterward, to calculate mean,max,min etc for each class polygon, i have to:
    • split the raster image into each band using raster calculator
    • run saga grid statistic for polygon where for grids, choose all the raster band that split before, and for the shapefile choose the dissolve polygon. Run it, and the result will give a shp file with cell number, sum, range, min, max, mean, var, standard deviation for each band and each polygon.
2

I had a similar issue with the tools available in the menus. After creating the additional attribute, you should check out the processing plugin, and then the related tools in the processing toolbox (search for dissolve), esp. try grass and saga!

enter image description here

  • Thank you. I am trying using QGIS vector dissolve now, but it is running very slow (already 20 hours and only reach 68% now). even though my RAM is 8GB, qgis only use around 500MB. I will try your suggestion using grass, saga and GDAL next time. Hopefully, there will be an option where I can increase the memory use and make it faster. – monruw Mar 24 '16 at 15:42
  • 1
    reached 100%? How many polygons do you have to dissolve though?! Does it matter, if you use qgis 32 or 64bit? However, my finding is that various tools often significantly differ in processing time. And do you have access to comercial tools (ESRI, FME)? Esp. FME is fast and reliable, but quite expensive... – Jochen Schwarze Mar 25 '16 at 8:45
  • around 70000 polygons in total. well after reaching point 78% the QGIS crashed, so no result so far. I'm using QGIS LYON 64bit. I rerun it using saga dissolve. Unfortunately, I don't have access for commercial tools :( Are they faster? – monruw Mar 25 '16 at 9:26
  • just checked this out with fme, i put some screenshots in another answer. – Jochen Schwarze Mar 25 '16 at 10:10
1

Using FME i did the following

  • downloaded administrative boundaries of the whole world from http://www.gadm.org/version2
  • take only boudaries of level 5 for further example processing (it'S only spain?!), 51432 polygons
  • created new attribute randomly populated with values 1 to 7, giving me a pattern different from yours, but this should not matter.
  • dissolved this based on the random class.
  • processing time 1 min, 12 sec as can be seen in screenshots below.

I don't really know what the guys secret is, but if you have hundreds of such processes, buying a commercial product can be a considerable way... (or a trial license, perhaps? https://www.safe.com/fme/fme-desktop/trial-download/ , i could send you the workspace...)

FME process:

enter image description here

Vis. in QGIS, total sample data set

enter image description here

close up...

enter image description here

... and the dissolved result.

enter image description here

  • Thank you. Is the dissolved polygon also contain statistic of other attributes? (mean, sum of each band etc)? Because using saga, the polygons is dissolve within seconds, but all the other accompanying attributes is gone – monruw Mar 25 '16 at 10:39
  • 1
    Yes, in FME this is possible, because input Attributes are kept as list attributes by the dissolver. On these you can use the so called StatistcsCalculator transformer. I suggest having a look a the FME transformer reference guide: cdn.safe.com/resources/fme/FME-Transformer-Reference-Guide.pdf – Jochen Schwarze Mar 25 '16 at 10:54
  • I made it using saga "grid statistic for polygon", it gives number of cell,min,max,sum,range,mean,varian and standard deviation for each class polygon and each band. So i think it is fine for now :) thank you for your help – monruw Mar 25 '16 at 12:29
  • Checked out GRASS v.dissolve for my example, 4:50, not as painful as i expected ;-) – Jochen Schwarze Mar 25 '16 at 14:17
  • somehow grass cannot be opened in my qgis.. i think i have to re-install.:) – monruw Mar 30 '16 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.