Example #1
0
def GeneralCmdLineProcessor(args, options=0):
    ErrorReset()
    in_sl = _gdal.ListToStringList(args)
    out_sl = _gdal.PyGDALGeneralCmdLineProcessor(in_sl, options)
    out = _gdal.StringListToList(out_sl)
    _gdal.CSLDestroy(in_sl)
    _gdal.CSLDestroy(out_sl)
    if len(out) == 0 and GetLastErrorNo() != 0:
        raise ValueError, GetLastErrorMsg()
    if len(out) == 0:
        return None
    else:
        return out
Example #2
0
    def AdviseRead(self,
                   nXOff,
                   nYOff,
                   nXSize,
                   nYSize,
                   nBufXSize=None,
                   nBufYSize=None,
                   eDT=None,
                   BandMap=None,
                   options=[]):
        if BandMap is None:
            BandMap = range(1, self.RasterCount + 1)
        if eDT is None:
            eDT = self._band[0].DataType
        if nBufXSize is None:
            nBufXSize = nXSize
        if nBufYSize is None:
            nBufYSize = nYSize

        IntBandMap = _gdal.ptrcreate('int', 0, len(BandMap))
        for i in range(len(BandMap)):
            _gdal.ptrset(IntBandMap, BandMap[i], i)

        sl_options = _gdal.ListToStringList(options)
        result = _gdal.GDALDatasetAdviseRead(self._o, nXOff, nYOff, nXSize,
                                             nYSize, nBufXSize, nBufYSize, eDT,
                                             len(BandMap), IntBandMap,
                                             sl_options)
        _gdal.CSLDestroy(sl_options)
        _gdal.ptrfree(IntBandMap)
        return result
Example #3
0
    def AddBand(self, datatype=GDT_Byte, options=[]):

        options_strlist = _gdal.ListToStringList(options)
        result = _gdal.GDALAddBand(self._o, datatype, options_strlist)
        _gdal.CSLDestroy(options_strlist)

        return result
Example #4
0
def CreateAndReprojectImage(src_ds,
                            dst_filename,
                            src_wkt=None,
                            dst_wkt=None,
                            dst_driver=None,
                            create_options=[],
                            eResampleAlg=GRA_NearestNeighbour,
                            warp_memory=0.0,
                            maxerror=0.0):

    if dst_driver is None:
        dst_driver = 'NULL'
    else:
        dst_driver = dst_driver._o

    src_wkt = ToNULLableString(src_wkt)
    dst_wkt = ToNULLableString(dst_wkt)
    dst_filename = ToNULLableString(dst_filename)
    options_strlist = _gdal.ListToStringList(create_options)

    err = _gdal.GDALCreateAndReprojectImage(src_ds._o, src_wkt, dst_filename,
                                            dst_wkt, dst_driver,
                                            options_strlist, eResampleAlg,
                                            warp_memory, maxerror, 'NULL',
                                            'NULL', 'NULL')

    FreeNULLableString(src_wkt)
    FreeNULLableString(dst_wkt)
    FreeNULLableString(dst_filename)
    _gdal.CSLDestroy(options_strlist)

    return err
Example #5
0
 def CopyLayer(self, src_layer, new_name, options=[]):
     md_c = _gdal.ListToStringList(options)
     obj = _gdal.OGR_DS_CopyLayer(self._o, src_layer._o, new_name, md_c)
     _gdal.CSLDestroy(md_c)
     if obj is None and obj != 'NULL':
         raise OGRError, gdal.GetLastErrorMsg()
     else:
         return Layer(obj=obj)
Example #6
0
    def CopyDataSource(self, src_ds, filename, options=[]):
        md_c = _gdal.ListToStringList(options)
        ds_o = _gdal.OGR_Dr_CopyDataSource(self._o, src_ds._o, filename, md_c)
        _gdal.CSLDestroy(md_c)

        if ds_o is None or ds_o == 'NULL':
            raise OGRError, _gdal.CPLGetLastErrorMsg()
        else:
            return DataSource(ds_o)
Example #7
0
    def CreateLayer(self, name, srs=None, geom_type=wkbUnknown, options=[]):
        if srs is None:
            srs_o = 'NULL'
        else:
            srs_o = srs._o

        md_c = _gdal.ListToStringList(options)
        obj = _gdal.OGR_DS_CreateLayer(self._o, name, srs_o, geom_type, md_c)
        _gdal.CSLDestroy(md_c)
        if obj is None or obj == 'NULL':
            raise OGRError, gdal.GetLastErrorMsg()
        else:
            return Layer(obj=obj)
Example #8
0
    def SetMetadata(self, metadata, domain=''):
        if type(metadata) == type({1: 2}):
            md_c = _gdal.DictToStringList(metadata)
        elif type(metadata) == type([1]):
            md_c = _gdal.ListToStringList(metadata)
        elif type(metadata) == type('a'):
            md_c = _gdal.ListToStringList([metadata])
        else:
            raise ValueError, 'metadata not a dict, list or string.'

        result = _gdal.GDALSetMetadata(self._o, md_c, domain)
        _gdal.CSLDestroy(md_c)
        return result
Example #9
0
    def Create(self,
               filename,
               xsize,
               ysize,
               bands=1,
               datatype=GDT_Byte,
               options=[]):

        options_c = _gdal.ListToStringList(options)
        target_ds = _gdal.GDALCreate(self._o, filename, xsize, ysize, bands,
                                     datatype, options_c)
        _gdal.CSLDestroy(options_c)
        if target_ds is None or target_ds == 'NULL':
            return None
        else:
            _gdal.GDALDereferenceDataset(target_ds)
            return Dataset(target_ds)
Example #10
0
 def CreateCopy(self,
                filename,
                source_ds,
                strict=1,
                options=[],
                callback=None,
                callback_data=None):
     options_c = _gdal.ListToStringList(options)
     (prog_cb, prog_info) = \
               _gdal.MakeProgressInfo( callback, callback_data )
     target_ds = _gdal.GDALCreateCopy(self._o, filename, source_ds._o,
                                      strict, options_c, prog_cb, prog_info)
     _gdal.CSLDestroy(options_c)
     _gdal.ptrfree(prog_info)
     if target_ds is None or target_ds == 'NULL':
         return None
     else:
         _gdal.GDALDereferenceDataset(target_ds)
         return Dataset(target_ds)
Example #11
0
    def AdviseRead(self,
                   nXOff,
                   nYOff,
                   nXSize,
                   nYSize,
                   nBufXSize=None,
                   nBufYSize=None,
                   eDT=None,
                   options=[]):
        if eDT is None:
            eDT = self.DataType
        if nBufXSize is None:
            nBufXSize = nXSize
        if nBufYSize is None:
            nBufYSize = nYSize

        sl_options = _gdal.ListToStringList(options)
        result = _gdal.GDALRasterAdviseRead(self._o, nXOff, nYOff, nXSize,
                                            nYSize, nBufXSize, nBufYSize, eDT,
                                            sl_options)
        _gdal.CSLDestroy(sl_options)
        return result