Skip to main content
Solved

Extract band to new raster by Python API in FME 2017

  • February 26, 2017
  • 2 replies
  • 11 views

taojunabc
Participant
Forum|alt.badge.img+6

I was learning Python FME Objects API for Raster, I tried to extract a band to generate a new raster, But it didn't work out. What's wrong with my code?

import fme
import fmeobjects
 
class ExtractRasterByBand(object):
    def __init__(self):
        pass
    def input(self, feature):
        rs=feature.getGeometry()
        rp=rs.getProperties()
        rb=rs.getBand(0)
        
        newfeature=fmeobjects.FMEFeature()
        rsnew=fmeobjects.FMERaster(rp)
        rsnew.appendBand(rb)
        self.pyoutput(newfeature)        
        
    def close(self):
        pass

Best answer by takashi

Hi @taojunabc, why not set the new raster to the new feature as its geometry before outputting?

        ...
        rsnew.appendBand(rb)
        newfeature.setGeometry(rsnew) # Insert this line!
        self.pyoutput(newfeature)

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

2 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • February 26, 2017

Hi @taojunabc, why not set the new raster to the new feature as its geometry before outputting?

        ...
        rsnew.appendBand(rb)
        newfeature.setGeometry(rsnew) # Insert this line!
        self.pyoutput(newfeature)


taojunabc
Participant
Forum|alt.badge.img+6
  • Author
  • Participant
  • February 26, 2017
takashi wrote:

Hi @taojunabc, why not set the new raster to the new feature as its geometry before outputting?

        ...
        rsnew.appendBand(rb)
        newfeature.setGeometry(rsnew) # Insert this line!
        self.pyoutput(newfeature)

Oh, I forgot this step :) Thanks.

 

 


Reply


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