[gdal-dev] preserving alpha channel data with gdal_transform.py

Jay L. jzl5325 at psu.edu
Mon Jul 25 23:43:14 EDT 2011


What format do you want the alphas channel in after running
gdal_polygonize.py?  I ask because after processing you could open the input
and read just the alpha band (band 4 I assume).  Here is a short script
framework that might get you started.

Something like:
from osgeo import gdal

gdal.open(inpudataset, gdal.GA_ReadOnly)

#Create an output
driverFormat = "GTiff" #Any GDAL supported write format
driver = gdal.GetDriverByName(driverFormat)
outdataset = driver.Create(options.output, dataset.RasterXSize,
dataset.RasterYSize, dataset.RasterCount)
outdataset.SetProjection(dataset.GetProjection())
outdataset.SetGeoTransform(dataset.GetGeoTransform())

inband = gdal.GetRasterBand(4) #Band counts are 1 based.  I am assuming that
your band 4 is alpha.

#Read in the gdal array
input_band = inband.ReadAsArray()
outdataset.GetRasterBand(1).WriteArray(input_band, 0, 0)

Someone with more experience might be able to tell you a method that uses
CreateCopy(), but I think that it isn't possible to selectively copy bands.

Hope that that helps,
Jay

On Mon, Jul 25, 2011 at 8:19 PM, jt2000 <thakkar at nexgenwireless.com> wrote:

> I have a very large raster file with data in the alpha band.  I need to
> vectorize it and associate band 4 data with resulting polygons.
>
> Is there anyway to preserve alpha channel data or get that data associated
> with vectorized file after using gdal_polygonize.py?
>
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/preserving-alpha-channel-data-with-gdal-transform-py-tp6620877p6620877.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110725/811dde16/attachment.html


More information about the gdal-dev mailing list