Solved

Python using calculateSlope


Userlevel 3
Badge +18

I have very little python knowledge so I have real trouble understanding the documentation FME provides:

http://docs.safe.com/fme/html/fmepython/api/fmeobjects/_rastertools/fmeobjects.FMERasterTools.calculateSlope.html?highlight=rastertools#fmeobjects.FMERasterTools.calculateSlope

 

I have a PythonCaller that calculates the slope of a Raster. At the end I want to itterate over the cells to calculate the desired height, but for now I want to understand how to use Python to manipulate a raster.

 

class FeatureProcessor(object):
    def input(self,feature):
            raster = feature.getGeometry()
            rst = fmeobjects.FMERasterTools()
            settings = {'kFME_CalculateSlope_interpolateNodata' : 'No'}
            raster_new = rst.calculateSlope(1,raster,settings)
            feature.setGeometry(raster_new)

This works, except that it still interpolates Nodata. So how should I write down the settings dict to tell the function not to interpolate and use the Horn method?

 

 

 

 

 

icon

Best answer by debbiatsafe 7 July 2021, 02:06

View original

6 replies

Userlevel 5
Badge +29

Any reason you're doing it this way rather than using some of the inbuilt transformers?

Userlevel 3
Badge +18

The next step is to itterate over the cells to set a new height, starting from the lowest or highest cell value working up/down. This I can't do effectively with the current tools.

 

But if I can't get the same results doing this with python and with the slope transformer I will not start the rest of the steps.

Userlevel 5
Badge +29

The next step is to itterate over the cells to set a new height, starting from the lowest or highest cell value working up/down. This I can't do effectively with the current tools.

 

But if I can't get the same results doing this with python and with the slope transformer I will not start the rest of the steps.

I'm struggling to understand exactly what you're trying to achieve. For more complex Raster manipulation I have had great success coercer then to pointclouds and using some of the pointcloud transformers. These may be helpful in what you're wanting to achieve?

 

Userlevel 6
Badge +33

I think the question is, what is the correct syntax to set the setting

kFME_CalculateSlope_interpolateNodata

to

No

because

class FeatureProcessor(object):
    def input(self,feature):
            raster = feature.getGeometry()
            rst = fmeobjects.FMERasterTools()
            settings = {'kFME_CalculateSlope_interpolateNodata' : 'No'}
            raster_new = rst.calculateSlope(1,raster,settings)
            feature.setGeometry(raster_new)

seems to be not correct.

Userlevel 3
Badge +18

I think the question is, what is the correct syntax to set the setting

kFME_CalculateSlope_interpolateNodata

to

No

because

class FeatureProcessor(object):
    def input(self,feature):
            raster = feature.getGeometry()
            rst = fmeobjects.FMERasterTools()
            settings = {'kFME_CalculateSlope_interpolateNodata' : 'No'}
            raster_new = rst.calculateSlope(1,raster,settings)
            feature.setGeometry(raster_new)

seems to be not correct.

I have this workbench and expect the same results from the rasterSlopeCalculator as the PythonCaller. But it is not working so I think I don't understand the Python documentation.

 

The Python_polate_no inspector should have the same result as the Slope_polate_no AND

The Python_polate_yes inspector should have the same result as the Slope_polate_yes

 

So i'm doing something wrong on line 5 or 6, but I don't know what.

 

 

 

Userlevel 3
Badge +17

Also replying here for greater visibility. The correct syntax for the key kFME_CalculateSlope_interpolateNodata would be:

settings = {fmeobjects.kFME_CalculateSlope_interpolateNodata:'No'}

Note that the key is a constant instead of a literal string.

Reply