I try to vectorize an image using java i.e. geotools with JAI.
The code is minimal and works just fine in intelliJ
InputStream stringAsStream = new ByteArrayInputStream(inputAsciiGrid.getBytes(StandardCharsets.UTF_8));
SimpleFeatureIterator vectorizedFeatures = extractor.execute(input, 0, true, null,
null, classificationRanges, null).features();
My problem is when executing this via maven like:
mvn clean package && \
java -jar target/quickstart-1.0.jar
it fails with exception of
RangeLookup: No OperationDescriptor is registered in the current operation registry under this name
sample code can be found at https://github.com/geoHeil/jts-vectorize
Note, the jar contains the class, but not the OperationDescriptors
in the META-INF/registry.jai
files.
jar -tf target/quickstart-1.0.jar| grep RangeLookupProcess
org/geotools/process/raster/RangeLookupProcess.class
edit
I tried to follow java.lang.ClassNotFoundException: it.geosolutions.jaiext.range.Range and added
<dependency>
<groupId>it.geosolutions.jaiext.utilities</groupId>
<artifactId>jt-utilities</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>it.geosolutions.jaiext.iterators</groupId>
<artifactId>jt-iterators</artifactId>
<version>1.1.8</version>
</dependency>
This changes the exception to:
Exception in thread "main" java.lang.NoClassDefFoundError: it/geosolutions/jaiext/utilities/ImageLayout2
at FooJava.getAsciiGridFromstring(FooJava.java:49)
at FooJava.main(FooJava.java:35)
Caused by: java.lang.ClassNotFoundException: it.geosolutions.jaiext.utilities.ImageLayout2
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
make: *** [run-java] Error 1
even though again the class is there:
geoheil@geoheilsMacBook ~/Downloads/vectorize/jts-vectorize [20:36:45]
> $ jar -tf target/quickstart-1.0.jar| grep ImageLayout2 [±master ●●]
org/jaitools/imageutils/ImageLayout2.class
this seems to be a version mismatch. When reverting and adding the versions also listed in (https://github.com/geotools/geotools/blob/18.4/pom.xml#L97):
<properties>
<geotools.version>18.4</geotools.version>
<jaiext.version>1.0.16</jaiext.version>
</properties>
<dependencies>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-main</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-arcgrid</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-process-raster</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>it.geosolutions.jaiext.utilities</groupId>
<artifactId>jt-utilities</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>it.geosolutions.jaiext.rlookup</groupId>
<artifactId>jt-rlookup</artifactId>
<version>${jaiext.version}</version>
</dependency>
</dependencies>
The error is again the initial one.
edit 2
Manually registering the missing operation descriptor:
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/javax.media.jai.registryFile.jai</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/registryFile.jaiext</resource>
</transformer>
and adding both files (see names above) with content of:
# --- JAI ext manual re-registration ---
descriptor it.geosolutions.jaiext.rlookup.RangeLookupDescriptor
gives me a new exception:
java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:827)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
at javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1791)
at javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:270)
at javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.java:125)
at javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySourceImpl.java:298)
at javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1817)
at javax.media.jai.RenderedOp.getPropertyNames(RenderedOp.java:1851)
at javax.media.jai.PropertySourceImpl.<init>(PropertySourceImpl.java:143)
at org.geotools.coverage.AbstractCoverage.<init>(AbstractCoverage.java:139)
at org.geotools.coverage.grid.AbstractGridCoverage.<init>(AbstractGridCoverage.java:102)
at org.geotools.coverage.grid.GridCoverage2D.<init>(GridCoverage2D.java:186)
at org.geotools.coverage.grid.GridCoverageFactory.create(GridCoverageFactory.java:589)
at org.geotools.process.raster.RangeLookupProcess.execute(RangeLookupProcess.java:208)
at org.geotools.process.raster.RangeLookupProcess.execute(RangeLookupProcess.java:234)
at org.geotools.process.raster.PolygonExtractionProcess.execute(PolygonExtractionProcess.java:167)
at FooJava.getWktForDbRangeFromRaster(FooJava.java:57)
at FooJava.main(FooJava.java:36)
However, this is not necessarily to be considered as progress, i.e. now even IntelliJ fails to start. It fails with: ExceptionInInitializerError
due to null pointer exception