2

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:

<PAMDataset>
   <PAMRasterBand band="1">
    <GDALRasterAttributeTable>
     <FieldDefn index="0">
       <Name>Class_ID</Name>
       <Type>0</Type>
       <Usage>0</Usage>
     </FieldDefn>
  <FieldDefn index="1">
    <Name>Class_info</Name>
    <Type>2</Type>
    <Usage>0</Usage>
  </FieldDefn>
  <Row index="0">
    <F>1</F>
    <F>Water</F>
  </Row>
  <Row index="1">
    <F>2</F>
    <F>Vegetation</F>
  </Row>
  <Row index="2">
    <F>3</F>
    <F>Built-up</F>
  </Row>
  <Row index="3">
    <F>4</F>
    <F>Bare_soil</F>
  </Row>
    </GDALRasterAttributeTable>
  </PAMRasterBand>
</PAMDataset>

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)
{
   System.out.println(c);
}

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.