Question

Cellwise raster manipulation by indexing row/col using the Python API

  • 7 February 2019
  • 2 replies
  • 6 views

Hello, I need to use FME to do some custom cellwise manipulation of different rasters.

 

I am quite new to FME, but so far my plan is to import rasters using a GeoTIFF reader and then doing custom manipulations in a PythonCreator transformer. Ideally I would like to be able to do operations equivalent to manipulating an numpy array, but I obviously realise that the operations do differ.

 

So far I have gathered that you can access different bands in rasterdata by using getBand(), however I am uncertain in regards to how you go about accessing the data itself and further, how you can change individual values and so on. I have also read up on tiles, and seen examples such as " prevData = prevRaster.getBand(0).getTile(0, 0, tile).getData() " (by @takashi), but I am not confident in exactly how to change individual datapoints within the raster.

 

And as a side question, what is the best/preferred way to troubleshoot code to be used in an PythonCreator?

 

Any help would be greatly appriciated!

 

 


2 replies

Userlevel 1
Badge +10

Hi @laguno, thanks for your questions! Just curious to see if any FME Transformers can do what you are trying to do with Python (i.e. RasterCellValueReplacer, RasterCellValueCalculator, RasterExpressionEvaluator, RasterSelector, RasterConsumer, etc.)

If you need to use python for some custom manipulations, etc., you might consider using a PythonCaller rather that the PythonCreator. The PythonCreator won't have an input port for you to connect to you GeoTIFF Reader.

In terms of troubleshooting, I would imagine many users use a Python IDE to build/debug their scripts before porting it over to FME. However, check out some of these resources which may help with some of the basics:

Let us know how you make out and if you have any further questions.

Badge +3

@laguno

 

G_Dal can target by row and column (cellwise targeting). Though fme seems not to offer this even if they use g-dal.

There is a python package for it PyPi wich can be downloaded from Pypi.org.

 

Reply