1

Background: Used this tutorial as base

System: Eclipse IDE in Windows 10 VM

So I have some RPF data that I'd like to display within a JFrame. Right now I'm trying to figure out a way of just displaying a single file (.i42) within a layer and then my next object is to display a image mosaic populated by multiple files of the same type.

It looks like I'll need to use RPFTOCFormat class to get a Reader to build the layer. Using Maven to import the library, my pom.xml (relevant section only) is the following:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <geotools.version>19-SNAPSHOT</geotools.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-imageio-ext-gdal</artifactId>
        <version>${geotools.version}</version>
    </dependency>
</dependencies>

Within my code (very similar to the tutorial referenced above) I try and use this Reader to build a GridReaderLayer to populate my map with.

private void getLayersAndDisplay() throws Exception {
    List<Parameter<?>> list = new ArrayList<>();
    list.add(new Parameter<>("image", File.class, "Image", //element id and label before file path box
            "GeoTiff or World+Image to display as basemap", //description below file path box
            new KVP(Parameter.EXT, "tif", Parameter.EXT, "jpg"))); //expected file extensions
    //list.add(new Parameter<>("shape", File.class, "Shapefile", "Shapefile contents to display",
    //      new KVP(Parameter.EXT, "shp")));



    JParameterListWizard wizard = new JParameterListWizard("Image Lab", 
            "Fill in the following layers", list);

    int finish = wizard.showModalDialog();

    if(finish != JWizard.FINISH) {
        System.exit(0);
    }

    File imageFile = (File) wizard.getConnectionParameters().get("image");  //get path from associated element id
    //File shapeFile = (File) wizard.getConnectionParameters().get("shape");
    //displayLayers(imageFile, shapeFile); //display those layers from file objs
    displayLayers(imageFile);
}

private void displayLayers(File rasterFile) throws Exception {
    AbstractGridFormat format = new RPFTOCFormat();

    reader = format.getReader(rasterFile);

    final MapContent map = new MapContent();
    map.setTitle("Jonathan's attempt");

    Style rasterStyle = createRGBStyle();
    Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);

    map.addLayer(rasterLayer);


    frame = new JMapFrame(map);
    frame.setSize(800, 600);
    frame.enableStatusBar(true);
    frame.enableToolBar(true);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    JMenu menu = new JMenu("Raster");
    menuBar.add(menu);

    frame.setVisible(true);
}

However when I run the class, I get the following error:

it.geosolutions.imageio.gdalframework.GDALUtilities loadGDAL
WARNING: Failed to load the GDAL native libs. This is not a problem unless you need to use the GDAL plugins: they won't be enabled.
java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path

I thought I imported the lib via that dependency specified within the maven pom but apparently I'm mistaken.

0

Looking at this page implies that you need to install the native libraries as well as the Java module that maven handles. It also states:

Warning: If you are on Windows, make sure that the GDAL DLL files are on your PATH. If you are on Linux, be sure to set the LD_LIBRARY_PATH environment variable to refer to the folder where the SOs are extracted.

So you may need to adjust the Windows path to make sure you include the dlls.

Finally, I don't see RPF listed on the supported formats list so you may need to add some code to support that format.

Feel free to add some links and/or text to the GeoTools page that should probably include this information.

4
  • So I downloaded a precompiled gdal/mapserver pkg from here: gisinternals.com/release.php (MSVC 2013-win32) – Jonathan Dec 27 '17 at 15:19
  • I then updated my path to point to the extracted gdal.jar and dll's (within map\gdal of extracted folder) and got the following error: WARNING: Failed to load the GDAL native libs. This is not a problem unless you need to use the GDAL plugins: they won't be enabled. java.lang.UnsatisfiedLinkError: C:\gdal-2-2-1-mapserver-7-0-6\bin\gdal\java\gdaljni.dll: Can't find dependent libraries Exception in thread "main" java.lang.IllegalStateException: GDAL native libraries are not available. – Jonathan Dec 27 '17 at 15:25
  • As for support of the format: gdal.org/frmt_various.html#RPFTOC and docs.geotools.org/stable/javadocs/org/geotools/coverageio/gdal/… were the reason I think the format should be able to be read and displayed – Jonathan Dec 27 '17 at 15:28
  • forgot to mention that I included the apps and plugin directories within the aforementioned package in my PATH as well – Jonathan Dec 27 '17 at 16:09
0

Following these instructions (sans python portion) and after removing gdal_ECW_JP2ECW.dll and gdal_MrSID.dll from GDAL_JAVA_PATH dir, things began to work. I removed these dlls because despite their presence (per this), I was getting the following error when running gdalinfo --version

gdal_ECW_JP2ECW.dll 126: The specified module could not be found.

After removing the files from the dir, I was able to run gdalinfo --version without issue. Not sure what caused that error to begin with--may need those plugins installed.

Once I updated my Environment Variables and PATH I was able to run my eclipse project to run my class. I got an exception however saying that the provided input was not supported by the reader. This page says that RPF data is natively supported by GDAL. I will probably post in another question as it's a separate issue from this question.

It also bears mentioning that I was incorrectly selecting the .i42 file to load into the reader, when I should have been selecting the A.TOC file.

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.