[gdal-dev] Help with GDAL & Visual Studio 2010 & netCDF

James Sulzman sulzman at casco.net
Mon Aug 15 15:09:19 EDT 2011


Hi All,

 

I could use a little help, and it would be greatly appreciated.

 

Goal:  Write a c++ program in MS Visual Studio 2010 (on win7 x64 machine)
that reads in a netCDF file.  Compile/build program in Visual Studio 2010
Release or Debug x64.  Execute the program.

The netCDF file I am trying to read in, has one variable in it.  That
variable is a 3d raster 76x40x93 of float32 type.

 

Steps I have taken:

1.       Download binaries from
http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1600-x64-gdal-
1-8-mapserver-6-0.zip

2.       Create .lib files from .dll(s)

3.       Follow instruction from download binary site, paths/linkers to
library and gdalplugins etc..

4.       Use code from API tutorial for c++
http://www.gdal.org/gdal_tutorial.html, also pasted below

5.       Compile the program (everything compiles fine).

6.       Run the program, does not bomb, but offers bad results.

7.       If you look at the c++ code tutorial in step 4 it has various print
statements. Here are the results from those print statements

 

Driver: netCDF/Network Common Data Format

Size is 76x40x93

Projection is ' '

Block=76x1 Type=Float32, ColorInterp=Undefinded

Min=72.905d Max 115.625d

Data=100.216d

 

Problem:

 

When I get a "band" and get the block size, the block size  is reported as
76x1 (as in the snips below).  I expected the block size to be 76x40

 

poBand = poDataset->GetRasterBand( 1 );

poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );

 

When I read the block (putting the snip below in a nested loop for column
and row) I get the proper data in that 76x1 (76 values) block, but I can't
move onto the next row (ie row > 0). Which makes sense because the block is
only 76x1.  Also, if I get band "2" the same thing, good data, but only one
column to work with.  What am I missing?  How do I retrieve the full band of
76x40?  I even tried a JPEG file and got similar results? 

 

 

poBand->RasterIO( GF_Read, column, row, nXSize, 1, 

                          pafScanline, nXSize, 1, GDT_Float32, 

                          0, 0 );

 

 

Thanks in advance for any help or advice,

 

James

 

 

My program

 

 

typedef __int64 _OFF_T;

#include "gdal.h"

#include "gdal_priv.h"

#include "netcdf.h"

#include "gdal_frmts.h"

#include "netcdfdataset.h"

#include "cpl_config.h"

#include "cpl_conv.h"

#include "cpl_error.h"

#include "cpl_hash_set.h"

#include "cpl_port.h"

#include "cpl_string.h"

#include "cpl_vsi.h"

#include "cpl_minixml.h"

#include "gdal_pam.h"

#include "gdal_version.h"

#include "gdal_vrt.h"

#include "ogr_core.h"

#include "ogr_spatialref.h"

#include "ogr_srs_api.h"

 

#include <iostream>

using namespace std;

//const char *pszFilename = "\\IMG_3527.jpg";

//const char *pszFilename = "\\hada2eugsi.nc";

const char *pszFilename = "\\james_test.nc";

 

//const char *pszFilename = "\\CRUTEM3.nc";

const char *netcdfmeta ("");

char ** ppinfo;

int * pncid; 

int main()

{

        

              

    GDALAllRegister();

       

       

       

       GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "VRT" );

       

       poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );

    

       

 

       GDALGetMetadata(poDataset,netcdfmeta);

       

       //poDataset->GetPamInfo();

       poDataset->GetMetadata(netcdfmeta);

       GDALOpenInfo(pszFilename, GA_ReadOnly ,ppinfo);

       //GDALGetGeoTransform( GDALDatasetH, double * );

       

       if( poDataset == NULL )

    {

       printf( "did not open file");

    }

       double        adfGeoTransform[6];

 

    printf( "Driver: %s/%s\n",

            poDataset->GetDriver()->GetDescription(), 

            poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );

 

    printf( "Size is %dx%dx%d\n", 

            poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),

            poDataset->GetRasterCount() );

 

    if( poDataset->GetProjectionRef()  != NULL )

        printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );

 

    if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )

    {

        printf( "Origin = (%.6f,%.6f)\n",

                adfGeoTransform[0], adfGeoTransform[3] );

 

        printf( "Pixel Size = (%.6f,%.6f)\n",

                adfGeoTransform[1], adfGeoTransform[5] );

    }

       GDALRasterBand  *poBand;

        int             nBlockXSize, nBlockYSize;

        int             bGotMin, bGotMax;

        double          adfMinMax[2];

        

        poBand = poDataset->GetRasterBand( 1 );

        

              

              poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );

        printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",

                nBlockXSize, nBlockYSize,

                GDALGetDataTypeName(poBand->GetRasterDataType()),

                GDALGetColorInterpretationName(

                    poBand->GetColorInterpretation()) );

 

        adfMinMax[0] = poBand->GetMinimum( &bGotMin );

        adfMinMax[1] = poBand->GetMaximum( &bGotMax );

        if( ! (bGotMin && bGotMax) )

            GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE,
adfMinMax);

 

        printf( "Min=%.3fd, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );

        

        if( poBand->GetOverviewCount() > 0 )

            printf( "Band has %d overviews.\n", poBand->GetOverviewCount()
);

 

        if( poBand->GetColorTable() != NULL )

            printf( "Band has a color table with %d entries.\n", 

                     poBand->GetColorTable()->GetColorEntryCount() );

              float *pafScanline;

        int   nXSize = poBand->GetXSize();

 

        pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize);

        poBand->RasterIO( GF_Read, 0, 0, nXSize, 1, 

                          pafScanline, nXSize, 1, GDT_Float32, 

                          0, 0 );

              printf( "data=%.3fd", *pafScanline );

              

              GDALClose(poDataset);

}

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110815/b4fe8225/attachment-0001.html


More information about the gdal-dev mailing list