Band maths between a raster and a shapefile vector using the graph builder


I’m trying to implement a very basic process in the Graph Builder :

  1. Read a GeoTiff file (it’s a subset of a Sentinel-1 single polarization calibrated product: single band Sigma0_VV).
  2. Import a shapefile mask (an ESRI Shapefile file covering the same area).
  3. Using Band Maths operator calculate the result of the expression: GeoTiff * Shapefile.
  4. Save the result in Dimap format.

Here is the graph xml generated:

<graph id="Graph">
  <node id="Read">
    <parameters class="com.bc.ceres.binding.dom.XppDomElement">

  <node id="Import-Vector">
      <sourceProduct refid="Read"/>
    <parameters class="com.bc.ceres.binding.dom.XppDomElement">

  <node id="BandMaths">
      <sourceProduct refid="Import-Vector"/>
    <parameters class="com.bc.ceres.binding.dom.XppDomElement">
          <expression>Sigma0_VV * ST20150315_Extent</expression>

  <node id="Write">
      <sourceProduct refid="BandMaths"/>
    <parameters class="com.bc.ceres.binding.dom.XppDomElement">

With this graph.xml file, the Graph Builder GUI used to show this error:

  • Could not parse expression: 'Sigma0_VV * ST20150315_Extent'. Numeric operands expected for binary '*' operator..
  • Then it transformed to this one: Expression is invalid. Undefined symbol 'Sigma0_VV.

Please note that this same process works perfectly well, when I do it manually (step by step using the GUI). And, I needed to uncheck virtual band in the band maths to save the result in a separate band in the new product.

I wonder if it’s just a bug or a step is missing in my process (between the import vector and the band maths).


You mention GeoTiffs - are you sure that you are at all times working with the full satellite product (contains full metadata) instead of the .tif measurement datasets? In practical terms you should never need to open the tiff-files themselves, but instead work with the full product (originally a .zip) and after subsetting save as Dimap as is customary inside SNAP.

I don’t think this issue has to do with the type of the input product. I tried as you suggested to give as an input a BEAM-DIMAP instead of a GeoTiff and I’m still getting the same outcome.

There is another error message that appears when I load the graph.xml file inside the graph builder:
java.lang.String cannot be cast to org.esa.snap.gpf.operators.standard.BandMathsOp$BandDescriptor.

Maybe this could be helpful to track what’s missing in my graph.xml.

This is a known issue that has been around for too long. The BandMaths
don’t currently work properly in the graph builder.

1 Like

If I remove the BandMaths node from the graph.xml and keep only the ImportVector node, it works on the Graph Builder Gui, but not on the command line with gpt. I got this error on the command line with gpt:

Error: com/bc/ceres/swing/figure/FigureStyle

+1 for getting the band maths operator to work in graph builder. It somehow disappeared from the bottom part of graph builder (when I reloaded a graph.xml) where you enter the parameters. In addition it would be great to 1) avoid cryptic (for the normal user) error messages like the one below and 2) the error messages should have a copy/paste option (i don’t like to write all the text to google it or to copy it to this forum)

I am getting this same error message - but am working with Dimap only rather than combining a raster and vector.

Read > Calibration > Speckle Filter > Band Maths

Expression is invalid. Undefined symbol ‘Sigma0_VV’

Simlar to the OP - the steps work fine on the GUI version, just not the graphbuilder. Is there any update on this?

SNAP 3.0
Windows 7 64bit

One option is not to use the Graphbuilder and assemble the graph on your own and run it from the command line via gpt.

The error is saying you are trying to do something with a band called Sigma0_VV but it can’t be found. Are you sure for your current product the band exists? I’m guessing it’s possible you saved the graph from a product which had VV and now may be running it on a different product without VV.

It doesn’t exist - but the previous graph step (Calibration) should have created it.

I think I found the problem - when changing the ‘Source Product’ in Graph ‘Read’ input it does not update some of the outputs and that causes the broken link - either that or it is linked to working with a subset?

  1. If you subset an area and then working from that
  2. Calibrate - Speckle - Band maths
  3. The sigma0_VV will not be there in the band maths, but is for the larger, unsubsetted file.
  4. Changing back and forth between the windws a few times and switching product types seems to trick it into seeing the correct file.

Haven’t tried the command line yet but will also give that a go too.

Thanks for the replies.

that’s a surprising bug. I have tried exactly the same expression in bandmath operator once separately and once inside a graph builder (to hopefully get the new band separated from the source product) and yet the band-math operator worked flawlessly on its own. I really really appreciate pointing this out