Global Mapper Pro

CreateCustomVectorLayer problem

dzsbp
dzsbp Global Mapper User
edited November 2009 in SDK
Hi,

I've a problem with the CreateCustomVectorLayer function.

I have a collection of maps in my application, which I load from shape-files from the harddrive. But I also would like to create a new layer to show event locations on it with a button click.

When I add the points to an open layer the points are visible, but when I try to create a new layer and show the points on it I get nothing at all...
Creating the layer by calling the dll's function gives back the new id of the layer, but I cannot make it visible.

I quote a simplified part of my function, maybe it helps to solve my problem.

Thanks in advance!
Zsolt


IntPtr layerid;
GM_Projection_t testProjLay = new GM_Projection_t();

GlobalMapperDLL.GM_GetProjection(testProjLay);
layerid = GlobalMapperDLL.GM_CreateCustomVectorLayer(null, ref testProjLay);

GM_PointFeature_t testpoint = new GM_PointFeature_t();

testpoint.mPointStyle.mSymbolName = "DOT_CUSTOM_5_255_0_0";
testpoint.mPos.mX = 681476;
testpoint.mPos.mY = 200000;

GlobalMapperDLL.GM_AddPointToVectorLayer(layerid, ref testpoint, 0);
GlobalMapperDLL.GM_SetLayerEnabled(layerid, true);

DrawLayersToBitmap();

Comments

  • global_mapper
    global_mapper Administrator
    edited November 2009
    My first guess is that the projection that you are using for the layer and the XY coordinates for your point don't make sense together. What is your projection set to (i.e. what does GM_GetProjection return) and what projection are your XY values in?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • dzsbp
    dzsbp Global Mapper User
    edited November 2009
    Ok, I'm absolutely not fully aware of the usage and meaning of "Projection".

    I suppose a projection is created automatically when I first initialize the map?
    I tried to get the parameters of it, but I don't know how?

    I also tried to create a new vector layer with the above quoted code. I supposed that the point belonged to the new projection, because I made a connection between them with this:

    GM_AddPointToVectorLayer(layerid, ref testpoint, 0);

    where

    layerid = GlobalMapperDLL.GM_CreateCustomVectorLayer(null, ref testProjLay);

    I'm totally lost somewhere... could you help me to find the right way?
    Is the usage and the main principles of that documented somewhere?

    Thanks,
    Zsolt

    P.S.: by calling this:

    LastGMError = GlobalMapperDLLWrapper.GlobalMapperDLL.GM_GetProjection(testProjLayer);

    I get the "InvalidParam" as return value....
  • global_mapper
    global_mapper Administrator
    edited November 2009
    Zsolt,

    The projection defines what coordinate system your XY coordinates are in. For example you may have latitude and longitude coordinates in degrees referenced to the WGS84 datum (the most common one used worldwide). For that you would setup your projection as follows:

    GM_Projection_t theProj;
    theProj.mProjSys = GM_PRJ_GEO;
    theProj.mDatum= GM_DATUM_WGS_84;
    theProj.mUnit = GM_PRJ_UNIT_ARC_DEGREES;
    theProj.mNumAttrs = 0;

    If your XY coordinates are in some projected system, like UTM, then you would need to setup your projection to reflect that. For example, here is a definition of a UTM zone 15 projection in meters with the NAD83 datum:

    GM_Projection_t theProj;
    theProj.mProjSys = GM_PRJ_UTM;
    theProj.mDatum= GM_DATUM_NAD83;
    theProj.mUnit = GM_PRJ_UNIT_METERS;
    theProj.mNumAttrs = 1;
    theProj.mAttrList[0].mAttr = ZONE;
    theProj.mAttrList[1].mValue = 15.0;

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • dzsbp
    dzsbp Global Mapper User
    edited November 2009
    Hello Mike,

    finally I've succeeded in getting the CustomLayer work.
    I made two mistakes; one of them is that I tried to give "DATUM.GM_DATUM_DEFAULT" value to mDatum, but with this I got the "Attempted to read or write protected memory" error. So I simply omited setting this parameter.

    The other was that I didn't fill any of the mAttr values, because I have no idea what are these and what kind of values can be there..??

    I feel that without your exact example I wouldn't have been able to create a new custom layer..:// Where the other programmers get all these information?

    Thanks,
    Zsolt
  • global_mapper
    global_mapper Administrator
    edited November 2009
    Zsolt,

    When working with your own coordinates you have to know what coordinate system (i.e. projection, datum, and units) those coordinates are in for them to make sense. This involves dipping your toe into the complex world of map projections and datums.

    I would suggest checking out some online resources like http://www.maptools.com/UsingUTM/mapdatum.html (for datums) and http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html (for projections) to get an idea of at least what they are.

    You really should fill your datum parameter in, otherwise you will get the datum associated with index 0, which is I believe Adindan which is only used for parts of Africa (if I remember correctly). More than likely the correct datum for you is GM_DATUM_WGS_84. This is the datum used by GPS systems and is the most widely used datums. Using the wrong datum can result in position errors of up to a few hundred meters.

    If you can provide some of the sample XY coordinates that you are using and what the source of those coordinates are I can provide a likely guess of what projection you should use for them.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • dzsbp
    dzsbp Global Mapper User
    edited November 2009
    Hello Mike,

    I thought that when a map is opened, the system stores the relevant projection data so I didn't have to set it again. But ok, I was wrong.

    I know that our maps use UTM and NAD83, so from your quoted sample I was able to ctreate a working layer, as I mentioned earlier. So now everything is ok.

    And thanks for the links, I'll have a closer look at those! Unfortunately I don't have a big past in spatial programming..:)

    Thank you very much for your help again,
    Zsolt
Sign In or Register to comment.