當前位置: 首頁>>代碼示例>>Python>>正文


Python gdal.GetDriverByName方法代碼示例

本文整理匯總了Python中osgeo.gdal.GetDriverByName方法的典型用法代碼示例。如果您正苦於以下問題:Python gdal.GetDriverByName方法的具體用法?Python gdal.GetDriverByName怎麽用?Python gdal.GetDriverByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在osgeo.gdal的用法示例。


在下文中一共展示了gdal.GetDriverByName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_tif

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def make_tif(path, tloffset=(0, 0), reso=(0.25, -0.25), rsize=(20, 10),
             proj=SRS[0]['wkt'], channel_count=1, dtype=gdal.GDT_Float32):
    """Create a tiff files and return info about it"""
    tl = ROOT_TL + tloffset
    reso = np.asarray(reso)
    fp = buzz.Footprint(tl=tl, rsize=rsize, size=np.abs(reso * rsize))
    x, y = fp.meshgrid_spatial
    x = np.abs(x) - abs(ROOT_TL[0])
    y = abs(ROOT_TL[1]) - np.abs(y)
    x *= 15
    y *= 15
    a = x / 2 + y / 2
    a = np.around(a).astype('float32')
    driver = gdal.GetDriverByName('GTiff')
    dataset = driver.Create(path, rsize[0], rsize[1], channel_count, dtype)
    dataset.SetGeoTransform(fp.gt)
    dataset.SetProjection(proj)
    for i in range(channel_count):
        dataset.GetRasterBand(i + 1).WriteArray(a)
        dataset.GetRasterBand(i + 1).SetNoDataValue(-32000.)
    dataset.FlushCache()
    return path, fp, a 
開發者ID:airware,項目名稱:buzzard,代碼行數:24,代碼來源:tools.py

示例2: writeRaster

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def writeRaster(arr, out_path, template):
    no_data = 0
    # First of all, gather some information from the template file
    data = gdal.Open(template)
    [cols, rows] = arr.shape
    trans = data.GetGeoTransform()
    proj = data.GetProjection()
    # nodatav = 0 #data.GetNoDataValue()
    # Create the file, using the information from the template file
    outdriver = gdal.GetDriverByName("GTiff")
    # http://www.gdal.org/gdal_8h.html
    # GDT_Byte = 1, GDT_UInt16 = 2, GDT_UInt32 = 4, GDT_Int32 = 5, GDT_Float32 = 6,
    outdata   = outdriver.Create(str(out_path), rows, cols, 1, gdal.GDT_UInt32)
    # Write the array to the file, which is the original array in this example
    outdata.GetRasterBand(1).WriteArray(arr)
    # Set a no data value if required
    outdata.GetRasterBand(1).SetNoDataValue(no_data)
    # Georeference the image
    outdata.SetGeoTransform(trans)
    # Write projection information
    outdata.SetProjection(proj)
    return arr


# raster to vector 
開發者ID:giswqs,項目名稱:lidar,代碼行數:27,代碼來源:slicing.py

示例3: CreateMultiBandGeoTiff

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def CreateMultiBandGeoTiff(OutPath, Array):
    '''
    Author: Jake Shermeyer
    Array has shape:
        Channels, Y, X?
    '''
    driver = gdal.GetDriverByName('GTiff')
    DataSet = driver.Create(OutPath, Array.shape[2], Array.shape[1],
                            Array.shape[0], gdal.GDT_Byte,
                            ['COMPRESS=LZW'])
    for i, image in enumerate(Array, 1):
        DataSet.GetRasterBand(i).WriteArray(image)
    del DataSet

    return OutPath


############################################################################### 
開發者ID:CosmiQ,項目名稱:apls,代碼行數:20,代碼來源:apls_utils.py

示例4: createImageDS

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def createImageDS(filename, x_min, y_min, x_max, y_max, pixel_size,  srs=None):
    # Create the destination data source
    x_res = int((x_max - x_min) / pixel_size) # resolution
    y_res = int((y_max - y_min) / pixel_size) # resolution
    ds = gdal.GetDriverByName('GTiff').Create(filename, x_res,
            y_res, 1, gdal.GDT_Byte)
    ds.SetGeoTransform((
            x_min, pixel_size, 0,
            y_max, 0, -pixel_size,
        ))
    if srs:
        # Make the target raster have the same projection as the source
        ds.SetProjection(srs.ExportToWkt())
    else:
        # Source has no projection (needs GDAL >= 1.7.0 to work)
        ds.SetProjection('LOCAL_CS["arbitrary"]')

    # Set nodata
    band = ds.GetRasterBand(1)
    band.SetNoDataValue(0)

    return ds 
開發者ID:mathildor,項目名稱:TF-SegNet,代碼行數:24,代碼來源:areacoverimage.py

示例5: to_tiff

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def to_tiff(self, filename):
        '''
        geo.to_tiff(filename)

        Saves GeoRaster as geotiff filename.tif with type datatype

        If GeoRaster does not have datatype, then it tries to assign a type.
        You can assign the type yourself by setting
         geo.datatype = 'gdal.GDT_'+type
        '''
        if self.datatype is None:
            self.datatype = gdal_array.NumericTypeCodeToGDALTypeCode(self.raster.data.dtype)
            if self.datatype is None:
                if self.raster.data.dtype.name.find('int') !=- 1:
                    self.raster = self.raster.astype(np.int32)
                    self.datatype = gdal_array.NumericTypeCodeToGDALTypeCode(self.raster.data.dtype)
                else:
                    self.raster = self.raster.astype(np.float64)
                    self.datatype = gdal_array.NumericTypeCodeToGDALTypeCode(self.raster.data.dtype)
        self.raster.data[self.raster.mask] = self.nodata_value
        create_geotiff(filename, self.raster, gdal.GetDriverByName('GTiff'), self.nodata_value,
                       self.shape[1], self.shape[0], self.geot, self.projection, self.datatype) 
開發者ID:ozak,項目名稱:georasters,代碼行數:24,代碼來源:georasters.py

示例6: make_raster

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def make_raster(in_ds, fn, data, data_type, nodata=None):
    """Create a one-band GeoTIFF.

    in_ds     - datasource to copy projection and geotransform from
    fn        - path to the file to create
    data      - NumPy array containing data to write
    data_type - output data type
    nodata    - optional NoData value
    """
    driver = gdal.GetDriverByName('GTiff')
    out_ds = driver.Create(
        fn, in_ds.RasterXSize, in_ds.RasterYSize, 1, data_type)
    out_ds.SetProjection(in_ds.GetProjection())
    out_ds.SetGeoTransform(in_ds.GetGeoTransform())
    out_band = out_ds.GetRasterBand(1)
    if nodata is not None:
        out_band.SetNoDataValue(nodata)
    out_band.WriteArray(data)
    out_band.FlushCache()
    out_band.ComputeStatistics(False)
    return out_ds 
開發者ID:cgarrard,項目名稱:osgeopy-code,代碼行數:23,代碼來源:listing11_1.py

示例7: open_raster

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def open_raster(filename, driver=None):
    """Open raster file, return gdal.Dataset

    Parameters
    ----------
    filename : string
        raster file name
    driver : string
        gdal driver string

    Returns
    -------
    dataset : gdal.Dataset
        dataset
    """

    dataset = gdal.OpenEx(filename)

    if driver:
        gdal.GetDriverByName(driver)

    return dataset 
開發者ID:wradlib,項目名稱:wradlib,代碼行數:24,代碼來源:gdal.py

示例8: write_geotiff

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def write_geotiff(tiff_path, data, upper_left_lon, upper_left_lat, step, AREA_OR_POINT='Point'):
    """
    寫入geotiff。默認pixel is point,默認WGS84
    """
    rows, columns = data.shape
    bands = 1
    pixel_width = step
    pixel_height = -step
    half_step = step / 2
    upper_left_x = upper_left_lon - half_step
    upper_left_y = upper_left_lat + half_step
    driver = gdal.GetDriverByName('GTiff')
    dataset = driver.Create(tiff_path, columns, rows, bands, gdal.GDT_Float32)
    dataset.SetMetadataItem('AREA_OR_POINT', AREA_OR_POINT)
    dataset.SetGeoTransform([upper_left_x, pixel_width, 0,
                             upper_left_y, 0, pixel_height])
    # 獲取地理坐標係統信息,用於選取需要的地理坐標係統
    sr = osr.SpatialReference()
    sr.SetWellKnownGeogCS('WGS84')
    dataset.SetProjection(sr.ExportToWkt())  # 給新建圖層賦予投影信息
    dataset.GetRasterBand(1).WriteArray(data)
    dataset.FlushCache()  # 將數據寫入硬盤
    dataset = None 
開發者ID:Mo-Dabao,項目名稱:pyMeteo,代碼行數:25,代碼來源:tools.py

示例9: createRaster

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def createRaster(self, srcraster, destfile, pixelType):
        '''
        Creates a raster file
        srcraster: source raster
        destfile: destination file
        pixelType: raster pixel type (e.g byte)
        '''
        cols = srcraster.RasterXSize
        rows = srcraster.RasterYSize

        (xOrigin, yOrigin, pixelWidth, pixelHeight) = self.getGeoreferenceInfo(srcraster)

        targetSR = self.getCRS(srcraster)

        driver = gdal.GetDriverByName('GTiff')

        outRaster = driver.Create(destfile, cols, rows, 3, pixelType)
        outRaster.SetGeoTransform((xOrigin, pixelWidth, 0, yOrigin, 0, pixelHeight))
        outRaster.SetProjection(targetSR.ExportToWkt())
        
        return outRaster 
開發者ID:dsgoficial,項目名稱:DsgTools,代碼行數:23,代碼來源:raster_processing.py

示例10: createRaster

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def createRaster(self, srcraster, destfile, pixelType):
        """
        Creates a raster file
        srcraster: source raster
        destfile: destination file
        pixelType: raster pixel type (e.g byte)
        """
        cols = srcraster.RasterXSize
        rows = srcraster.RasterYSize

        (xOrigin, yOrigin, pixelWidth, pixelHeight) = self.getGeoreferenceInfo(srcraster)

        targetSR = self.getCRS(srcraster)

        driver = gdal.GetDriverByName('GTiff')

        outRaster = driver.Create(destfile, cols, rows, 3, pixelType)
        outRaster.SetGeoTransform((xOrigin, pixelWidth, 0, yOrigin, 0, pixelHeight))
        outRaster.SetProjection(targetSR.ExportToWkt())
        
        return outRaster 
開發者ID:dsgoficial,項目名稱:DsgTools,代碼行數:23,代碼來源:HSV_fusion.py

示例11: write_data

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def write_data(self, data, fileName, colorTable):
		fileName 	= os.path.join(self.outpath, fileName)
		driver 		= gdal.GetDriverByName( "GTiff" )
		dst_ds 		= driver.Create( fileName, self.RasterXSize, self.RasterYSize, 1, gdal.GDT_Byte, [ 'COMPRESS=DEFLATE' ] )
		band 		= dst_ds.GetRasterBand(1)

		if self.geotransform:
			dst_ds.SetGeoTransform( self.geotransform )
			
		if self.projection:
			dst_ds.SetProjection( self.projection )

		if colorTable:
			print "Add colortable"
			band.SetRasterColorTable(self.ct)

		band.WriteArray(data, 0, 0)
			
		if verbose:
			print "Written", fileName

		ds 		= None 
開發者ID:vightel,項目名稱:FloodMapsWorkshop,代碼行數:24,代碼來源:landsat8_composite_toa.py

示例12: main

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def main():
    args = parse_arguments()
    src_ds = gdal.Open(args.src_file[0])

    driver = gdal.GetDriverByName("GTiff")

    dst_ds = driver.CreateCopy(args.out_file[0], src_ds, 0)

    point = ogr.Geometry(ogr.wkbPoint)
    point.AddPoint(float(args.position[0]), float(args.position[1]))
    point.Transform(transform)

    gt = [point.GetX(), float(args.pixelsize[0]), 0,
          point.GetY(), 0, -float(args.pixelsize[1])]

    dst_ds.SetGeoTransform(gt)

    to_sys = osr.SpatialReference()
    to_sys.ImportFromEPSG(to_srs)

    dest_wkt = to_sys.ExportToWkt()

    dst_ds.SetProjection(dest_wkt) 
開發者ID:LarsSchy,項目名稱:SMAC-M,代碼行數:25,代碼來源:georeference_tif.py

示例13: toGDAL

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def toGDAL(self):
		'''Get GDAL memory driver dataset'''
		w, h = self.size
		n = self.nbBands
		dtype = str(self.dtype)
		if dtype == 'uint8': dtype = 'byte'
		dtype = gdal.GetDataTypeByName(dtype)
		mem = gdal.GetDriverByName('MEM').Create('', w, h, n, dtype)
		#writearray is available only at band level
		if self.isOneBand:
			mem.GetRasterBand(1).WriteArray(self.data)
		else:
			for bandIdx in range(n):
				bandArray = self.data[:,:,bandIdx]
				mem.GetRasterBand(bandIdx+1).WriteArray(bandArray)
		#write georef
		if self.isGeoref:
			mem.SetGeoTransform(self.georef.toGDAL())
			if self.georef.crs is not None:
				mem.SetProjection(self.georef.crs.getOgrSpatialRef().ExportToWkt())
		return mem 
開發者ID:domlysz,項目名稱:BlenderGIS,代碼行數:23,代碼來源:npimg.py

示例14: fillNodata

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def fillNodata(self):
		#if not self.noData in self.data:
		if not np.ma.is_masked(self.data):
			#do not process it if its not necessary
			return
		if self.IFACE == 'GDAL':
			# gdal.FillNodata need a band object to apply on
			# so we create a memory datasource (1 band, float)
			height, width = self.data.shape
			ds = gdal.GetDriverByName('MEM').Create('', width, height, 1, gdal.GetDataTypeByName('float32'))
			b = ds.GetRasterBand(1)
			b.SetNoDataValue(self.noData)
			self.data =  np.ma.filled(self.data, self.noData)# Fill mask with nodata value
			b.WriteArray(self.data)
			gdal.FillNodata(targetBand=b, maskBand=None, maxSearchDist=max(self.size.xy), smoothingIterations=0)
			self.data = b.ReadAsArray()
			ds, b = None, None
		else: #Call the inpainting function
			# Cast to float
			self.cast2float()
			# Fill mask with NaN (warning NaN is a special value for float arrays only)
			self.data =  np.ma.filled(self.data, np.NaN)
			# Inpainting
			self.data = replace_nans(self.data, max_iter=5, tolerance=0.5, kernel_size=2, method='localmean') 
開發者ID:domlysz,項目名稱:BlenderGIS,代碼行數:26,代碼來源:npimg.py

示例15: create_ds

# 需要導入模塊: from osgeo import gdal [as 別名]
# 或者: from osgeo.gdal import GetDriverByName [as 別名]
def create_ds(file_name, xsize, ysize, band_count, compress=True):
    options = ['PHOTOMETRIC=RGB']
    if compress:
        options.append('COMPRESS=DEFLATE')
        options.append('PREDICTOR=2')

    datatype = gdal.GDT_UInt16
    gdal_ds = gdal.GetDriverByName('GTIFF').Create(
        file_name, xsize, ysize, band_count, datatype,
        options=options)
    return gdal_ds 
開發者ID:planetlabs,項目名稱:radiometric_normalization,代碼行數:13,代碼來源:gimage.py


注:本文中的osgeo.gdal.GetDriverByName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。