Skip to main content
Solved

Using the FMe Objects API in Python to Raster

  • February 26, 2017
  • 2 replies
  • 41 views

danilo_fme
Celebrity
Forum|alt.badge.img+51

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Celebrity
  • 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
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • February 28, 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

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