Skip to main content
Solved

Python using calculateSlope


jkr_wrk
Influencer
Forum|alt.badge.img+29

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?

 

 

 

 

 

Best answer by debbiatsafe

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.

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

6 replies

hkingsbury
Celebrity
Forum|alt.badge.img+55
  • Celebrity
  • June 27, 2021

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


jkr_wrk
Influencer
Forum|alt.badge.img+29
  • Author
  • June 28, 2021

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.


hkingsbury
Celebrity
Forum|alt.badge.img+55
  • Celebrity
  • June 28, 2021
jkr_da wrote:

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?

 


nielsgerrits
VIP
Forum|alt.badge.img+54

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.


jkr_wrk
Influencer
Forum|alt.badge.img+29
  • Author
  • June 30, 2021
nielsgerrits wrote:

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.

 

 

 


debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • July 7, 2021

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.


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