1

I'm classifying vegetation in eCognition. From ArcMap I already have a shapefile with training polygons that I would like to use for this but so far I was only able to insert this as a thematic layer and use for the segmentation process. Also, is eCognition able to handle the attribute table information where the classes for the polygons are stored or will I have to split the shapefile with all the information into individual shapefiles?

2

If you want to use training polygons as samples in eCognition you need to add them as a TTA mask (Training and Test Area), also this can be used in Accuracy Assessment process.

A TTA mask is a raster layer with training classes as integers. You also need to create a .csv file with Class name, ID, Red, Green and Blue (0-255 value for coloring each training class).

I've been using an R code for this purpose, it could help you:

require(rgdal)
require(raster)

# Load training shapefile
shp <- readOGR(dsn="/path/to/folder", layer = "layer_name")

r <- setValues(raster("/path/to/sample/layer/used/in/eCognition"), values = NA)

Class_Names <- unique(shp@data$Class_name_field)
id <- as.numeric(unique(shp@data$Integer_ID_field))
Red <- round(sample(0:255,length(Class_Names),replace = T))
Green <- round(sample(0:255,length(Class_Names),replace = T))
Blue <- round(sample(0:255,length(Class_Names),replace = T))

TTAconversor <- data.frame(id,Red,Green,Blue,Class_Names)

write.table(TTAconversor,file = "/path/to/TTAMask.csv",quote = F,row.names=F,sep = ";") # sep = ',' if this csv doesn't work

TTAr <- rasterize(shp,r,field=as.numeric(shp@data$Integer_ID_field),background=255)

writeRaster(TTAr,filename ="/path/to/TTAmask",format = "GTiff", overwrite= T, datatype="INT1U") #same name than .csv file

Finally, add TTA mask by selecting Classification / Samples / Load TTA Mask and a dialog box will appear asking if you want to use this mask as training samples.

  • "I also need to do supervised classification. I will try to follow your method" – Shiuli Pervin May 3 '18 at 9:02

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.