Zorobay
Zorobay

Reputation: 649

Geotools OGR plugin - UnsatisfiedLinkError (ogrjni or gdalalljni)

I'm working with Geotools but I am unable to correctly setup gdal for the OGR plugin. According to the vague documentation for the OGR Plugin, I need to use GDAL 3.2 or older.

I am using binaries from Gisinternals and when using version 2.2.3, I get a an UnsatisfiedLinkError for 'gdalalljni'. And it is missing from version 2.2.3. However, when I instead use version 3.1.4, I get an UnsatisfiedLinkError for 'ogrjni', which correctly is missing from that version. It seems like version 2.2.3 is missing the 'gdalalljni.dll', which in later versions was added but then removed the 'ogrjni.dll' instead.

Here's an example of a stacktrace from using 3.1.4:

Native library load failed.
java.lang.UnsatisfiedLinkError: no ogrjni in java.library.path: [C:\Program Files\Java\jdk-11\bin, C:\WINDOWS\Sun\Java\bin, C:\WINDOWS\system32, C:\WINDOWS, C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin, C:\Program Files (x86)\Common Files\Oracle\Java\javapath, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\WindowsPowerShell\v1.0\, C:\WINDOWS\System32\OpenSSH\, C:\Program Files\dotnet\, C:\Program Files\nodejs\, C:\Program Files\Microsoft SQL Server\150\Tools\Binn\, C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\, C:\Program Files\PowerShell\7\, C:\Program Files\PuTTY\, C:\Program Files\RedHat\Podman\, C:\gdal-314\bin\gdal\java, C:\gdal-314\bin, C:\gdal-314\bin\gdal\apps, C:\aliases, C:\Users\sehe\AppData\Local\Programs\Git\cmd, C:\Users\sehe\AppData\Local\Programs\oh-my-posh\bin, C:\Users\sehe\AppData\Roaming\pypoetry\venv\Scripts, C:\Users\sehe\AppData\Local\Programs\Microsoft VS Code\bin, C:\Users\sehe\AppData\Roaming\npm, C:\Program Files\Azure Data Studio\bin, C:\Users\sehe\AppData\Local\Microsoft\WindowsApps, C:\Users\sehe\AppData\Local\Programs\EmEditor, C:\Users\sehe\AppData\Local\Pandoc\, C:\Users\sehe\AppData\Local\Programs\Gpg4win\..\GnuPG\bin, C:\Users\sehe\AppData\Roaming\Programs\Zero Install, C:\Users\sehe\.dotnet\tools, C:\grails-4.1.4\bin, ., .]
Caught: java.lang.UnsatisfiedLinkError: org.gdal.ogr.ogrJNI.GetDriverCount()I
java.lang.UnsatisfiedLinkError: org.gdal.ogr.ogrJNI.GetDriverCount()I
    at org.gdal.ogr.ogrJNI.GetDriverCount(Native Method)
    at org.gdal.ogr.ogr.GetDriverCount(ogr.java:114)
    at org.geotools.data.ogr.jni.JniOGR.<clinit>(JniOGR.java:88)
    at org.geotools.data.ogr.jni.JniOGRDataStoreFactory.createOGR(JniOGRDataStoreFactory.java:32)
    at org.geotools.data.ogr.OGRDataStoreFactory.getAvailableDrivers(OGRDataStoreFactory.java:285)
    at GeotoolsTest.run(GeotoolsTest.groovy:12)

This is the sample code that is failing (Groovy):

import org.geotools.data.ogr.OGRDataStoreFactory
import org.geotools.data.ogr.jni.JniOGRDataStoreFactory

OGRDataStoreFactory factory = new JniOGRDataStoreFactory()
for (String driver : factory.getAvailableDrivers()) {
    System.out.println(driver);
}

And here is my buildfile:

plugins {
    id 'groovy'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven { url "https://repo.osgeo.org/repository/geotools-releases/" }
    maven { url "https://packages.atlassian.com/maven-3rdparty/" }
}

dependencies {
    implementation 'org.apache.groovy:groovy-all:4.0.14'

    implementation group: 'org.geotools', name: 'gt-main', version: '32.1'
    implementation group: 'org.geotools', name: 'gt-ogr-core', version: '32.1'
    implementation group: 'org.geotools', name: 'gt-ogr-jni', version: '32.1'
}

test {
    useJUnitPlatform()
}

configurations.all {

    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'javax.media') {
            if (details.requested.name == 'jai_core') {
                details.useTarget group: 'javax.media', name: 'jai-core', version: details.requested.version
            }
        }
    }
}

I have googled this error for hours, and all sources keep telling me to check my PATH, which I am quite sure is setup correctly. And either way, the problem is the missing DLLs from the binaries. But just to be sure, here are my environment variables:

GDAL_SDK_ROOT = C:\gdal-314 GDAL_DATA = %GDAL_SDK_ROOT%\bin\gdal-data

PATH = %GDAL_SDK_ROOT%\bin\gdal\java;%GDAL_SDK_ROOT%\bin;%GDAL_SDK_ROOT%\bin\gdal\apps

Thankful for any help!

Upvotes: 0

Views: 22

Answers (0)

Related Questions