3

I have a geotiff file and I use geotools library for parsing it.

This is my code:

File f = new File("myFile.tif");

ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY.createValue();
policy.setValue(OverviewPolicy.IGNORE);

ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
useJaiRead.setValue(true);

GridCoverage2D image = new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});

Rectangle2D bounds2D = image.getEnvelope2D().getBounds2D();     
GridGeometry2D geometry = image.getGridGeometry();

System.out.println(geometry);

System.out.println(bounds2D);

The output of geometry is:

GridGeometry2D[
    GeneralGridEnvelope[0..1199, 0..1399], 
    PARAM_MT[
        "Affine", 
        PARAMETER["num_row", 3], 
        PARAMETER["num_col", 3], 
        PARAMETER["elt_0_0", 996.4799194335938], 
        PARAMETER["elt_0_2", -598386.1975402832], 
        PARAMETER["elt_1_1", -999.6777954101562], 
        PARAMETER["elt_1_2", 650290.4111022949]
    ]
]

The output of bounds2D is:

java.awt.geom.Rectangle2D$Double[x=-598884.4375, y=-748758.6635742188, w=1195775.9033203125, h=1399548.9135742188]

What does this information mean?

1 Answer 1

3

It means your image is 1200 pixels wide and 1400 pixels high.

(precision truncated for readability) The pixel size is not square, it is 996.47 (meters?) by -999.67. The negative value indicates the axis direction.

The top left corner of the image is -598386.19 ; 650290.41 (meters?)

The same information is written in the bounds information, in a slightly transformed way:

The center of the image bottom left corner is at x=-598884.43, y=-748758.66

//Add 1/2 pixel size, we get the same coordinate as before
-598884.43 +  996.47 / 2 = -598386.19

For the Y, since it is the bottom coordinate, we can validate by doing

// Add 1/2 pixel size + number of pixels * pixel size, we get the same coordinate as before
// Need to handle the negative pixel size adequatly
 -748758.663574219 + (1400 * 999.677795410156) - (999.677795410156 / 2) =  650290.41

At last, you get the image width and height, in meters

1200 pixels * 996.4799194335938 = 1195775.9
1400 pixels * 999.677795410156 = 1399548.9
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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