Opened 17 years ago

Last modified 17 years ago

#1492 closed enhancement (wontfix)

improve gdal_translate()

Reported by: gok@… Owned by: warmerdam
Priority: highest Milestone:
Component: default Version: 1.4.0
Severity: minor Keywords:
Cc: gok@…

Description

To make gdal_translate() "smarter" add code below (started from line 621).
It will allow to use area of interest (AOI) window not exactly inside image area. Now AOI will be clipped to image border and will continue operation.

621: anSrcWin[0] = (int) 
            ((dfULX - adfGeoTransform[0]) / adfGeoTransform[1] + 0.001);
        anSrcWin[1] = (int) 
            ((dfULY - adfGeoTransform[3]) / adfGeoTransform[5] + 0.001);
		
        anSrcWin[2] = (int) ((dfLRX - dfULX) / adfGeoTransform[1] + 0.5);
        anSrcWin[3] = (int) ((dfLRY - dfULY) / adfGeoTransform[5] + 0.5);
		
        if( !bQuiet )
            sprintf( errMsg, 
			"Computed -srcwin %d %d %d %d from projected window.\n",
			anSrcWin[0], 
			anSrcWin[1], 
			anSrcWin[2], 
			anSrcWin[3] );

//todo: make it smarter:		
		if ( anSrcWin[0] < 0 ) {anSrcWin[2] += anSrcWin[0]; anSrcWin[0] = 0;}
		if ( anSrcWin[1] < 0 ) {anSrcWin[3] += anSrcWin[1]; anSrcWin[1] = 0;}
		if ( (anSrcWin[0] + anSrcWin[2]) > nRasterXSize ) {anSrcWin[2] = nRasterXSize - anSrcWin[0];}
		if ( (anSrcWin[1] + anSrcWin[3]) > nRasterYSize ) {anSrcWin[3] = nRasterYSize - anSrcWin[1];}
        
        if( anSrcWin[0] < 0 || anSrcWin[1] < 0 
            || anSrcWin[0] + anSrcWin[2] > nRasterXSize 
            || anSrcWin[1] + anSrcWin[3] > nRasterYSize )
        {

Change History (1)

comment:1 by warmerdam, 17 years ago

Gok,

I am concerned that adjusting the window is dangerous and people may not 
realize what is happening.  I would prefer to take the approach of 
allowing specification of a larger than original window by appropriate setup of 
a larger than original virtual file.  But that will require more complex
changes to the code. 

Thanks for the proposed patch anyways, and I imagine it will work well for
your needs.
Note: See TracTickets for help on using tickets.