本文整理汇总了Python中osgeo.gdal.GDT_Int32方法的典型用法代码示例。如果您正苦于以下问题:Python gdal.GDT_Int32方法的具体用法?Python gdal.GDT_Int32怎么用?Python gdal.GDT_Int32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osgeo.gdal
的用法示例。
在下文中一共展示了gdal.GDT_Int32方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNumpyType
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [as 别名]
def getNumpyType(self, pixelType = gdal.GDT_Byte):
"""
Translates the gdal raster type to numpy type
pixelType: gdal raster type
"""
if pixelType == gdal.GDT_Byte:
return numpy.uint8
elif pixelType == gdal.GDT_UInt16:
return numpy.uint16
elif pixelType == gdal.GDT_Int16:
return numpy.int16
elif pixelType == gdal.GDT_UInt32:
return numpy.uint32
elif pixelType == gdal.GDT_Int32:
return numpy.int32
elif pixelType == gdal.GDT_Float32:
return numpy.float32
elif pixelType == gdal.GDT_Float64:
return numpy.float64
示例2: writeRaster
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [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
示例3: getNumpyType
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [as 别名]
def getNumpyType(self, pixelType = gdal.GDT_Byte):
'''
Translates the gdal raster type to numpy type
pixelType: gdal raster type
'''
if pixelType == gdal.GDT_Byte:
return numpy.uint8
elif pixelType == gdal.GDT_UInt16:
return numpy.uint16
elif pixelType == gdal.GDT_Int16:
return numpy.int16
elif pixelType == gdal.GDT_UInt32:
return numpy.uint32
elif pixelType == gdal.GDT_Int32:
return numpy.int32
elif pixelType == gdal.GDT_Float32:
return numpy.float32
elif pixelType == gdal.GDT_Float64:
return numpy.float64
示例4: _str_of_gdt
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [as 别名]
def _str_of_gdt(gdt):
return {
gdal.GDT_Byte: 'GDT_Byte',
gdal.GDT_Int16: 'GDT_Int16',
gdal.GDT_Int32: 'GDT_Int32',
gdal.GDT_UInt16: 'GDT_UInt16',
gdal.GDT_UInt32: 'GDT_UInt32',
gdal.GDT_Float32: 'GDT_Float32',
gdal.GDT_Float64: 'GDT_Float64',
gdal.GDT_CFloat32: 'GDT_CFloat32',
gdal.GDT_CFloat64: 'GDT_CFloat64',
gdal.GDT_CInt16: 'GDT_CInt16',
gdal.GDT_CInt32: 'GDT_CInt32',
}[gdt]
示例5: polygonize
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [as 别名]
def polygonize(img,shp_path):
# mapping between gdal type and ogr field type
type_mapping = {gdal.GDT_Byte: ogr.OFTInteger,
gdal.GDT_UInt16: ogr.OFTInteger,
gdal.GDT_Int16: ogr.OFTInteger,
gdal.GDT_UInt32: ogr.OFTInteger,
gdal.GDT_Int32: ogr.OFTInteger,
gdal.GDT_Float32: ogr.OFTReal,
gdal.GDT_Float64: ogr.OFTReal,
gdal.GDT_CInt16: ogr.OFTInteger,
gdal.GDT_CInt32: ogr.OFTInteger,
gdal.GDT_CFloat32: ogr.OFTReal,
gdal.GDT_CFloat64: ogr.OFTReal}
ds = gdal.Open(img)
prj = ds.GetProjection()
srcband = ds.GetRasterBand(1)
dst_layername = "Shape"
drv = ogr.GetDriverByName("ESRI Shapefile")
dst_ds = drv.CreateDataSource(shp_path)
srs = osr.SpatialReference(wkt=prj)
dst_layer = dst_ds.CreateLayer(dst_layername, srs=srs)
raster_field = ogr.FieldDefn('id', type_mapping[srcband.DataType])
dst_layer.CreateField(raster_field)
gdal.Polygonize(srcband, srcband, dst_layer, 0, [], callback=None)
del img, ds, srcband, dst_ds, dst_layer
# convert images in a selected folder to shapefiles
示例6: polygonize
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [as 别名]
def polygonize(img,shp_path):
# mapping between gdal type and ogr field type
type_mapping = {gdal.GDT_Byte: ogr.OFTInteger,
gdal.GDT_UInt16: ogr.OFTInteger,
gdal.GDT_Int16: ogr.OFTInteger,
gdal.GDT_UInt32: ogr.OFTInteger,
gdal.GDT_Int32: ogr.OFTInteger,
gdal.GDT_Float32: ogr.OFTReal,
gdal.GDT_Float64: ogr.OFTReal,
gdal.GDT_CInt16: ogr.OFTInteger,
gdal.GDT_CInt32: ogr.OFTInteger,
gdal.GDT_CFloat32: ogr.OFTReal,
gdal.GDT_CFloat64: ogr.OFTReal}
ds = gdal.Open(img)
prj = ds.GetProjection()
srcband = ds.GetRasterBand(1)
dst_layername = "Shape"
drv = ogr.GetDriverByName("ESRI Shapefile")
dst_ds = drv.CreateDataSource(shp_path)
srs = osr.SpatialReference(wkt=prj)
dst_layer = dst_ds.CreateLayer(dst_layername, srs=srs)
# raster_field = ogr.FieldDefn('id', type_mapping[srcband.DataType])
raster_field = ogr.FieldDefn('id', type_mapping[gdal.GDT_Int32])
dst_layer.CreateField(raster_field)
gdal.Polygonize(srcband, srcband, dst_layer, 0, [], callback=None)
del img, ds, srcband, dst_ds, dst_layer
# extract sinks from dem
示例7: pts2raster
# 需要导入模块: from osgeo import gdal [as 别名]
# 或者: from osgeo.gdal import GDT_Int32 [as 别名]
def pts2raster(shapefile,RASTER_PATH,cellSize,field_name=False):
from osgeo import gdal, ogr
# Define pixel_size and NoData value of new raster
pixel_size = cellSize
NoData_value = -9999
# Filename of input OGR file
vector_ptsShp_fn = shapefile
# Filename of the raster Tiff that will be created
raster_ptsShp_fn = RASTER_PATH
# Open the data source and read in the extent
source_ds = ogr.Open(vector_ptsShp_fn)
source_layer = source_ds.GetLayer()
x_min, x_max, y_min, y_max = source_layer.GetExtent()
# Create the destination data source
x_res = int((x_max - x_min) / pixel_size)
y_res = int((y_max - y_min) / pixel_size)
target_ds = gdal.GetDriverByName('GTiff').Create(raster_ptsShp_fn, x_res, y_res, 1, gdal.GDT_Int32 )
target_ds.SetGeoTransform((x_min, pixel_size, 0, y_max, 0, -pixel_size))
band = target_ds.GetRasterBand(1)
band.SetNoDataValue(NoData_value)
# Rasterize
# gdal.RasterizeLayer(target_ds, [1], source_layer, burn_values=[0])
# Rasterize
if field_name:
gdal.RasterizeLayer(target_ds,[1], source_layer,options=["ATTRIBUTE={0}".format(field_name)])
# print("write:",field_name)
else:
gdal.RasterizeLayer(target_ds,[1], source_layer,burn_values=[-1])
return gdal.Open(RASTER_PATH).ReadAsArray()
#批量计算