Skip to main content

Hi 

I'm using FME WorkBench 2017 and I want to use the pythoncaller to replace the cell values of multiple raster features with list values of an equivalent size. 

 

The input raster features are: 

 

1. different-sized clips of a larger raster 

 

2. in ASCII format, 

 

3. and have a background value of zero. 

For each raster, I want to replace raster cell values greater than zero with values from an associated list, where this list is the same size as all the non-zero values of each raster.    

I'm new to FME and the python caller, but I would use the following code in a regular python console to perform the task:

my_rasterInumpy.nonzero(my_raster)] = my_list 

My confusion lies in correctly using the Template Function and Class Interface so I call the input raster features into the pythoncaller and manipulate them. I am always receiving errors saying that 'my_raster' is being recognised as a string, causing me to think i am not calling it correctly.  

Is there also an FME function that has the same functionality as 'numpy.nonzero()'?

 

Any help is appreciated!! 

Have you looked at the fmeobjects documentation for the raster classes?

http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html

See also the excellent examples posted by Takashi here (scroll down a bit):

https://knowledge.safe.com/questions/38000/python-fme-objects-api-for-raster-manipulation.html


Have you looked at the fmeobjects documentation for the raster classes?

http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html

See also the excellent examples posted by Takashi here (scroll down a bit):

https://knowledge.safe.com/questions/38000/python-fme-objects-api-for-raster-manipulation.html

Thanks @david_r - I had a look at the documentation but couldn't find a function which had the same functionality

 

 

 


Hi @zarquon, how @david_r did write you about the powerful fmeobjects documentation.

The Class FMEBand has any attributes that you can use for it.

Thanks,

Danilo


Hi @zarquon,

The general idea behind FME is NOT to use PythonCaller unless it is really-really necessary - the only proper case to use Python is when FME lacks the appropriate functionality. The pure no-Python approach to designing workspaces is usually much faster.

 

 

I cannot say I fully understood what you are trying to achieve, but I am pretty sure, with a few transformers you can get what you want. Use FeatureMerger, Joiner, or FeatureReader to pass the necessary list values to the rasters, and then use the power of RasterExpressionEvaluator, which can work with attributes and parameters, and understands conditions, to make the necessary replacements.

I can help you more if you let me know more details and can provide a sample dataset. Feel free to contact me directly at dmitri@safe.com

Dmitri

 


Hi @zarquon,

The general idea behind FME is NOT to use PythonCaller unless it is really-really necessary - the only proper case to use Python is when FME lacks the appropriate functionality. The pure no-Python approach to designing workspaces is usually much faster.

 

 

I cannot say I fully understood what you are trying to achieve, but I am pretty sure, with a few transformers you can get what you want. Use FeatureMerger, Joiner, or FeatureReader to pass the necessary list values to the rasters, and then use the power of RasterExpressionEvaluator, which can work with attributes and parameters, and understands conditions, to make the necessary replacements.

I can help you more if you let me know more details and can provide a sample dataset. Feel free to contact me directly at dmitri@safe.com

Dmitri

 

For example, once you joined your values to the raster, you can specify pretty complex cell assignment conditions within RasterExpressionEvaluator.

 

 

Here I specify specific pixel value ranges to replace them with attribute values taken from an attribute "pavement", otherwise, I replace the values with "list{0}.forest". This gives me a raster with two values only. Of course, the conditions can be nested, separate expressions can be written for each band and so on.

 

 

if(A/0]>160&&A;&0]<180&&A;&1]>240&&A;&2]>120&&A;&2]<130,@@Value(A:pavement),@Value(A:list{0}.forest))

Reply