コード例 #1
0
ファイル: dsm.py プロジェクト: niels-anders/eubrazilcc-lidar
def createDSM(x,y,z,xi,yi,bx,by,res,geotransform, proj):
    """
    Create DSM based on max point elevation
    """
    from generic_tools import idw
    #print 'Create DSM (%d x %d)...' % (len(xi), len(yi))
    #time.sleep(0.1)
    #t0 = time.time()
    
    # initialize dsm array
    dsm = np.zeros((len(yi), len(xi))) * np.NaN
    
    #step = 0
    for i in np.arange(len(xi)):
        col = np.argwhere((x > bx[i]) & (x < bx[i+1]))
        for j in np.arange(len(yi)):
            row = (y[col] >= by[j]) & (y[col] < by[j+1])
            if sum(row) > 0:           
                dsm[j,i] = z[col[row]].max()
        #step = ETA(t0,time.time(),0.01,step,i,0,len(xi))                
            
    # fill gaps using IDW interpolation ---------------------------
    XI, YI = np.meshgrid(xi,yi, indexing='xy')
    values = np.isnan(dsm)==0
    nodata = np.isnan(dsm)==1    
    dsm[nodata] = idw(XI[values], YI[values], dsm[values], XI[nodata], YI[nodata], 25)
         
    # return
    #t1 = time.time()
    #print ' --> finished in %1d seconds' % (t1-t0)
    #time.sleep(0.1)
    
    return dsm    
コード例 #2
0
ファイル: dtm.py プロジェクト: niels-anders/eubrazilcc-lidar
def createDTM(x, y, z, xi, yi, res, geotransform, proj, method='idw', printYN='no'):    
    if printYN=='yes':    
        print 'Create DTM (%d x %d)...' % (len(xi), len(yi)),
        time.sleep(0.1)
        t0 = time.time()
        
    XI, YI = np.meshgrid(xi, yi, indexing='xy')

    nnear = 25
    if method=='idw':
        from generic_tools import idw
        dtm = idw(x,y,z,XI.flatten(),YI.flatten(), nnear).reshape(XI.shape)
    else:
        from scipy import interpolate
        dtm = interpolate.griddata((x,y),z,(XI,YI), method=method)
    
    dtm[dtm==-999] = np.NaN

    # return
    if printYN=='yes':    
        t1 = time.time()
        print 'finished in %2d seconds' % (t1-t0)
        time.sleep(0.1)
    return dtm