1

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>
1
  • Can you add the dependencies from your pom.xml file to your question please
    – Ian Turton
    Mar 18, 2021 at 16:22

2 Answers 2

0

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.

2
  • Thanks for the suggestion but it didn't solve my issue. The issue is due to apacheSIS and geotoolkt already present in the dependendy tree sharing older version of some dependencies with geotools.
    – charlycou
    Mar 19, 2021 at 14:35
  • I don't think there is any way to make the two toolkits work together
    – Ian Turton
    Mar 19, 2021 at 17:03
0

I had a similar issue with gt-geotiff version 26.0 having conflicting dependencies with another package. In my case I could resolve it by explicitly loading a newer version of unit-api in the dependencies:

<dependency>
    <groupId>javax.measure</groupId>
    <artifactId>unit-api</artifactId>
    <version>2.0</version>
    <type>jar</type>
</dependency>

You can also exclude the older dependency by adding

<exclusions>
    <exclusion>
        <groupId>javax.measure</groupId>
        <artifactId>unit-api</artifactId>
    </exclusion>
</exclusions>

to the <dependency> section of its package, just to be sure.

However, the cleaner way to solve such problems is to have both packages depend on the same GeoTools version.

Your Answer

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

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