Hi all,
I am working on my raster branch again:
One of the things I would like the geoscript raster module to be able to do is map algebra. My Raster class now has add, minus, divide, multiply methods that use the wonderful org.geotools.coverage.processing.operation classes and jiffle. I noticed that GeoTools didn't have Subtract and Divide operations, so I took a stab at implementing them:
Divide works fine but Subtract gives me an exception:
java.lang.IllegalArgumentException: Illegal transform of type "ConstantTransform1D".
at org.geotools.coverage.Category.<init>(Category.java:494)
at org.geotools.coverage.Category.<init>(Category.java:429)
at org.geotools.coverage.Category.<init>(Category.java:398)
at org.geotools.coverage.processing.OperationJAI.deriveCategory(OperationJAI.java:841)
at org.geotools.coverage.processing.OperationJAI.deriveSampleDimension(OperationJAI.java:792)
at org.geotools.coverage.processing.OperationJAI.deriveGridCoverage(OperationJAI.java:572)
at org.geotools.coverage.processing.OperationJAI.doOperation(OperationJAI.java:302)
at org.geotools.coverage.processing.CoverageProcessor.doOperation(CoverageProcessor.java:542)
at org.geotools.coverage.processing.CoverageProcessor.doOperation(CoverageProcessor.java:564)
at org.geotools.coverage.processing.CoverageProcessor$doOperation.call(Unknown Source)
...
Caused by: org.opengis.referencing.operation.NoninvertibleTransformException: Transform is not invertible.
at org.geotools.referencing.operation.transform.AbstractMathTransform.inverse(AbstractMathTransform.java:585)
at org.geotools.referencing.operation.transform.LinearTransform1D.inverse(LinearTransform1D.java:167)
at org.geotools.coverage.Category.<init>(Category.java:530)
at org.geotools.coverage.GeophysicsCategory.<init>(GeophysicsCategory.java:58)
at org.geotools.coverage.Category.<init>(Category.java:485)
...
when called:
def processor = new CoverageProcessor()
def params = processor.getOperation("Subtract").parameters
params.parameter("Source0").value = this.coverage
params.parameter("Source1").value = other.coverage
def newCoverage = processor.doOperation(params)
new Raster(newCoverage)
so I switched to Jiffle and it works:
MapAlgebra mapAlgebra = new MapAlgebra()
List size = this.size
Raster output = mapAlgebra.calculate("dest = src1 - src2;", [src1: this, src2: other])
output
Sorry for the long email, but I was hoping someone could help. Is using the org.geotools.coverage.processing.operation classes the right way to go, or should I just use Jiffle?
Thanks,
Jared