Global Mapper v25.0

how to draw an area feature with a hole in it?

JerryLia
JerryLia Global Mapper User
edited August 2008 in SDK
Mike,

I can create an area feature,but cannot create the one with a polygon hole in it! Could you help me for this?:)

Thanks

Jerry

Comments

  • global_mapper
    global_mapper Administrator
    edited August 2008
    Jerry,

    The mHoleList and mNumHoles values in the GM_AreaFeature_t structure control the creation of holes within a polygon. Just set those up to create holes in a polygon.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • JerryLia
    JerryLia Global Mapper User
    edited August 2008
    Mike,

    Does the mPointList parameter contain the points of mHoleList parameter,or they should be different GM_Point_t arrays? For example:

    //both the polygon and hole have four vertices.
    GM_Point_t[]=new GM_Point_t[10] {Point0,point1,...,point9} ;

    I use it as followed:

    IntPtr ptrPointList,ptrHoleList;
    fixed (GM_Point_t* pointList = &lt_Point[0])
    {
    ptrPoint = (IntPtr) pointList ;//get the address of array
    }

    fixed (GM_Point_t* holePointList = &lt_Point[5])
    {
    ptrHoleList= (IntPtr) holePointList ;//get the address of array
    }

    GM_AreaFeature_t lt_Customize = new GM_AreaFeature_t();
    lt_Customize.mFeatureInfo = lt_VectorFeature;
    lt_Customize.mPointList = ptrPointList;
    lt_Customize.mNumPoints = 10;
    lt_Customize.mHoleList = ptrHoleList;
    lt_Customize.mNumHoles = 1;

    This method does not work at all.If i do not give the mHoleList parameter value and just mNumHoles = 1,program can work but the result is wrong!

    Wrong result:
    attachment.php?attachmentid=110&stc=1&d=1220065725

    Should be:
    attachment.php?attachmentid=111&stc=1&d=1220065784

    What is wrong with me?

    Jerry
  • global_mapper
    global_mapper Administrator
    edited August 2008
    Jerry,

    The hole list is a pointer to an array of GM_HoleInArea_t structures, which are defined as follows:

    typedef struct
    {
    GM_Point_t* mPoints; // List of points in the hole in global coordinates
    uint32 mNumPoints; // Number of points in the list
    } GM_HoleInArea_t;


    You are just passing in the point array and not an array of this structure type. With this structure you pass in the point list and point count for each hole that you need.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • JerryLia
    JerryLia Global Mapper User
    edited August 2008
    Thanks a lot,Mike,
    Following your advice,i have been created a polygon with a hole successfully.But i want to create a polygon with two hole or more,how to do?
    Is it a correct way creating a GM_HoleInArea_t array and assign Points parameter for each hole?

    My English is poor,i give you some code to tell what i want:

    GM_HoleInArea_t [] holeArea=new GM_HoleInArea_t [3];//create a polygon with 3 holes.
    holeArea[0].Points=hole0_Ptr;
    holeArea[0].NumPoints=hole0_PointNumber;

    holeArea[1].Points=hole1_Ptr;
    holeArea[1].NumPoints=hole1_PointNumber;

    holeArea[2].Points=hole2_Ptr;
    holeArea[2].NumPoints=hole2_PointNumber;

    IntPtr ptrHoleStruct;
    fixed (GM_HoleInArea_t* holeInArea_t = &GM_HoleInArea_t[0])
    {
    ptrHoleStruct = (IntPtr)holeInArea_t;
    }

    GM_AreaFeature_t lt_Customize = new GM_AreaFeature_t();
    lt_Customize.mPointList = ptrHoleStruct ;

    Please give me some advice.

    Jerry
  • global_mapper
    global_mapper Administrator
    edited August 2008
    Jerry,

    You look pretty close to me (although is it legal to name your variable for the hole list with the same name as as the type?). I think you just need to set the mNumHoles value to match your whole list array size (i.e. 3) and it looks like it will work.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • JerryLia
    JerryLia Global Mapper User
    edited August 2008
    Mike,
    I have to trouble you again.I do what you tell me and throw three holes points into one GM_Point_t array named pHolePoint,then use it such as.

    IntPtr holePtr;
    fixed (GM_Point_t* point_t1 = &pHolePoint[0])
    {
    holePtr = (IntPtr) point_t1;
    }
    GM_HoleInArea_t gm_HoleInArea_t = new GM_HoleInArea_t();
    gm_HoleInArea_t.Points = holePtr;
    gm_HoleInArea_t.NumPoints = (uint) pHolePoint.Length;
    IntPtr ptrHoleStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(gm_HoleInArea_t));
    Marshal.StructureToPtr(gm_HoleInArea_t, ptrHoleStruct, true);

    GM_AreaFeature_t lt_Customize = new GM_AreaFeature_t();
    .......
    lt_Customize.mHoleList = ptrHoleStruct;
    lt_Customize.mNumHoles = 3;//being fixed for test conveniently .

    When the polyon has only one hole,it works well and faill with more holes!
  • global_mapper
    global_mapper Administrator
    edited August 2008
    You have misunderstood, I did not want you to use a single GM_Point_t array for all of the holes, your previous attempt was closer to what you needed. You need to have a separate GM_Point_t array for each hole. I have provided you previous code from above with one line added at the end that I think will make everything work:

    GM_HoleInArea_t [] holeArea=new GM_HoleInArea_t [3];//create a polygon with 3 holes.
    holeArea[0].Points=hole0_Ptr;
    holeArea[0].NumPoints=hole0_PointNumber;

    holeArea[1].Points=hole1_Ptr;
    holeArea[1].NumPoints=hole1_PointNumber;

    holeArea[2].Points=hole2_Ptr;
    holeArea[2].NumPoints=hole2_PointNumber;

    IntPtr ptrHoleStruct;
    fixed (GM_HoleInArea_t* holeInArea_t = &GM_HoleInArea_t[0])
    {
    ptrHoleStruct = (IntPtr)holeInArea_t;
    }

    GM_AreaFeature_t lt_Customize = new GM_AreaFeature_t();
    lt_Customize.mPointList = ptrHoleStruct ;
    lt_Customize.mNumHoles = 3;

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • JerryLia
    JerryLia Global Mapper User
    edited August 2008
    Mike,
    It is now working well,thanks a lot.
    I had tried this method,maybe i missed some thing.