Global Mapper SDK
GM_CreateCustomRasterLayer
Creates a new custom layer that represents an in-memory raster. The handle to the newly created layer is returned. You must call GM_CloseLayer on the returned handle when you are done with it. If a problem occurs, NULL is returned for the layer handle.
The layer handle returned can be used just like any other layer handle.
Syntax
C++
Copy
GM_LayerHandle_t32 __stdcall GM_CreateCustomRasterLayer
(
const char* aDescription, // IN: Description to use for layer (can be NULL to use default)
const GM_Projection_t* aProj, // IN: Native projection of new layer
const GM_RasterLayout_t* aRasterLayout, // IN: Raster layer layout
const void* aDataBuf // IN: Grid of raster data values in row-major order
)
EXAMPLE : - Create a Square 24-bit RGB Raster Layer
Copy
// Setup raster layout
const sint32 thePixWidth = 128;
const sint32 thePixHeight = 128;
GM_RasterLayout_t theLayout;
memset( &theLayout, 0, sizeof theLayout );
theLayout.mFlags = GM_RasterLayout_CopyData; // copy data buffer so we can free ours
theLayout.mTopLeft.mX = -90.0; // place it in the US somewhere
theLayout.mTopLeft.mY = 35.0;
theLayout.mXPixelSize = 1.0 / 3600.0; // one arc second in size
theLayout.mYPixelSize = 1.0 / 3600.0; // one arc second in size
theLayout.mPixelWidth = thePixWidth;
theLayout.mPixelHeight = thePixHeight;
theLayout.mNumBands = 3;
theLayout.mBitsPerBand = 8;
// Setup projection as lat/lon
GM_Projection_t theGeoProj;
memset( &theGeoProj, 0, sizeof theGeoProj );
theGeoProj.mProjSys = GM_PRJ_GEO;
theGeoProj.mDatum = GM_DATUM_WGS_84;
theGeoProj.mUnit = GM_PRJ_UNIT_ARC_DEGREES;
// Allocate color buffer
uint8* theColorBuf = (uint8*)malloc( ( theLayout.mPixelWidth * theLayout.mPixelHeight * theLayout.mNumBands * theLayout.mBitsPerBand + 7 ) / 8 );
if ( NULL == theColorBuf )
{
// Out of memory
return;
}
// Fill in the color buffer. We'll just generate some basic colors
uint8* theCurColorPos = theColorBuf;
for ( sint32 i = 0; i < theLayout.mPixelHeight; i++ )
{
for ( sint32 j = 0; j < theLayout.mPixelWidth; j++ )
{
*theCurColorPos++ = i % 256; // set red
*theCurColorPos++ = ( i + j ) % 256; // set green
*theCurColorPos++ = j % 256; // set blue
}
}
// Create custom raster layer
GM_LayerHandle_t32 theRasterLayer = GM_CreateCustomRasterLayer
(
"My Custom Raster Layer", &theGeoProj, &theLayout, theColorBuf
);
// Free the color buffer
free( theColorBuf );