Trouble creating Raster Layer (GM_RasterLayout_t)
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?
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
-
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 -
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? -
Sorry, I was going from memory. Replace mImageWidth with mPixelWidth and mImageHeight with mPixelHeight.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Worked like a charm. Thanks for the help.
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website