1

GeoToolsを利用して GeoTiff 画像を読み取るOSMOSIS拡張機能を作成しようとしています。

私はそれが何をするかの最小限の実例を書きました:

package that.is.my.test;

import java.io.File;
import java.io.IOException;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
import org.opengis.coverage.grid.GridEnvelope;

public class ExampleClass {
    public static void main(String[] args) {
        new ExampleClass();
    }

    public ExampleClass() {
        try {
            File file = new File("<GEOTIFFFILE>");
            GeoTiffReader reader = new GeoTiffReader(file);
            GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
            GridEnvelope gridBounds = coverage.getGridGeometry().getGridRange();
            System.out.println("grid bounds: " + gridBounds);

            Envelope2D worldBounds = coverage.getEnvelope2D();
            System.out.println("world bounds: " + worldBounds);

            int numBands = coverage.getNumSampleDimensions();
            System.out.println("num bands: " + numBands);

            System.out.println("Goodbye.");
        } catch (IllegalArgumentException | IOException e) {
            e.printStackTrace();
        }
    }
}

注: これは最小限のサンプル クラスですが、OSMOSIS プラグインのコードはまだ何も実行していません。

このサンプル クラスを NetBeans から実行できますが、問題なく動作します。実行可能な jar にパッケージ化できますが、これも正常に機能します。

OSMOSIS プラグインは、jar にコンパイルされてから OSMOSIS 自体によって呼び出されるため、NetBeans から実行することはできません。しかし、それを行うと、で始まる行にメッセージが表示されGridCoverage2Dます。IllegalArgumentExceptionImageRead: No OperationDescriptor is registered in the current operation registry under this name.

両方のクラスに完全な JAI レジストリ リストを出力させると、OSMOSIS のケースではImageReadImageWriteと他のいくつかが単純に欠落していることがわかります。

どうしてこれが起こるのか理解できません!jar を調べると、ファイルMETA-INF\services\javax.imageio.spi.ImageReaderSpiは両方に存在し、内容はまったく同じです。

これはプラグインからの私の POM.xml です。Example クラスには同じ依存関係と repos および build ディレクティブがあります。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>hello.OSMOSIS</groupId>
    <artifactId>my-osmosis-plugin</artifactId>
    <version>1.0-SNAPSHOT${jarWarning}</version>
    <packaging>jar</packaging>
    <name>OSMOSIS TEST plugin</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <osmosisScope>provided</osmosisScope> <!-- configure this by using the profiles, this is fallback only. -->
        <geotools.version>12-RC1</geotools.version>
    </properties>
    <!-- We define two different profiles: 
        debugWithNetbeans includes all the OSMOSIS jars into the plugin, 
            so that we can test-run the plugin with Netbeans (or anything else). 
            Note: This does not work yet...
        pluginProductions doesn't include the OSMOSIS sources, because later on 
            the plugin will be called BY osmosis and will not need the jars anymore. 
    DO NOT FORGET to set this correctly :-) -->
    <profiles>
        <profile>
            <id>debugWithNetbeans</id>
            <properties>
                <osmosisScope>compile</osmosisScope>
                <jarWarning>-DEBUG-BUILD</jarWarning>
            </properties>
        </profile>
        <profile>
            <id>pluginProduction</id>
            <properties>
                <osmosisScope>provided</osmosisScope>
                <jarWarning></jarWarning>
            </properties>
        </profile>
    </profiles>
    <repositories>
        <repository>
            <id>osgeo</id>
            <name>Open Source Geospatial Foundation Repository</name>
            <url>http://download.osgeo.org/webdav/geotools/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-core</artifactId>
            <version>0.43-RELEASE</version>
            <scope>${osmosisScope}</scope>
        </dependency>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-xml</artifactId>
            <version>0.43.1</version>
            <scope>${osmosisScope}</scope>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geotiff</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>${geotools.version}</version>                 
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.3.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>hello.OSMOSIS.DoNothingBecauseImAPluginOnly</Main-Class>
                                        <Implementation-Vendor>Blapfi</Implementation-Vendor>
                                        <Implementation-Vendor-Id>huiuiui</Implementation-Vendor-Id>
                                        <Implementation-Version>bapfi</Implementation-Version>
                                    </manifestEntries>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

おそらく、誰かが私が間違っていることについてヒントを与えることができますか? とても素晴らしいでしょう。:-)

4

1 に答える 1