Global Mapper Pro

GM_GetProjection

Osei
Osei Global Mapper UserTrusted User
edited April 2008 in Projection Questions
I using the GM SDK 1.24 with .NET (C#).

I am finding it very difficult trying to Marshal the GM_Projection_t structure. I have defined my GM_Projection_t structure as follows

public struct GM_Projection_t
{
public PROJSYS ProjSys; // Projection system
public DATUM Datum; // Horizontal datum
public UNIT Unit; // Ground units
public ulong NumAttrs; // Number of attributes in attribute list

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16, ArraySubType = UnmanagedType.Struct)]
public GM_ProjAttrValue_t[] AttrList; // attribute list.
};


I believe the problem has to do with the AttrList . This is an array and I think the size is not always 16. I was thinking initially that the size is always 16 but only for instance the first 3 array values had been set.

Comments

  • global_mapper
    global_mapper Administrator
    edited March 2008
    The array is always fixed at 16 elements in length. However for some strange reason it seems that it is not possible to declare a fixed-length array in C# (or VB for that matter)that automatically marshals correctly, so we use the following declaration in C# to get this to work:

    // This type is used to fully describe a projection.
    public struct GM_Projection_t
    {
    public PROJSYS mProjSys; // Projection system
    public DATUM mDatum; // Horizontal datum
    public UNIT mUnit; // Ground units
    public UInt32 mNumAttrs; // Number of attributes in attribute list
    public GM_ProjAttrValue_t mAttr1; // Attribute value list items (C# doesn't support fixed length arrays)
    public GM_ProjAttrValue_t mAttr2;
    public GM_ProjAttrValue_t mAttr3;
    public GM_ProjAttrValue_t mAttr4;
    public GM_ProjAttrValue_t mAttr5;
    public GM_ProjAttrValue_t mAttr6;
    public GM_ProjAttrValue_t mAttr7;
    public GM_ProjAttrValue_t mAttr8;
    public GM_ProjAttrValue_t mAttr9;
    public GM_ProjAttrValue_t mAttr10;
    public GM_ProjAttrValue_t mAttr11;
    public GM_ProjAttrValue_t mAttr12;
    public GM_ProjAttrValue_t mAttr13;
    public GM_ProjAttrValue_t mAttr14;
    public GM_ProjAttrValue_t mAttr15;
    public GM_ProjAttrValue_t mAttr16;
    };

    This declaration (as well as updated projection and datum declarations) are included in the C# example for the SDK on the Developers page at GLOBAL MAPPER. You can also update your SDK to v1.26 there if you want.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Osei
    Osei Global Mapper User Trusted User
    edited April 2008
    Hope oneday I become an expert like you.
  • Osei
    Osei Global Mapper User Trusted User
    edited April 2008
    Thanks a lot for your response earlier.

    My code no longer crashes but I have another problem.

    However, if I load a layer that does not have projection information, a dialog comes up which says select projection. I select a projection but whenever I call GM_GetProjection, it returns the default projection. That is
    ProjSys = 0 // GM_PROJ_GEO
    DATUM = 0 //GM_DATUM_ADINDAN = 0,
    UNIT = 0 //GM_PRJ_UNIT_RADIANS = 0,

    How do I solve this problem.

    Looking forward to your response.
  • Osei
    Osei Global Mapper User Trusted User
    edited April 2008
    Thanks a lot for your response earlier.

    My code no longer crashes but I have another problem.

    However, if I load a layer that does not have projection information, a dialog comes up which says select projection. I select a projection but whenever I call GM_GetProjection, it returns the default projection. That is
    ProjSys = 0 // GM_PROJ_GEO
    DATUM = 0 //GM_DATUM_ADINDAN = 0,
    UNIT = 0 //GM_PRJ_UNIT_RADIANS = 0,

    How do I solve this problem.

    Looking forward to your response.
  • Osei
    Osei Global Mapper User Trusted User
    edited April 2008
    Please ignore all last two messages. Problem has been solved amicably.
Sign In or Register to comment.