Geotools 找不到 HSQL EPSG DB,引发错误:NoSuchAuthorityCodeException

2022-09-02 23:50:02

我正在Apache Storm中运行Geotools,并且对geotools依赖性管理进行了一段时间。当我在本地运行风暴群集(Windows 7笔记本电脑)时,一切都有效,但是当我部署到群集时,我会在日志中得到此异常。

编辑:这是我使用的Java调用此功能

      GridCoverage2D image = 
new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});
        /**
         * reproject to WGS84
         */
        CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
        GridCoverage2D reprojectedImage = (GridCoverage2D) Operations.DEFAULT.resample(image, targetCRS);

这是我的环境

geotools 11.1
java 7
POM is below
running on windows 7 when in local mode (works perfectly here)
this problem happens on Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-63-virtual x86_64)

here's the exception from the log


[ERROR] Exception in Bolt org.geotools.data.DataSourceException: GEOTIFF Module Error Report
No code "EPSG:32637" from authority "EPSG" found for object of type "EngineeringCRS".
ModelPixelScaleTag: [2.0,2.0,0.0]
ModelTiePointTag: (1 tie points)
TP #0: [0.0,0.0,0.0] -> [337668.0,3837288.0,0.0]
ModelTransformationTag: NOT AVAILABLE
GeoKey #1: Key = 2049, Value = GCS_WGS_1984
GeoKey #2: Key = 2054, Value = 9102
GeoKey #3: Key = 3072, Value = 32637
GeoKey #4: Key = 1024, Value = 1
GeoKey #5: Key = 1025, Value = 1
GeoKey #6: Key = 1026, Value = PCS Name = WGS_1984_UTM_zone_37N
GeoKey #7: Key = 3076, Value = 9001
org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:32637" from authority "EPSG" found for object of type "EngineeringCRS".
        at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.noSuchAuthorityException(CartesianAuthorityFactory.java:136)
        at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.createEngineeringCRS(CartesianAuthorityFactory.java:130)
        at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.createCoordinateReferenceSystem(CartesianAuthorityFactory.java:121)
        at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:802)
        at org.geotools.coverage.grid.io.imageio.geotiff.GeoTiffMetadata2CRSAdapter.createProjectedCoordinateReferenceSystem(GeoTiffMetadata2CRSAdapter.java:284)
        at org.geotools.coverage.grid.io.imageio.geotiff.GeoTiffMetadata2CRSAdapter.createCoordinateSystem(GeoTiffMetadata2CRSAdapter.java:205)
        at org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:299)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:211)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:156)
        at dgi.eii.utils.PixelExtractor.extract(PixelExtractor.java:80)
        at dgi.eii.storm.bolts.RasterPixelExtractorBolt.execute(RasterPixelExtractorBolt.java:59)
        at backtype.storm.daemon.executor$fn__5641$tuple_action_fn__5643.invoke(executor.clj:631)
        at backtype.storm.daemon.executor$mk_task_receiver$fn__5564.invoke(executor.clj:399)
        at backtype.storm.disruptor$clojure_handler$reify__745.onEvent(disruptor.clj:58)
        at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:125)
        at backtype.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:99)
        at backtype.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:80)
        at backtype.storm.daemon.executor$fn__5641$fn__5653$fn__5700.invoke(executor.clj:746)
        at backtype.storm.util$async_loop$fn__457.invoke(util.clj:431)
        at clojure.lang.AFn.run(AFn.java:24)
        at java.lang.Thread.run(Thread.java:745)

当我遇到带有EPSQ:4326的图像时,我也会得到相同的错误

 [ERROR] Exception in Bolt org.geotools.data.DataSourceException: GEOTIFF Module Error Report
No code "EPSG:4326" from authority "EPSG" found for object of type "EngineeringCRS".
ModelPixelScaleTag: [2.0230196490091333E-5,2.0230196490071028E-5,0.0]
ModelTiePointTag: (1 tie points)
TP #0: [0.0,0.0,0.0] -> [36.8167576323252,34.429979601192464,0.0]
ModelTransformationTag: NOT AVAILABLE
GeoKey #1: Key = 2048, Value = 4326
GeoKey #2: Key = 2049, Value = GCS_WGS_1984
GeoKey #3: Key = 2054, Value = 9102
GeoKey #4: Key = 1024, Value = 2
GeoKey #5: Key = 2057, Value = 6378137.0
GeoKey #6: Key = 1025, Value = 1
GeoKey #7: Key = 2059, Value = 298.257223563
org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:4326" from authority "EPSG" found for object of type "EngineeringCRS".
        at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.noSuchAuthorityException(CartesianAuthorityFactory.java:136)
        at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.createEngineeringCRS(CartesianAuthorityFactory.java:130)
        at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.createCoordinateReferenceSystem(CartesianAuthorityFactory.java:121)
        at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:802)
        at org.geotools.coverage.grid.io.imageio.geotiff.GeoTiffMetadata2CRSAdapter.createGeographicCoordinateReferenceSystem(GeoTiffMetadata2CRSAdapter.java:389)
        at org.geotools.coverage.grid.io.imageio.geotiff.GeoTiffMetadata2CRSAdapter.createCoordinateSystem(GeoTiffMetadata2CRSAdapter.java:208)
        at org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:299)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:211)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:156)
        at dgi.eii.utils.PixelExtractor.extract(PixelExtractor.java:80)
        at dgi.eii.storm.bolts.RasterPixelExtractorBolt.execute(RasterPixelExtractorBolt.java:59)
        at backtype.storm.daemon.executor$fn__5641$tuple_action_fn__5643.invoke(executor.clj:631)
        at backtype.storm.daemon.executor$mk_task_receiver$fn__5564.invoke(executor.clj:399)
        at backtype.storm.disruptor$clojure_handler$reify__745.onEvent(disruptor.clj:58)
        at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:125)
        at backtype.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:99)
        at backtype.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:80)
        at backtype.storm.daemon.executor$fn__5641$fn__5653$fn__5700.invoke(executor.clj:746)
        at backtype.storm.util$async_loop$fn__457.invoke(util.clj:431)
        at clojure.lang.AFn.run(AFn.java:24)
        at java.lang.Thread.run(Thread.java:745)

我已经看到几个答案,表明我需要将gt-epsg-hsql放在我的pom中,而我仍然没有找到它需要的东西。

这是我的地理工具POM条目

 <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-swing</artifactId>
            <version>11.1</version>        
        </dependency>
         <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-opengis</artifactId>
            <version>11.1</version>        
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>11.1</version>                 
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geotiff</artifactId>
            <version>11.1</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-image</artifactId>
            <version>11.1</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-wms</artifactId>
            <version>11.1</version>
        </dependency>

这就是我如何用maven shade插件构建uber-jar

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                    <!--  <minimizeJar>true</minimizeJar>-->
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>stand-alone</shadedClassifierName>
                    <artifactSet>
                        <excludes>                 
                            <exclude>org.slf4j:slf4j-api:jar:</exclude>
                            <exclude>org.slf4j:slf4j-simple:jar:1.6.4:jar:</exclude>
                            <exclude>org.slf4j:slf4j-log4j12:jar:</exclude>
                            <exclude>org.slf4j:jcl-over-slf4j:jar:</exclude>
                            <exclude>org.slf4j:slf4j-api:jar:1.7.5:jar:</exclude>
                            <!-- <exclude>org.slf4j*:</exclude>-->
                            <exclude>commons-logging:commons-logging:jar:</exclude>
                            <exclude>commons-logging:commons-logging-api:jar:</exclude>
                        </excludes>
                    </artifactSet>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <finalName>storm-topos</finalName>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>dgi.eii.storm.base.StormTopologyRunner</mainClass>
                        </transformer>
                       <!-- <transformer
                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.handlers</resource>
                        </transformer>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.schemas</resource>
                        </transformer>-->
                    </transformers>
                </configuration>
            </plugin>
        </plugins>
    </build>

编辑:所以我想出了一些事情,并得到了一点点...现在收到此错误

[ERROR] Exception in Bolt org.geotools.data.DataSourceException: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;

导致上述新错误的这种轻微进步是由于使用了正确的转换器,并使用maven jar插件将正确的条目注入到MANIFEST中。MF 文件。这是我的POM的新版本构建部分,它可能有助于某人至少克服geotools的META-INF /服务文件的合并,并注入正确的条目以克服旧的错误vendorname cannot be null!

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>false</filtering>
            <includes>
                <include>schema.xsd</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>stand-alone</shadedClassifierName>
                <artifactSet>
                    <excludes>
                        <exclude>org.slf4j:slf4j-api:jar:</exclude>
                        <exclude>org.slf4j:slf4j-log4j12:jar:</exclude>
                        <exclude>org.slf4j:jcl-over-slf4j:jar:</exclude>

                        <exclude>commons-logging:commons-logging:jar:</exclude>
                        <exclude>commons-logging:commons-logging-api:jar:</exclude>
                    </excludes>
                </artifactSet>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
                <finalName>insightcloud-storm-topos</finalName>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>dgi.eii.storm.base.StormTopologyRunner</mainClass>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>

                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.handlers</resource>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.schemas</resource>
                    </transformer>
                </transformers>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
    </plugins>

</build>

答案 1

Geotools 使用 Java 的服务基础结构来加载负责 EPSG 查找的类。原始文件具有指定哪些接口由 jar 文件实现的条目,以及哪些接口可以在运行时动态加载。gt-epsg-hsql.jar/META-INF/services/

在构建超级 jar 时,您可以将多个 jar 文件合并为一个。最有可能的是,另一个 jar 文件也实现了相同的接口(例如 ),因此在其 中具有具有相同名称的文件。当把所有东西放到一个jar文件中时,这些条目很可能会被覆盖(至少我找不到任何关于maven-shade-plugin合并这些服务文件的引用)。gt-referencing.jar/META-INF/services/

您可以通过查看创建的 uber-jar 中的服务目录来验证这一点,尤其是在条目 。两者都有这样一个文件(可能还有来自GeoTools的其他jar文件),并且最有可能的是,只有一个的内容将出现在你的uber-jar中,导致所有其他类在运行时找不到/加载。/META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactorygt-epsg-hsql.jargt-referencing.jar

我不太熟悉maven-shade-plugin,但是关于SO的其他问题(如[1])建议使用额外的转换器:

<transformer
   implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />

编辑:由于这个答案得到了定期访问,而且我现在对shade插件很熟悉,这里有一个更详细的指南来使用shade-plugin。

因此,我们可以使用maven-shade插件来创建一个多合一jar,而不是使用maven-assembly插件。为此,请在室内配置 maven-shade 插件并将其绑定到包阶段(因此,每当您调用 时,都会创建着色 jar:pom.xmlmvn package

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.1.0</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <transformers>
              <!-- This bit sets the main class for the executable jar as you otherwise -->
              <!-- would with the assembly plugin                                       -->
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <manifestEntries>
                  <Main-Class>com.example.YourMainClass</Main-Class>
                  <Implementation-Vendor>Your Company Name</Implementation-Vendor>
                  <Implementation-Version>${project.version}</Implementation-Version>
                </manifestEntries>
              </transformer>
              <!-- This bit merges the various GeoTools META-INF/services files         -->
              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

和 可能不是在所有情况下都需要,但是我观察到一些代码(我认为JAI - Java高级映像)在缺少此信息时抱怨和行为不端的情况,可能是因为原始JAR包含此类信息,而默认情况下没有阴影,因此最好只包含它。Implementation-VendorImplementation-Version

运行时,它会将原始 jar 文件重命名为类似的东西,并将阴影(=多合一,胖罐,超级罐)放在 。如果您不喜欢此行为,并希望保持原始 jar 文件不变,并将带阴影的 jar 文件分隔开来,请在块中添加以下行:mvn packageoriginal-myArtifact.jarmyArtifact.jarconfiguration

<shadedArtifactAttached>true</shadedArtifactAttached>

在这种情况下,构建过程将创建一个文件(类似于由程序集插件创建)。myArtifact-shaded.jarmyArtifact-jar-with-dependencies.jar


[1] Maven shade + resteasy 可以找到内容类型的作家


答案 2

我也遇到了这个问题。与其把头撞在墙上,不如使用一种解决方法,即从WKT创建CRS,而不是使用:decode

private static final String EPSG4326 = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";
    CoordinateReferenceSystem worldCRS = CRS.parseWKT(EPSG4326);

一个提示是,如果使用此方法,则生成的 CRS 将首先在 WKT 中存储经度,然后存储纬度。使用ServicesResourceTransformer为WKT提供纬度后跟经度。有关此问题的更多信息,请访问此链接 http://docs.geotools.org/latest/userguide/library/referencing/order.html


推荐