Skip to main content
Solved

Using the FMe Objects API in Python to Raster

  • February 26, 2017
  • 2 replies
  • 18 views

danilo_fme
Evangelist
Forum|alt.badge.img+41

Hello All,

Has someone been to use in the edition FME Deskto 2017 the API in Python to manipulate Raster files?

I need to create a example to share this news to my customer, but my Workspace has a Error when i write the code inside the transformer PythonCaller.

import fme
import fmeobjects


class FMERasterProperties(object):
    def __init__(self):
        pass
    def input(self,feature):
        begin = fmeobjects.FMERasterProperties()
        begin.getNumCols()
        
    def close(self):
        pass

Atttached my Workspace,   * the Reader can be any Raster file

Best answer by takashi

Hi @danilo_inovacao, according to the API doc, constructor of the FMERasterProperties class requires multiple arguments, but you have passed no arguments to the constructor when creating a new instance of the class. It's the direct reason for the error.

If you intend to get the number of columns of the input raster, you can use an FMERasterProperties instance which is returned from the FMERaster.getProperties() method. e.g.

import fme
import fmeobjects

class FMERasterProperties(object):
    def __init__(self):
        pass
    def input(self, feature):
        raster = feature.getGeometry()
        if isinstance(raster, fmeobjects.FMERaster):
            properties = raster.getProperties()
            feature.setAttribute('_num_columns', properties.getNumCols())
        else:
            feature.setAttribute('_error''The geometry is not Raster.')
        self.pyoutput(feature)
        
    def close(self):
        pass

Although the API documentation has not been published on the Knowledge Center yet, you can find the doc with this path in your machine if you selected the option for installing SDK when installing FME 2017.0.

<FME 2017 HOME>/fmeobjects/python/apidoc/index.html

View original
Did this help you find an answer to your question?

2 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • February 26, 2017

Hi @danilo_inovacao, according to the API doc, constructor of the FMERasterProperties class requires multiple arguments, but you have passed no arguments to the constructor when creating a new instance of the class. It's the direct reason for the error.

If you intend to get the number of columns of the input raster, you can use an FMERasterProperties instance which is returned from the FMERaster.getProperties() method. e.g.

import fme
import fmeobjects

class FMERasterProperties(object):
    def __init__(self):
        pass
    def input(self, feature):
        raster = feature.getGeometry()
        if isinstance(raster, fmeobjects.FMERaster):
            properties = raster.getProperties()
            feature.setAttribute('_num_columns', properties.getNumCols())
        else:
            feature.setAttribute('_error''The geometry is not Raster.')
        self.pyoutput(feature)
        
    def close(self):
        pass

Although the API documentation has not been published on the Knowledge Center yet, you can find the doc with this path in your machine if you selected the option for installing SDK when installing FME 2017.0.

<FME 2017 HOME>/fmeobjects/python/apidoc/index.html


danilo_fme
Evangelist
Forum|alt.badge.img+41
  • Author
  • Evangelist
  • February 28, 2017
takashi wrote:

Hi @danilo_inovacao, according to the API doc, constructor of the FMERasterProperties class requires multiple arguments, but you have passed no arguments to the constructor when creating a new instance of the class. It's the direct reason for the error.

If you intend to get the number of columns of the input raster, you can use an FMERasterProperties instance which is returned from the FMERaster.getProperties() method. e.g.

import fme
import fmeobjects

class FMERasterProperties(object):
    def __init__(self):
        pass
    def input(self, feature):
        raster = feature.getGeometry()
        if isinstance(raster, fmeobjects.FMERaster):
            properties = raster.getProperties()
            feature.setAttribute('_num_columns', properties.getNumCols())
        else:
            feature.setAttribute('_error''The geometry is not Raster.')
        self.pyoutput(feature)
        
    def close(self):
        pass

Although the API documentation has not been published on the Knowledge Center yet, you can find the doc with this path in your machine if you selected the option for installing SDK when installing FME 2017.0.

<FME 2017 HOME>/fmeobjects/python/apidoc/index.html

Thanks @takashi your excellent explanation about this code.   :)

 

 


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