You can access Jiffle the easy way by using the Jiffle process
<https://github.com/geotools/geotools/blob/main/modules/unsupported/process-raster/src/main/java/org/geotools/process/raster/JiffleProcess.java>

Regards,

Andrea Aime


==


GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

==

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax:     +39 0584 1660272

mob:   +39  339 8844549

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it

-------------------------------------------------------

Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE
2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si
precisa che ogni circostanza inerente alla presente email (il suo
contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è
riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il
messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra
operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is
addressed and may contain information that is privileged, confidential or
otherwise protected from disclosure. We remind that - as provided by
European Regulation 2016/679 “GDPR” - copying, dissemination or use of this
e-mail or the information herein by anyone other than the intended
recipient is prohibited. If you have received this email by mistake, please
notify us immediately by telephone or e-mail


On Wed, Sep 3, 2025 at 8:02 AM Jody Garnett <[email protected]> wrote:

> Hi,
>
> This is one of the examples of the Jiffle "raster calculator" operator
> approach.
>
>  9        <Transformation>10          <ogc:Function name="ras:Jiffle">11      
>       <ogc:Function name="parameter">12              
> <ogc:Literal>coverage</ogc:Literal>13            </ogc:Function>14            
> <ogc:Function name="parameter">15              
> <ogc:Literal>script</ogc:Literal>16              <ogc:Literal>17              
>   nir = src[7];18                vir = src[3];19                dest = (nir - 
> vir) / (nir + vir);20              </ogc:Literal>21            
> </ogc:Function>22          </ogc:Function>23        </Transformation>
>
> See
> https://docs.geoserver.org/latest/en/user/styling/sld/extensions/rendering-transform.html#running-map-algebra-on-the-fly-using-jiffle
>
>
> - -
> Jody Garnett
>
>
> On Sep 2, 2025 at 10:47:35 PM, Roar Brænden <[email protected]>
> wrote:
>
>> Hi,
>>
>> I would like to compute NDVI from a Sentinel 2 scene using bands B04 and
>> B08. I asked Copilot if he had a suggestion how to do it, and here is its
>> answer.
>>
>> To compute NDVI (Normalized Difference Vegetation Index) using Geotools
>> from two GridCoverage2D objects (representing the NIR and Red bands),
>> use the Operations class to perform raster math:
>>
>>    1. Subtract Red from NIR: nir - red
>>    2. Add NIR and Red: nir + red
>>    3. Divide the difference by the sum: (nir - red) / (nir + red)
>>
>> Here is how you can do it:
>>
>> // Assume redCoverage and nirCoverage are your GridCoverage2D 
>> objectsOperations op = new Operations(null);
>> // Step 1: Compute numerator (nir - red)GridCoverage2D numerator = 
>> (GridCoverage2D) op.subtract(nirCoverage, redCoverage);
>> // Step 2: Compute denominator (nir + red)GridCoverage2D denominator = 
>> (GridCoverage2D) op.add(nirCoverage, redCoverage);
>> // Step 3: NDVI = (nir - red) / (nir + red)GridCoverage2D ndviCoverage = 
>> (GridCoverage2D) op.divide(numerator, denominator);
>>
>> This will give you a new GridCoverage2D containing the NDVI values.
>>
>>
>> So far, so good. Exactly as I would have thought. The problem is that
>> both op.subtract and op.divide doesn't exists. It is only possible to
>> subtract by a constant or divide by a constant, not by a coverage.
>> That seems strange because add and multiply have functions for both
>> converage and constants and two coverages.
>> Do anyone have an explanation for that?
>>
>> And I know this is old code, and someone might suggest other
>> alternatives. That would be fine as well, but still the code is there and
>> bothers me.
>>
>> Best regards,
>> Roar Brænden
>>
>>
>> _______________________________________________
>> GeoTools-GT2-Users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
> _______________________________________________
> GeoTools-GT2-Users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to