Skip to main content

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

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)


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