def importRaster():
        try:
            ilw.Engine.setWorkingCatalog("file:///C:/xxx")
            raster = ilw.RasterCoverage("EV_2003_al_warp.bsq")
            b = rasterCoverageToIndexedNumpy(raster, 28992, 366, 'bycolumn')
            print('saving object to disk')
            fileIO.saveObject('C:/xxx/new/EV_2003_al_warp', b)
            print('loading object from disk')
            c = fileIO.loadObject('C:/xxx/new/EV_2003_al_warp')
            return b, c

        except Exception as e:
            print(e)
Пример #2
0
    def importSingleBandRaster():
        try:
            ilw.Engine.setWorkingCatalog("file:///D:/xxx/new")
            raster = ilw.RasterCoverage("T_2010_all_warp.bsq")
            b=rasterCoverageToIndexedNumpy(raster,28992,1,'bycolumn')
            print ('saving object to disk')
            fileIO.saveObject('D:/xxx/T_2010_all_warp_1',b)
            print ('loading object from disk')
            c=fileIO.loadObject('D:/xxx/T_2010_all_warp_1')
            return b,c

        except Exception as e:
            print (e)
Пример #3
0
    def importSingleBand():
        try:
            ilw.Engine.setWorkingCatalog("file:///D:/xxx/new")
            raster = ilw.RasterCoverage("T_2010_all_warp.bsq")
            print ('creating pixel iterator')
            it = iter(raster)
            print ('exporting to indexed numpy array')
            a=singleBandToIndexedNumpy(it)
            print ('saving object to disk')
            fileIO.saveObject('D:/xxx/new/T_2010_single',a)
            print ('loading object from disk')
            c=fileIO.loadObject('D:/xxx/new/T_2010_single')
            return a,c

        except Exception as e:
            print (e)
import ilwisobjects as ilwis
import numpy as np
import matplotlib.pyplot as plt

#do not visualize the ilwis messages
ilwis.disconnectIssueLogger()

means = []
bandmeans = []
ndvinodatavalue = -10
rdnew = 28992
for ndviname in ['T_2009.tif']:
    print('loading raster')
    ilwis.Engine.setWorkingCatalog(r'D:\xxx\new')
    ndvi = ilwis.RasterCoverage(ndviname)
    csynew = ilwis.CoordinateSystem('epsg:' + str(rdnew))
    ndvi.geoReference().setCoordinateSystem(csynew)
    #georeference="code=georef:type=corners,csy=epsg:"+str(epsg)+",envelope="+str(topleftx)+" "+str(toplefty)+" "+str(bottomrightx)+" "+str(bottomrighty)+",gridsize="+str(width)+" "+str(height)+",cornerofcorners=yes,name="+name

    nbands = ndvi.size().zsize
    print('ndvi has ' + str(nbands) + ' bands')

    b = ilwisRasterIO.rasterCoverageToIndexedNumpy(ndvi, rdnew, nbands,
                                                   'bycolumn', ndvinodatavalue)
    print(b[0][0].shape)
    print(b[1].shape)

    means.append(b[1].mean())
    xxx = []
    #dividing the raster into 30 bands each and calculating the mean
Пример #5
0
 def describeRaster():
     ilw.Engine.setWorkingCatalog("file:///D:/xxx/new")
     raster = ilw.RasterCoverage("T_2010_all_warp.bsq")
     #raster = ilw.RasterCoverage("2003.tif")
     return describeRasterCoverage(raster,28992)
Пример #6
0
def indexedNumpyToRasterDataset(c, nodata=-1e+308, returnlist=True):
    """Create a raster dataset from an indexed numpy array
        input:  input tuple (index+indexed array+properties dictionary), nodata value, return a list with the bands?
        output: a raster coverage, may return a list where each element as a 1dimensional array for each raster band
    """
    try:
        print('initializing new raster...')
        #Create range
        nr = ilw.NumericRange(0.0, 100000000.0, 0.00001)
        #Create empty Numeric Domain
        numdom = ilw.NumericDomain()
        #Set range of new domain
        numdom.setRange(nr)
        df = ilw.DataDefinition(numdom, nr)
        #initialize new raster coverage
        rc = ilw.RasterCoverage()
        georef = ilw.GeoReference(c[2]['spatialref'])
        rc.setGeoReference(georef)
        rc.setDataDef(df)
        #initialize a support raster coverage
        rc2 = ilw.RasterCoverage()
        rc2.setGeoReference(georef)
        rc2.setDataDef(df)

        #get the number of bands
        if c[1].ndim==1: nbands=1
        #else: nbands=c[1].shape[1]

        # bands were stores bycolumn or byrow
        else:
            if c[2]['band'] == 'byrow':
                nbands=c[1].shape[0]
            else: nbands=c[1].shape[1]

        print ('This array has '+str(nbands)+' bands')
        #create a list to store the bands
        if returnlist:bands=[]
        #create band by band
        print('getting band data....')
        for i in range(nbands):
            itNew = rc2.begin()



            #set an empty numpy array for the band
            a = np.zeros((c[2]['rows']*c[2]['columns']))+nodata
            #fill np array with data from the indexed np array using the index
            if c[1].ndim>1:
                if c[2]['band']=='bycolumn':
                    #a[c[0]] = c[1][:,i].flatten() #flatten will always make a copy
                    a[c[0]] = c[1][:,i].ravel()
                else: #byrows
                    #a[c[0]] = c[1][i,:].flatten()
                    a[c[0]] = c[1][i,:].ravel()
            else: #single band raster
                a[c[0]] = c[1][:].flatten()
            #print (a)
            #print (a.shape[0])

            if returnlist:bands.append(a)
            #fill iterator with pixel data
            for y in range(a.shape[0]):
                itNew[y] = a[y]

            print ('adding band'+ str(i))
            #for bands other than the first add the band


            '''
            if i > 0:
                rc.addBand(i+1, rc2.begin())
            else: rc.addBand(1, rc.begin())
            '''

            rc.addBand(i, rc2.begin())


        if returnlist:
            return bands,rc
        else:
            return rc

    except Exception as e:
        raise e
Пример #7
0
    print(pointmap.coordinateSystem().name())
    print(pointmap.featureCount())
    #reproject the points from WGS84 lat/lon to ETRS1989
    ##    csynew = ilwis.CoordinateSystem('epsg:'+str(ETRS1989))
    ##    pointmap.reprojectFeatures(csynew) #this will reprojrct the featurecoverage, does not return a new featurecoverage
    ##
    ##    print(pointmap.coordinateSystem().name())
    ##    print(pointmap.featureCount())
    ##    pointmap.name('pointfile_reprojected')
    ##    #save the reproject featurecoverage to the reprojectd folder
    ##    pointmap.store('file:///'+ workingcatalog4+'/' + reprojected, 'ESRI Shapefile', 'gdal')
    ##
    #load the raster
    print('loading land cover map...')
    ilwis.Engine.setWorkingCatalog('file:///' + workingcatalog3)
    raster = ilwis.RasterCoverage(rastername)

    # perform the pointrastercrossing operation between points and
    print('crossing points with land use map to get the labels...')
    print('getting values...')

    #get the raster value for each point;
    rastervalues = []

    for fc in pointmap:
        x = fc.geometry().envelope().maxCorner().x
        y = fc.geometry().envelope().maxCorner().y
        rastervalues.append(raster.coord2value(ilwis.Coordinate(x, y)))

    #import the raster
    print('loading raster...')
Пример #8
0
#####import multiband image#######
'''
print ('indexing multiband raster...')
def saveimage():
    ilwis.Engine.setWorkingCatalog('file:///'+workingcatalog)
    raster = ilwis.RasterCoverage(inputraster)
    b=ilwisRasterIO.rasterCoverageToIndexedNumpy(raster, epsg, bandstoimport, 'bycolumn', innodatavalue)
    print ('saving object to disk')
    fileIO.saveObject(workingcatalog2+'/'+binaryfile,b)

#you can comment this out once is done once
saveimage()
'''
ilwis.Engine.setWorkingCatalog('file:///' + workingcatalog)
raster = ilwis.RasterCoverage(inputraster)
inputdata = ilwisRasterIO.rasterCoverageToIndexedNumpy(raster, epsg,
                                                       bandstoimport,
                                                       'bycolumn',
                                                       innodatavalue)
print("loading the indexed array from disk...")
#load the indexed array from disk (you created one with ilwisRasterIO.py)
#inputdata=fileIO.loadObject(workingcatalog2+'/'+binaryfile)
####classify image; export image##########


def classify(inputdata, classifier, outnodatavalue, outputpath, outname, frmt):

    print('classify raster, wait...')

    #use only the indexed array inputdata[0] is the index, inputdata[1] the indexed array,