Skip to main content
Question

AppCrash using API Raster - Clipper


danilo_fme
Evangelist
Forum|alt.badge.img+45

Hello Team,

I am try to use Clipper function in Python API for Raster.

When i run my Workspace a crash is happen:

Attached my Workspace.

Thanks in Advance,

2 replies

takashi
Influencer
  • March 12, 2017

Hi @danilo_inovacao, the FME Objects API doesn't have any capability to read and create an FMERaster object from a raster file path, except a case where you read a raster feature from a file using an FMEUniversalReader object.

If the input feature has a raster geometry, this script works to clip the raster held by the input feature and update (overwrite) the geometry of the feature with the clipped raster.

# PythonCaller Script Example: Clip a Raster
# Assuming that the input feature always has a raster geometry.
import fmeobjects

class FMERasterTools(object):
    def input(self, feature):
        # Clipper's extents.
        # Modify these values appropriately according to the requirement.
        xMin, yMin = -97.686430.3571
        xMax, yMax = -97.680230.3509

        # Retrieve the geometry (FMERaster object) from the input feature.        
        raster = feature.getGeometry()
        
        # Create an FMERasterTools object.    
        rasterTools = fmeobjects.FMERasterTools()
    
        # Clip the original raster by the specified extents.
        # The FMERasterTools.clip() method returns a clipped raster.
        newRaster = rasterTools.clip(xMin, yMin, xMax, yMax, raster)
    
        # Set the clipped raster to the feature.
        feature.setGeometry(newRaster)
        
        # Output the feature containing the clipped raster.
        self.pyoutput(feature)

See also the FME Objects Python API Documentation.

<FME 2017 Installation Directory>/fmeobjects/python/apidoc/index.html


danilo_fme
Evangelist
Forum|alt.badge.img+45
  • Author
  • Evangelist
  • March 14, 2017
takashi wrote:

Hi @danilo_inovacao, the FME Objects API doesn't have any capability to read and create an FMERaster object from a raster file path, except a case where you read a raster feature from a file using an FMEUniversalReader object.

If the input feature has a raster geometry, this script works to clip the raster held by the input feature and update (overwrite) the geometry of the feature with the clipped raster.

# PythonCaller Script Example: Clip a Raster
# Assuming that the input feature always has a raster geometry.
import fmeobjects

class FMERasterTools(object):
    def input(self, feature):
        # Clipper's extents.
        # Modify these values appropriately according to the requirement.
        xMin, yMin = -97.686430.3571
        xMax, yMax = -97.680230.3509

        # Retrieve the geometry (FMERaster object) from the input feature.        
        raster = feature.getGeometry()
        
        # Create an FMERasterTools object.    
        rasterTools = fmeobjects.FMERasterTools()
    
        # Clip the original raster by the specified extents.
        # The FMERasterTools.clip() method returns a clipped raster.
        newRaster = rasterTools.clip(xMin, yMin, xMax, yMax, raster)
    
        # Set the clipped raster to the feature.
        feature.setGeometry(newRaster)
        
        # Output the feature containing the clipped raster.
        self.pyoutput(feature)

See also the FME Objects Python API Documentation.

<FME 2017 Installation Directory>/fmeobjects/python/apidoc/index.html

Hi @takashi 

 

  Thans your explatnation and comments inside the code.

 

The explanation was very powerful with this my Doubt.

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings