TransWikia.com

How to load GeoTIFF using Geotools?

Geographic Information Systems Asked by charlycou on July 14, 2021

I’m having trouble to load a GeoTIFF file using Geotools (never used it before).
What I’ve tried so far:

File koppenClassificationTif = new File("mongodb-repository/src/main/resources/land_shallow_topo_2048.tif");    
GeoTiffFormat format = new GeoTiffFormat();
Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
GeoTiffReader reader = format.getReader(koppenClassificationTif, hints);

The GeoTiffFormat could not be initialized because of java.lang.NoSuchMethodError: 'javax.measure.Unit javax.measure.Unit.multiply(java.lang.Number)'. My .m2 repository contain 2 versions javax/measure/unit-api but I don’t see why this would be a problem.

I’ve also tried to directly use GeoTiffReader reader = new GeoTiffReader(koppenClassificationTif); which throw this exception:

org.geotools.data.DataSourceException: class
org.apache.sis.referencing.factory.GeodeticObjectFactory cannot be
cast to class org.opengis.referencing.Factory
(org.apache.sis.referencing.factory.GeodeticObjectFactory and
org.opengis.referencing.Factory are in unnamed module of loader ‘app’)

I’m using newly released 25.0 but I’ve been experiencing the same issue using 24.2

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geojsondatastore</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-referencing</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-coverage</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-opengis</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geotiff</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-main</artifactId>
        <version>${geotools.version}</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>osgeo-alt</id>
        <url>https://repo.osgeo.org/repository/release</url>
    </repository>
</repositories>

<properties>
    <geotools.version>25.0</geotools.version>
</properties>

One Answer

You don't seem to be providing an implementation of the referencing module, see the GeoTools FAQ for more details, but adding gt-epsg-hsql should solve your issue.

Answered by Ian Turton on July 14, 2021

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