Skip to main content
Solved

Python using calculateSlope

  • June 27, 2021
  • 6 replies
  • 26 views

jkr_wrk
Influencer
Forum|alt.badge.img+35

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.

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.

6 replies

hkingsbury
Celebrity
Forum|alt.badge.img+63
  • Celebrity
  • 1625 replies
  • 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+35
  • Author
  • 424 replies
  • 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+63
  • Celebrity
  • 1625 replies
  • 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.

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+60
  • 2938 replies
  • June 30, 2021

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+35
  • Author
  • 424 replies
  • June 30, 2021

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+21
  • Safer
  • 648 replies
  • 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.