Global Mapper v25.0

GM_LoadRectifiedLayer

Dilys
Dilys Global Mapper UserTrusted User
edited April 2009 in SDK
Hi Mike,

I have a problem of using the GM_LoadRectifiedLayer fuction. I have tried to use it with the following code:

Structure testing
Dim test0 As Double
Dim test1 As Double
Dim test2 As Double
Dim test3 As Double
Dim test4 As Double
Dim test5 As Double
Dim test6 As Double
Dim test7 As Double
Dim test8 As Double
Dim test9 As Double
Dim test10 As Double
Dim test11 As Double
Dim test12 As Double
Dim test13 As Double
Dim test14 As Double
Dim test15 As Double
End Structure

Private sub loadaLayer()

Dim theCurProj As GM_Projection_t
Dim theErr As Int32 = GM_GetProjection(theCurProj)
Dim mPictureFileN As String = "C:\missions\BRIEF\Water lilies.jpg"

Dim mytest As testing
With mytest
.test0 = 89
.test1 = 51
.test2 = 148.14950731
.test3 = -35.29209815

.test4 = 0
.test5 = 500
.test6 = 148.14783818
.test7 = -35.42395892

.test8 = 700
.test9 = 0
.test10 = 148.30139755
.test11 = -35.29710552

.test12 = 700
.test13 = 500
.test14 = 148.30306668
.test15 = -35.42729716
End With

Dim aryPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(mytest))
Marshal.StructureToPtr(mytest, aryPtr, False)

Dim theLayerHandle As Int32

theErr = GM_LoadRectifiedLayer(mPictureFileN, theLayerHandle, GM_LoadFlags_t32.GM_LoadFlags_HideProgress, aryPtr, 4, theCurProj)

aryMapList.Add(theLayerHandle)

Marshal.FreeHGlobal(aryPtr)

end sub


But it does not work! The picture does not come up in the picture box. Could you kindly telling me what wrong with my coding, or what things I miss please?

Thanks!
Dilys

Comments

  • global_mapper
    global_mapper Administrator
    edited April 2009
    Dilys,

    I suppose that method should work. What does your declaration of the GM_LoadRectifiedLayer function look like? Is any error code returned? If you call GM_GetLayerInfo on the layer handle returned what does it look like?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Dilys
    Dilys Global Mapper User Trusted User
    edited April 2009
    Hi Mike,

    The declaration of the GM_LoadRectifiedLayer function is like that:
    Public Declare Ansi Function GM_LoadRectifiedLayer Lib "GlobalMapperInterface" _
    ( _
    ByVal aFilename As String, _
    ByRef aLayer As Int32, _
    ByVal aLoadFlags As GM_LoadFlags_t32, _
    ByVal aGCPList As IntPtr, _
    ByVal aNumGCPs As Int32, _
    ByVal aProj As GM_Projection_t _
    ) As Int32

    And the GM_GroundControlPoint_t is defined as below:
    <StructLayout(LayoutKind.Sequential)> Public Structure GM_GroundControlPoint_t
    Public mPixelX As Double
    Public mPixelY As Double
    Public mGroundX As Double
    Public mGroundY As Double
    End Structure

    There is no error code returned.
    But the function returns some wrong information in the GM_LayerInfo_t.

    I pass theCurProj with the following information:

    theCurProj.mDatum = DATUM.GM_DATUM_WGS_84
    theCurProj.mProjSys = PROJSYS.GM_PRJ_GEO
    theCurProj.mUnit = UNIT.GM_PRJ_UNIT_ARC_DEGREES

    But it returns as below:
    theLayerInfo.mNativeProj.mDatum = DATUM.GM_DATUM_ADINDAN
    theLayerInfo.mNativeProj.mProjSys = PROJSYS.GM_PRJ_GEO
    theLayerInfo.mNativeProj.mUnit = UNIT.GM_PRJ_UNIT_RADIANS

    AND

    theLayerInfo.mGlobalRect.mMaxX = 0.0
    theLayerInfo.mGlobalRect.mMaxY = 0.0
    theLayerInfo.mGlobalRect.mMinX = 0.0
    theLayerInfo.mGlobalRect.mMinY = 0.0

    theLayerInfo.mPixelSizeX = 1110.1156092145072
    theLayerInfo.mPixelSizeY = 0.0

    I have attached a copy of the information in theLayerInfo for your reference.
  • global_mapper
    global_mapper Administrator
    edited April 2009
    You should be passing the projection to GM_LoadRectifiedLayer as ByRef, not ByVal since you want the address of the projection structure passed in and not a copy of the structure, even though it is a const pointer and the data won't be modified. I believe this will fix your problem.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Dilys
    Dilys Global Mapper User Trusted User
    edited April 2009
    Hi Mike,

    It works! Thank you very much! It is my fault! I have not notice that I have put ByVal for it.

    Thanks again!
    Dilys