def array2raster(newRasterFilename,rasterOrigin,pixelWidth,pixelHeight,array,dataType):
array=array.astype(float)
cols=array.shape[1]
rows=array.shape[0]
originX=rasterOrigin[0]
originY=rasterOrigin[1]
driver=gdal.GetDriverByName('GTiff')
outRaster = driver.Create(newRasterFilename, cols, rows, 1, dataType)
outRaster.SetGeoTransform((originX, pixelWidth, 0, originY, 0, pixelHeight))
outband = outRaster.GetRasterBand(1)
outband.WriteArray(array)
outRasterSRS = osr.SpatialReference()
outRasterSRS.ImportFromEPSG(4326)#EPSG code for Nepal only
outRaster.SetProjection(outRasterSRS.ExportToWkt())
outband.FlushCache()
#gets the lat/lon extent of a raster
评论列表
文章目录