TransWikia.com

Reading, displaying and modifying a raster using Java

Geographic Information Systems Asked by Justin OUATTARA on August 24, 2021

I am new to the Geotools library.

The idea is to display and be able to modify a raster in java with the said library. I referred to the code of MARK.

According to the description of the test class, it must be called from the main method by sending it an object of type File. For this, I created the said method as we can see it in the code.

My problem is that when compiling the program crashes at the first line of the test method.
Here are the main errors:

Exception in thread "main" java.lang.NoClassDefFoundError: javax / measure / UnconvertibleException  
Caused by: java.lang.ClassNotFoundException: javax.measure.UnconvertibleException

I have the impression that it is telling me that there is a class it cannot find but I do not know which one.

public class Test {
    
    public static void main(String[] args){
        try {
            test(new File("okok.TIF"));
        } catch (Exception ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void test(java.io.File file) throws Exception {

       //IT CRASHES HERE even if I swap its row blocks when there is no underlined error in the code
        
        // ************************************************
        ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY.createValue();
        policy.setValue(OverviewPolicy.IGNORE);

        //this will basically read 4 tiles worth of data at once from the disk...
        ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();

        //Setting read type: use JAI ImageRead (true) or ImageReaders read methods (false)
        ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
        useJaiRead.setValue(true);
        
         //*********************************************

        GridCoverage2DReader reader = new GeoTiffReader(file);
        GridEnvelope dimensions = reader.getOriginalGridRange();
        GridCoordinates maxDimensions = dimensions.getHigh();
        int w = maxDimensions.getCoordinateValue(0)+1;
        int h = maxDimensions.getCoordinateValue(1)+1;
        int numBands = reader.getGridCoverageCount();

        GridCoverage2D coverage = reader.read(
            new GeneralParameterValue[]{policy, gridsize, useJaiRead}
        );
        GridGeometry2D geometry = coverage.getGridGeometry();


        for (int i=0; i<w; i++) {
            for (int j=0; j<h; j++) {

                org.geotools.geometry.Envelope2D pixelEnvelop =
                geometry.gridToWorld(new GridEnvelope2D(i, j, 1, 1));

                double lat = pixelEnvelop.getCenterY();
                double lon = pixelEnvelop.getCenterX();

                double[] vals = new double[numBands];
                coverage.evaluate(new GridCoordinates2D(i, j), vals);

                //Do something!

            }
        }

    }
}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP