[gdal-dev] gdalwarp rather than gdal_translate

Diana Esch-Mosher desch-mosher at lanl.gov
Fri Feb 15 13:24:33 EST 2008


Frank,

So I have I done something incorrectly?

                    ds=gdal.Open(image) # image is a BIG nitf
                    band=ds.GetRasterBand(1)
                    sizeX= ds.RasterXSize
                    sizeY= ds.RasterYSize
                    driver=gdal.GetDriverByName('GTiff')
                    sizeXNew = int(math.ceil(factor*sizeX))
                    sizeYNew = int(math.ceil(factor*sizeY))
                    resampledFile=driver.Create(outFilename, sizeXNew, 
sizeYNew, bands=1, datatype=band.DataType)
                    resampledFile.SetProjection(ds.GetProjection())
                    resampledFile.SetGeoTransform(ds.GetGeoTransform())
                    resampledFile.SetMetadata(ds.GetMetadata())
                    cmd = string.join(["gdalwarp -rc" ,image,outFilename])
                    p = subprocess.Popen(cmd, 
shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                    (stdout, stderr) = p.communicate(input=None)


Diana Esch-Mosher wrote:
> Frank,
>
> Well, this isn't quite doing what I thought. It is no longer 
> transforming the file (yeah!)  but is not resampling to the new size. 
> If I give it a new size, say slightly smaller (I'm trying to resample 
> to a common GSD), then it just crops the image to the new smaller 
> size, rather than downsizing. FYI, I'm using 1.3.2.0 ..... is that a 
> problem? Same goes for making a larger image, it is not resampling to 
> a larger size, and additionally it is washing it out.
>
> Thanks,
>
> Diana
>
> Frank Warmerdam wrote:
>> Diana Esch-Mosher wrote:
>>> I looked at gdalwarp and I see where it checks to see if the 
>>> destination file exists, if so then it reads the TargetSRS from that 
>>> dataset. So I should pre-create to the target size that I am 
>>> requesting in gdalwarp? I have no problem in python  pre-creating 
>>> the file, copying the metadata, geotransform, and projection data 
>>> ... anything else I should copy? Then I just call gdalwarp as 
>>> gdalwarp -rcs -ts x y -of  NITF (or any other -of  I want).
>>
>> Diana,
>>
>> Right, except of course you don't specify parameters used to create the
>> file (like -of or -ts).
>>
>> Best regards,
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev




More information about the gdal-dev mailing list