While developing custom map algebra in GeoTools, I adopted Jiffle. (see : Creating custom Operation for encapsulating some map algebra using GeoTools?)

This allowed very easy implementation of logic but two major issued raised:

  • Jiffle as stated here does all calculations using double values
  • Dumping to GeoTIFF the output ++can take a lot of time++: more than one would expect.

This is how I dump a GridGoverage2D from a Jiffle process.

[.. jiffleProcess defined ouside this snippet ..]
Map<String, Object> output = jiffleProcess.execute(inputs, null);
GridCoverage2D ndviCoverage = (GridCoverage2D) output.get(JiffleProcess.OUT_RESULT);
File outputNDVIGeoTIFF = new File("NDVI.tif");
GridCoverageWriter writerNDVI = geotiffFormat.getWriter(outputNDVIGeoTIFF);     
writerNDVI.write((GridCoverage) ndviCoverage, null);

So the questions are:

  • Can file saving time be shortened in any way? (I mean from GeoTools / Jiffle perspective, not hardware one)

.. but more important:

  • Is there any way to have Jiffle output GridCoverage2D in float to reduce the bits required to store data ?

Well, if the bottleneck is really the file writing and you have enough memory, then why not just create a new GridCoverage of Float (or Short, depending on your content) and just copy the cast data into it after the jiffle operation?

If jiffle only permits double, then you won't have many other options I guess.

To create a coverage of a particular type and populate it with some initial data:

ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, 1, cols, new int[]{0});

WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);

// here use a RectIter or something fast to copy the data from one to the other

Envelope2D writeEnvelope = new Envelope2D(template.getCoordinateReferenceSystem(), west, south, east - west,
        north - south);
GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
GridCoverage2D floatGrid = factory.create("newraster", raster, writeEnvelope);

I know it is not nice to copy stuff around, but the only other way is to write support for more types in jiffle. Which btw, would be really great! :-)

|improve this answer|||||
  • I got your point and it should work. Unfortunately I am on a Windows Server and I also need to execute GDAL binaries as part of the image processing chain. This has forced me to 32bit JDK where I quickly stumble in: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferFloat.<init>(DataBufferFloat.java:87) – mcfoi Feb 15 '19 at 15:01
  • Outch... docker as a last hope? :-) – moovida Feb 15 '19 at 15:09
  • I checked Docker and looks like isn't an option too: requires Windows Server 2016.. ..but my machines run on 2012 R2. – mcfoi Feb 18 '19 at 7:30

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.