Changeset 19377


Ignore:
Timestamp:
Apr 11, 2010 4:52:25 AM (6 years ago)
Author:
rouault
Message:

NumPy? Band.WriteArray?() : use numpy object directly instead of converting to string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gdal/swig/include/gdal_array.i

    • Property svn:keywords set to Id
    r18192 r19377  
    521521
    522522%apply ( int *optional_int ) {(int*)};
    523 %feature( "kwargs" ) BandReadRasterNumPy;
     523%feature( "kwargs" ) BandRasterIONumPy;
    524524%inline %{
    525   CPLErr BandReadRasterNumPy( GDALRasterBandShadow* band, int xoff, int yoff, int xsize, int ysize,
     525  CPLErr BandRasterIONumPy( GDALRasterBandShadow* band, int bWrite, int xoff, int yoff, int xsize, int ysize,
    526526                     PyArrayObject *psArray,
    527527                     int *buf_xsize = 0,
     
    576576    }
    577577
    578     return  GDALRasterIO( band, GF_Read, xoff, yoff, xsize, ysize,
     578    return  GDALRasterIO( band, (bWrite) ? GF_Write : GF_Read, xoff, yoff, xsize, ysize,
    579579                          psArray->data, nxsize, nysize,
    580580                          ntype, pixel_space, line_space );
     
    737737        datatype = NumericTypeCodeToGDALTypeCode( buf_obj.dtype.type )
    738738           
    739         if BandReadRasterNumPy( band, xoff, yoff, win_xsize, win_ysize,
     739        if BandRasterIONumPy( band, 0, xoff, yoff, win_xsize, win_ysize,
    740740                                buf_obj, buf_xsize, buf_ysize, datatype ) != 0:
    741741            return None
     
    745745def BandWriteArray( band, array, xoff=0, yoff=0 ):
    746746    """Pure python implementation of writing a chunk of a GDAL file
    747     from a numpy array.  Used by the gdal.Band.WriteAsArray method."""
     747    from a numpy array.  Used by the gdal.Band.WriteArray method."""
     748
     749    if array is None or len(array.shape) != 2:
     750        raise ValueError("expected array of dim 2")
    748751
    749752    xsize = array.shape[1]
     
    765768        raise ValueError("array does not have corresponding GDAL data type")
    766769
    767     result = band.WriteRaster( xoff, yoff, xsize, ysize,
    768                                array.tostring(), xsize, ysize, datatype )
    769 
    770     return result
     770    return BandRasterIONumPy( band, 1, xoff, yoff, xsize, ysize,
     771                                array, xsize, ysize, datatype )
    771772
    772773   
Note: See TracChangeset for help on using the changeset viewer.