I have sample.tif, sample.tif.aux.xml, sample.qml files in a directory. The .qml and .xml files contain classification data about .tif file. For example my .xml file is something like this:

   <PAMRasterBand band="1">
     <FieldDefn index="0">
  <FieldDefn index="1">
  <Row index="0">
  <Row index="1">
  <Row index="2">
  <Row index="3">

I want to read these files as a whole. I tried this way:

File file = new File("sample.tif");
AbstractGridFormat format = GridFormatFinder.findFormat(file);
GridCoverage2DReader reader = format.getReader(file);
GridCoverage2D coverage = reader.read(null);
List<Category> categories = coverage.getSampleDimension(0).getCategories();
for(Category c : categories)

According to the javadoc for category (http://docs.geotools.org/latest/javadocs/org/geotools/coverage/Category.html), I expect to have 4 categories for this file: (Water, Vegetation, Build-up, Bare_soil) but I found only one category with name "No data".

How can I read these files to correctly initialize categories collection?

  • The qml file is a Qgis style file so will be ignored by geotools – Ian Turton Aug 21 '17 at 18:20

Your Answer

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

Browse other questions tagged or ask your own question.