Global Mapper v25.0

Trouble creating Raster Layer (GM_RasterLayout_t)

John Lee
John Lee Global Mapper User
edited February 2010 in SDK
Hello,

I am trying to create a new Raster Layer with the same dimensions and location of an already loaded Raster Layer. In order to do this, I use GM_GetLayerInfo( ) on the already loaded layer:

GM_RasterLayout_t aRasterLayout;
aRasterLayout.mFlags = 0; // General flags for layout.
aRasterLayout.mTopLeft.mX = mImageLayerInfo->mNativeRect.mMinX; // Ground coordinates of top left sample
aRasterLayout.mTopLeft.mY = mImageLayerInfo->mNativeRect.mMaxY; // Ground coordinates of top left sample
aRasterLayout.mXPixelSize = mImageLayerInfo->mPixelSizeX; // Size of each pixel in the x direction
aRasterLayout.mYPixelSize = mImageLayerInfo->mPixelSizeY; // Size of each pixel in the y direction
aRasterLayout.mPixelWidth = mImageLayerInfo->mPixelWidth; // Number of pixels in the x direction
aRasterLayout.mPixelHeight = mImageLayerInfo->mPixelHeight; // Number of pixels in the y direction
aRasterLayout.mNumBands = 3; // Number of bands of data (usually 1 for grayscale or 3 for RGB)
aRasterLayout.mBitsPerBand = 8; // Number of bits per band of data (usually 8)
aRasterLayout.mBytesPerRow = 0; // Number of bytes per row of data in data buffer. If 0 this will be calculated for you.
aRasterLayout.mPalette = NULL; // Array of colors for palette (set to NULL for no palette)
aRasterLayout.mPaletteSize = 0; // Number of colors in palette
aRasterLayout.mAlphaBandIdx = 0; // 0-based alpha channel band index (usually 0 or 3). Ignored unless GM_RasterLayout_AlphaPresent flag is set.

In the SDK, it claims that GM_LayerInfo::mPixelSizeX and mPixelSizeY are in meters. What is the unit for GM_RasterLayout_t::mXPixelSize and mYPixelSize?

When I create the layer using the above code, the resulting layer is way too large. If I call GM_GetLayerInfo on this newly created layer the mPixelSizeX is 70197.54... (tried to set to 0.6754) and mPixelSizeY is 0.000000 (tried to set to 1.00011...).

Is there an easier way to duplicate and clear a Raster Layer? What units are requested by GM_RasterLayout_t, or is there another problem?

Comments

  • global_mapper
    global_mapper Administrator
    edited February 2010
    The mPixelSizeX and mPixelSizeY in the GM_RasterLayout_t structure are in the units of whatever projection that you pass in to the GM_CreateCustomRasterLayer function. To duplicate an existing layer, use the mNativeProj of the original layer's information. Also rather than using the mPixelSizeX and mPixelSizeY from the original layer's information which are always in meters and maybe not the units of the projection that you are using, instead simply calculate the native pixel dimensions of the original layer as follows:

    double theNativePixSizeX = ( mImageLayerInfo->mNativeRect.mMaxX - mImageLayerInfo->mNativeRect.mMinX ) / mImageLayerInfo->mImageWidth;
    double theNativePixSizeY = ( mImageLayerInfo->mNativeRect.mMaxY - mImageLayerInfo->mNativeRect.mMinY ) / mImageLayerInfo->mImageHeight;

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • John Lee
    John Lee Global Mapper User
    edited February 2010
    I checked my GM_CreateCustomRasterLayer function and I was using the original native projection &(mImageLayerInfo->mNativeProj).

    I thought I'd calculate them as suggested, but was unable to find the mImageLayerInfo->imageWidth or imageHeight. Perhaps I need to update my SDK?
  • global_mapper
    global_mapper Administrator
    edited February 2010
    Sorry, I was going from memory. Replace mImageWidth with mPixelWidth and mImageHeight with mPixelHeight.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • John Lee
    John Lee Global Mapper User
    edited February 2010
    Worked like a charm. Thanks for the help.