WCS from multiple netCDF returning only background image

Norman Barker nbarker at ITTVIS.COM
Fri Mar 30 09:58:20 PDT 2007


Hi Frank, all,

I raised this as a bug report about 18 months or so ago, and put in a proposed fix, and it was put into the main code with a bit of twist, and I noticed that it didn't fix the problem with my data, thinking it was just a problem with my dataset I just continue to patch MapServer.  It might be the same problem you are seeing.

(Must add this isn't a criticism, I am not a c++ programmer, and I could never write anything as fast as mapserver, just trying to help :-) ).

Can you try this in mapresample.c (Fixed msSimpleRasterResample() so that if in raw mode it loops through all the available bands) and see if it works (it is probably horribly inefficient)



/************************************************************************/
/*                       msSimpleRasterResample()                       */
/************************************************************************/

static int 
msSimpleRasterResampler( imageObj *psSrcImage, colorObj offsite,
                         imageObj *psDstImage, int *panCMap,
                         SimpleTransformer pfnTransform, void *pCBData,
                         int debug )

{
    double	*x, *y; 
    int		nDstX, nDstY;
    int         *panSuccess;
    int		nDstXSize = psDstImage->width;
    int		nDstYSize = psDstImage->height;
    int		nSrcXSize = psSrcImage->width;
    int		nSrcYSize = psSrcImage->height;
    int		nFailedPoints = 0, nSetPoints = 0;
    gdImagePtr  srcImg, dstImg;
    
    srcImg = psSrcImage->img.gd;
    dstImg = psDstImage->img.gd;

    x = (double *) malloc( sizeof(double) * nDstXSize );
    y = (double *) malloc( sizeof(double) * nDstXSize );
    panSuccess = (int *) malloc( sizeof(int) * nDstXSize );

    int band;

    for (band =0; band < psSrcImage->format->bands; band++)
    {
        for( nDstY = 0; nDstY < nDstYSize; nDstY++ )
        {
            for( nDstX = 0; nDstX < nDstXSize; nDstX++ )
            {
                x[nDstX] = nDstX + 0.5;
                y[nDstX] = nDstY + 0.5;
            }
    
            pfnTransform( pCBData, nDstXSize, x, y, panSuccess );
            
            for( nDstX = 0; nDstX < nDstXSize; nDstX++ )
            {
                int		nSrcX, nSrcY;
                int		nValue;
    
                if( !panSuccess[nDstX] )
                {
                    nFailedPoints++;
                    continue;
                }
    
                nSrcX = (int) x[nDstX];
                nSrcY = (int) y[nDstX];
    
                /*
                 * We test the original floating point values to 
                 * avoid errors related to asymmetric rounding around zero.
                 */
                if( x[nDstX] < 0.0 || y[nDstX] < 0.0
                    || nSrcX >= nSrcXSize || nSrcY >= nSrcYSize )
                {
                    continue;
                }
    
                if( MS_RENDERER_GD(psSrcImage->format) )
                {
                    if( !gdImageTrueColor(psSrcImage->img.gd) )
                    {
                        nValue = panCMap[srcImg->pixels[nSrcY][nSrcX]];
    
                        if( nValue == -1 )
                            continue;
    
                        nSetPoints++;
                        dstImg->pixels[nDstY][nDstX] = nValue; 
                    }
                    else
                    {
                        int nValue = srcImg->tpixels[nSrcY][nSrcX];
                        int gd_alpha = gdTrueColorGetAlpha(nValue);
    
                        if( gd_alpha == 0 )
                        {
                            nSetPoints++;
                            dstImg->tpixels[nDstY][nDstX] = nValue;
                        }
                        else if( gd_alpha == 127 )
                            /* overlay is transparent, do nothing */;
                        else
                        {
                            nSetPoints++;
                            dstImg->tpixels[nDstY][nDstX] = 
                                gdAlphaBlend( dstImg->tpixels[nDstY][nDstX], 
                                              nValue );
                        }
                    }
                }
                else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
                {
                    if( psSrcImage->format->imagemode == MS_IMAGEMODE_INT16 )
                    {
                        int	nValue;
    
                        nValue = psSrcImage->img.raw_16bit[
                            nSrcX + nSrcY * psSrcImage->width + band*psSrcImage->width*psSrcImage->height];
    
                        if( nValue == offsite.red )
                            continue;
                        
                        nSetPoints++;
                        psDstImage->img.raw_16bit[
                            nDstX + nDstY * psDstImage->width + band*psDstImage->width*psDstImage->height] = nValue;
                    }
                    else if( psSrcImage->format->imagemode == MS_IMAGEMODE_FLOAT32)
                    {
                        float fValue;
    
                        fValue = psSrcImage->img.raw_float[
                            nSrcX + nSrcY * psSrcImage->width + band*psSrcImage->width*psSrcImage->height];
    
                        if( fValue == offsite.red )
                            continue;
                        
                        nSetPoints++;
                        psDstImage->img.raw_float[
                            nDstX + nDstY * psDstImage->width + band*psDstImage->width*psDstImage->height] = fValue;
                    }
                    else if( psSrcImage->format->imagemode == MS_IMAGEMODE_BYTE)
                    {
                        int nValue;
    
                        nValue = psSrcImage->img.raw_byte[
                            nSrcX + nSrcY * psSrcImage->width + band*psSrcImage->width*psSrcImage->height];
    
                        if( nValue == offsite.red )
                            continue;
                        
                        nSetPoints++;
                        psDstImage->img.raw_byte[nDstX + nDstY * psDstImage->width + band*psDstImage->width*psDstImage->height]
                            = (unsigned char) nValue;
                    }
                    else
                    {
                        assert( 0 );
                    }
                }
            }
        }
    }
    free( panSuccess );
    free( x );
    free( y );

/* -------------------------------------------------------------------- */
/*      Some debugging output.                                          */
/* -------------------------------------------------------------------- */
    if( nFailedPoints > 0 && debug )
    {
        char	szMsg[256];
        
        sprintf( szMsg, 
                 "msSimpleRasterResampler: "
                 "%d failed to transform, %d actually set.\n", 
                 nFailedPoints, nSetPoints );
        msDebug( szMsg );
    }

    return 0;
}



-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On Behalf Of Frank Warmerdam
Sent: 29 March 2007 18:17
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] WCS from multiple netCDF returning only background image

Jérôme Martin wrote:
> In fact the resolution pixel X must be the same as the resolution pixel 
> Y, to do not strech on one axe the data.

Ed / Jérôme,

This is not expected behavior and if it persists in MapServer 4.10.1 and/or
CVS-head I'd appreciate a bug report.

One thing that is different when the aspect ratio is non-square is that
MapServer goes through more general resampling code (similar to when
reprojection is taking place), so if there are problems with the
coordinate system definitions on layers or the WCS request things might
fail.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the MapServer-users mailing list