Class Operator
- Direct Known Subclasses:
BandMathsOp,GraphOp,ImportVectorOp,JaiOp,MergeOp,MosaicOp,PassThroughOp,PointOperator,ProductSetReaderOp,QuantizationOp,RasterToVectorOp,ReadOp,ReprojectionOp,ResamplingOp,SubsetOp,ToolAdapterOp,WriteOp,WriteRGBOp
The following methods are intended to be implemented or overridden:
initialize(): must be implemented in order to initialise the operator and create the target product.computeTile(): implemented to compute the tile for a single band.computeTileStack(Map, Rectangle, ProgressMonitor): implemented to compute the tiles for multiple bands.dispose(): can be overridden in order to free all resources previously allocated by the operator.
Generally, only one computeTile method needs to be implemented. It depends on the type of algorithm which
of both operations is most advantageous to implement:
- If bands can be computed independently of each other, then it is
beneficial to implement the
computeTile()method. This is the case for sub-sampling, map-projections, band arithmetic, band filtering and statistic analyses. computeTileStack()should be overridden in cases where the bands of a product cannot be computed independently, e.g. because they are a simultaneous output. This is often the case for algorithms based on neural network, cluster analyses, model inversion methods or spectral unmixing.
For information on how to best implement the computeTile() or computeTileStack() method please
read also the Tile documentation.
The framework execute either the computeTile() or the computeTileStack() method
based on the current use case or request.
If tiles for single bands are requested, e.g. for image display, it will always prefer an implementation of
the computeTile() method and call it.
If all tiles are requested at once, e.g. writing a product to disk, it will attempt to use the computeTileStack()
method. If the framework cannot use its preferred operation, it will use the one implemented by the operator.
- Since:
- 4.1
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines whether this operator'scomputeTileStackmethod can be used.booleanDetermines whether this operator'scomputeTileStackmethod can be used.protected final voidChecks for cancellation of the current processing request.voidcomputeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) Called by the framework in order to compute a tile for the given target band.voidcomputeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectangle, ProgressMonitor pm) Called by the framework in order to compute the stack of tiles for the given target bands.voiddispose()Releases the resources the operator has acquired during its lifetime.voidExecutes the operator.protected voidensureSceneGeoCoding(Product... products) Ensures that the given source products all have a scene geo-coding.protected DimensionensureSingleRasterSize(Product... products) Ensures that the given source products only contain raster data nodes having the same size in pixels and that all products have the same scene raster size.protected DimensionensureSingleRasterSize(RasterDataNode... rasterDataNodes) Ensures that the given raster data nodes only contain raster data nodes having the same size in pixels.final voidExecutes the operator.protected final voidfinalize()Overridden in order to force a call todispose(), if not already done.final StringgetId()final LoggerGets the logger whuich can be used to log information during initialisation and tile computation.getParameter(String name) Gets the value for the parameter with the given name.getParameter(String name, Object defaultValue) Gets the value for the parameter with the given name.Provides the context product manager which can be used to exchange product instances across operators or allow (reading) operators to check if a given product is already opened.Gets a single source product.final ProductGets the source product using the specified name.final StringgetSourceProductId(Product product) Gets the identifier for the given source product.final Product[]Gets the source products in the order they have been declared.final TilegetSourceTile(RasterDataNode rasterDataNode, Rectangle region) Gets aTilefor a given band and image region.final TilegetSourceTile(RasterDataNode rasterDataNode, Rectangle region, javax.media.jai.BorderExtender borderExtender) Gets aTilefor a given band and image region.final OperatorSpigetSpi()Gets the SPI which was used to create this operator.final ProductGets the target product for the operator.final ObjectgetTargetProperty(String name) Gets a target property of the operator.abstract voidInitializes this operator and sets the one and only target product.final voidSets the logger which can be used to log information during initialisation and tile computation.voidsetParameter(String name, Object value) Sets the value for the parameter with the given name.voidSets the operator parameters to their default values, if any.protected final voidsetRequiresAllBands(boolean requiresAllBands) final voidsetSourceProduct(String id, Product product) Sets a source product.voidsetSourceProduct(Product sourceProduct) Sets a single source product.final voidsetSourceProducts(Product... products) Sets the source products.final voidsetSpi(OperatorSpi operatorSpi) Sets the SPI which was used to create this operator.final voidsetTargetProduct(Product targetProduct) Sets the target product for the operator.voidNon-API.final voidupdate()Updates this operator forcing it to recreate the target product.
-
Constructor Details
-
Operator
protected Operator()Constructs a new operator.
-
-
Method Details
-
setParameterDefaultValues
public void setParameterDefaultValues()Sets the operator parameters to their default values, if any. -
finalize
Overridden in order to force a call todispose(), if not already done. -
initialize
Initializes this operator and sets the one and only target product.The target product can be either defined by a field of type
Productannotated with theTargetProductannotation or by callingsetTargetProduct(org.esa.snap.core.datamodel.Product)method.This method shall never be called directly. The framework calls this method after it has created an instance of this
Operator. This will occur only once durting the lifetime of anOperatorinstance. If not already done, calling thegetTargetProduct()will always trigger a call to theinitialize()method.Any client code that must be performed before computation of tile data should be placed here.
- Throws:
OperatorException- If an error occurs during operator initialisation.- See Also:
-
update
public final void update()Updates this operator forcing it to recreate the target product. -
execute
Executes the operator. Call this method to execute an operator that doesn't compute raster data tiles on its own.- Parameters:
pm- A progress monitor to be notified for long-running tasks.
-
doExecute
Executes the operator.For operators that compute raster data tiles, the method is usually a no-op. Other operators might perform their main work in this method, e.g. perform some image analysis such as extracting statistics and other features from data products.
Don't call this method directly. The framework may call this method
- once before the very first tile is computed, or
- as a result of a call to
execute(ProgressMonitor).
The default implementation only progresses the progress monitor.
- Parameters:
pm- A progress monitor to be notified for long-running tasks.- Throws:
OperatorException- If an error occurs during computation of the target raster.
-
computeTile
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException Called by the framework in order to compute a tile for the given target band.The default implementation throws a runtime exception with the message "not implemented".
This method shall never be called directly.
- Parameters:
targetBand- The target band.targetTile- The current tile associated with the target band to be computed.pm- A progress monitor which should be used to determine computation cancellation requests.- Throws:
OperatorException- If an error occurs during computation of the target raster.
-
computeTileStack
public void computeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorExceptionCalled by the framework in order to compute the stack of tiles for the given target bands.The default implementation throws a runtime exception with the message "not implemented".
This method shall never be called directly.
- Parameters:
targetTiles- The current tiles to be computed for each target band.targetRectangle- The area in pixel coordinates to be computed (same for all rasters intargetRasters).pm- A progress monitor which should be used to determine computation cancellation requests.- Throws:
OperatorException- If an error occurs during computation of the target rasters.
-
dispose
public void dispose()Releases the resources the operator has acquired during its lifetime. The default implementation does nothing.Overrides should make sure to call
super.dispose()as well. -
canComputeTile
public boolean canComputeTile()Determines whether this operator'scomputeTileStackmethod can be used.The default implementation of this method checks if the this operator's class overrides the
Operator.computeTileStackmethod.- Returns:
trueif so.- Since:
- SNAP 3.0
-
canComputeTileStack
public boolean canComputeTileStack()Determines whether this operator'scomputeTileStackmethod can be used.The default implementation of this method checks if the this operator's class overrides the
Operator.computeTileStackmethod.- Returns:
trueif so.- Since:
- SNAP 3.0
-
getProductManager
Provides the context product manager which can be used to exchange product instances across operators or allow (reading) operators to check if a given product is already opened.- Returns:
- A context product manager.
- Since:
- SNAP 3.0
-
setRequiresAllBands
protected final void setRequiresAllBands(boolean requiresAllBands) -
getId
- Returns:
- The operator's runtime identifier assigned by the framework.
-
getSourceProducts
Gets the source products in the order they have been declared.- Returns:
- The array source products.
-
setSourceProducts
Sets the source products.- Parameters:
products- The source products.- Since:
- BEAM 4.2
-
getSourceProduct
Gets a single source product. This method is a shortcut forgetSourceProduct("sourceProduct").- Returns:
- The source product, or
nullif not set. - Since:
- BEAM 4.2
-
setSourceProduct
Sets a single source product. This method is a shortcut forsetSourceProduct("sourceProduct", sourceProduct).- Parameters:
sourceProduct- the source product to be set- Since:
- BEAM 4.2
-
getSourceProduct
Gets the source product using the specified name.- Parameters:
id- the identifier- Returns:
- the source product, or
nullif not found - See Also:
-
setSourceProduct
Sets a source product. One product instance can be registered with different identifiers, e.g. "source", "source1" and "input" in consecutive calls.- Parameters:
id- a source product identifierproduct- the source product to be set- Since:
- BEAM 4.2
-
getSourceProductId
Gets the identifier for the given source product.- Parameters:
product- The source product.- Returns:
- The identifier, or
nullif no such exists. - See Also:
-
getTargetProduct
Gets the target product for the operator.If the target product is not set, calling this method results in a call to
initialize().- Returns:
- The target product.
- Throws:
OperatorException- May be caused byinitialize(), if the operator is not initialised, or if the target product is not set.
-
setTargetProduct
Sets the target product for the operator.Must be called from within the
initialize()method.- Parameters:
targetProduct- The target product.
-
getTargetProperty
Gets a target property of the operator.If the requested target property is not set, calling this method results in a call to
initialize().- Parameters:
name- the name of the property requested.- Returns:
- the target property requested.
- Throws:
OperatorException- May be caused byinitialize(), if the operator is not initialised, or if the target product is not been set.
-
getParameter
Gets the value for the parameter with the given name.- Parameters:
name- The parameter name.- Returns:
- The parameter value, which may be
null. - Since:
- BEAM 4.7
-
getParameter
Gets the value for the parameter with the given name.- Parameters:
name- The parameter name.defaultValue- The default value which is used in casegetParameter(String)returnsnull. May benull.- Returns:
- The parameter value, or the given
defaultValue. - Since:
- BEAM 5.0
-
setParameter
Sets the value for the parameter with the given name.- Parameters:
name- The parameter name.value- The parameter value, which may benull.- Since:
- BEAM 4.7
-
getSourceTile
public final Tile getSourceTile(RasterDataNode rasterDataNode, Rectangle region) throws OperatorException Gets aTilefor a given band and image region.- Parameters:
rasterDataNode- the raster data node of a data product, e.g. aBandorTiePointGrid.region- the image region in pixel coordinates- Returns:
- a tile.
- Throws:
OperatorException- if the tile request cannot be processed
-
getSourceTile
public final Tile getSourceTile(RasterDataNode rasterDataNode, Rectangle region, javax.media.jai.BorderExtender borderExtender) throws OperatorException Gets aTilefor a given band and image region. The region can overlap the bounds of source image. This method is particularly useful if you need to compute target pixels from an n x m region around a corresponding source pixel. In this case an extended tile will need to be read from the source.- Parameters:
rasterDataNode- the raster data node of a data product, e.g. aBandorTiePointGrid.region- The image region in pixel coordinatesborderExtender- A strategy used to fill the raster regions that lie outside the bounds of the source image.- Returns:
- A tile whose region can overlap the bounds of source image.
- Throws:
OperatorException- if the tile request cannot be processed- Since:
- BEAM 4.7.1
-
checkForCancellation
Checks for cancellation of the current processing request. Throws an exception, if the request has been canceled (e.g. by the user).- Throws:
OperatorException- if the current processing request has been canceled (e.g. by the user).
-
ensureSceneGeoCoding
Ensures that the given source products all have a scene geo-coding. Operator implementations may use this method in theirinitialize()method to ensure that their sources are geo-coded.- Parameters:
products- The products to test.- Throws:
OperatorException- if any product has no geo-coding.- Since:
- SNAP 3
-
ensureSingleRasterSize
Ensures that the given source products only contain raster data nodes having the same size in pixels and that all products have the same scene raster size. Operator implementations may use this method in theirinitialize()method if they can only deal with single-size sources.- Parameters:
products- Source products products to test.- Returns:
- the unique raster size,
nullifproductsis an empty array - Throws:
OperatorException- if the product contains multi-size rasters.- Since:
- SNAP 3
-
ensureSingleRasterSize
protected Dimension ensureSingleRasterSize(RasterDataNode... rasterDataNodes) throws OperatorException Ensures that the given raster data nodes only contain raster data nodes having the same size in pixels.- Parameters:
rasterDataNodes- Other optional products to test.- Returns:
- the unique raster size,
nullifrasterDataNodesis an empty array - Throws:
OperatorException- if the product contains multi-size rasters.- Since:
- SNAP 3
-
getLogger
Gets the logger whuich can be used to log information during initialisation and tile computation.- Returns:
- The logger.
-
setLogger
Sets the logger which can be used to log information during initialisation and tile computation.- Parameters:
logger- The logger.
-
stopTileComputationObservation
public void stopTileComputationObservation()Non-API. -
getSpi
Gets the SPI which was used to create this operator. If no operator has been explicitly set, the method will return an anonymous SPI.- Returns:
- The operator SPI.
-
setSpi
Sets the SPI which was used to create this operator.- Parameters:
operatorSpi- The operator SPI.
-