GM_LoadLayer flag problem

golfmonkegolfmonke Global Mapper UserPosts: 13
edited October 2008 in SDK
Hello,

I am trying to load a JPEG with world file from TerraServer (because I found out that pocket pc doesn't like Tif, tifs are huge anyway).

The code i'm using is below.

When I don't set any Loadlayer flags, I can successfully load the layer and call the method to convert from pixel coordinates to lat/long coordinates.

However, when I try to suppress the projection window from displaying, by using the GlobalMapperDLL.GM_LoadFlags_t32.GM_LoadFlags_NoProjPrompt
I then get a null pointer while calling Info = (GM_LayerInfo_t)Marshal.PtrToStructure(InfoPtr, typeof(GM_LayerInfo_t));

because InfoPtr is null.

Is this a bug or am I doing something wrong?

BTW, I also noticed that unless I draw the Image, then I can't get any information for the layer or update with new projection, I assume this is the way the API works right?

Also.... sorry for the long list here :)

When I call the convert x,y to ground coordinate my 0,0 values are off from the Terraserver image file data.

Now , the Terraserver image data file says "x-coordinate of the CENTER of the upper left pixel (the Easting UTM" and "y-coordinate of the CENTER of the upper left pixel (the northing UTM"

I'm hoping that the Global mapper SDK is adjusting for this and that is why my values are slightly off?

Thanks,
Mike

string path = @C:\Projects\gpshdcp\courses\CT\RidgeField\RidgeFieldGolfCourse\Hole1\TerraServerImageRidgefieldHole1\;
            string fileToLoad = path + "Hole1.jpg";

            Image image = new Bitmap(fileToLoad);

            GM_Projection_t projection = new GM_Projection_t();
            projection.Datum = DATUM.GM_DATUM_WGS_84;
            projection.ProjSys = PROJSYS.GM_PRJ_UTM;
            projection.Unit = UNIT.GM_PRJ_UNIT_METERS;
            projection.Attr1.mAttr = PROJATTR.ZONE;
            projection.Attr1.mValue = 18;
            projection.NumAttrs = 1;
           // projection.Attr1 = 
            //how to set zone 18

            GlobalMapperDLL.GM_SetProjection(ref projection);

            IntPtr layerReference;
            GlobalMapperDLL.GM_LoadLayer(fileToLoad, out layerReference, GlobalMapperDLL.GM_LoadFlags_t32.GM_LoadFlags_NoProjPrompt);
           // GlobalMapperDLL.GM_LoadLayer(fileToLoad, out layerReference, 0);

           GM_LayerInfo_t Info = new GM_LayerInfo_t();

            IntPtr InfoPtr = GlobalMapperDLL.GM_GetLayerInfo(layerReference);

            IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(Info));  //MIKE: this is not needed ???

             

            //If I don't draw the layer, then I can't get coordinate info
           Info = drawImage(image.Height, image.Width, Info);


           GM_Projection_t gpsProjection = new GM_Projection_t();
           gpsProjection.Datum = DATUM.GM_DATUM_WGS_84;
           gpsProjection.ProjSys = PROJSYS.GM_PRJ_GEO;
           gpsProjection.Unit = UNIT.GM_PRJ_UNIT_ARC_DEGREES;
         

           GlobalMapperDLL.GM_SetProjection(ref gpsProjection);
           GM_LayerInfo_t Info2 = new GM_LayerInfo_t();
           IntPtr InfoPtr2 = GlobalMapperDLL.GM_GetLayerInfo(layerReference);

           IntPtr buffer2 = Marshal.AllocCoTaskMem(Marshal.SizeOf(Info2));  //MIKE: this is not needed ???

           Info2 = (GM_LayerInfo_t)Marshal.PtrToStructure(InfoPtr2, typeof(GM_LayerInfo_t));

           Info2 = drawImage(image.Height, image.Width, Info2);
           

            double latLongXdouble;
            double latLongYdouble;
            convertPixelToGround(0,0,out latLongXdouble, out latLongYdouble);


Mike

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited October 2008
    Mike,

    If you pass in the NoProjPrompt flag and the SDK cannot automatically determine a projection for the layer, then the load will fail. You should check the return values of the function calls to get the reason for the failure.

    Since you know the projection ahead of time, I would suggest calling GM_LoadRectifiedLayer and provide the projection for the layer at load time (just pass NULL for the control point list). Another option if you would prefer to use GM_LoadLayerList is to call GM_SetQueryProjectionCallback to set a function to be called when a projection is needed for a file rather than prompting the user.

    I think this will solve all of your problems, and yes, the SDK does treat world file coordinates as you listed.

    You might also be interested that you can load directly from TerraServer-USA with the SDK via the GM_LoadTerraserver function.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • golfmonkegolfmonke Global Mapper User Posts: 13
    edited October 2008
    Hi,

    I'm not expecting the SDK to know the proper projection, I am setting the proper projection before I call GM_LoadLayer in both cases.

    When I do this without the flag then the popup window shows the correct values that I set in the projection. When I do it with the flag, then I get the Nullpointer

    I'll try the GMLoadRectifiedLayer, but shouldn't passing in the correct projection before calling GMLoadLayer work? Or are you saying that if I set the flag, then GMLoadLayer ignores the projection that I set before the call?

    Btw, I noticed that GMLoadTerraServer function, but is that legal? Or do you guys have a special agreement with them where your customers don't have to pay for image use?

    Mike
  • golfmonkegolfmonke Global Mapper User Posts: 13
    edited October 2008
    Hi Mike

    Alright, I tried the GM_LoadRectifiedLayer and it works. I called it without the flag and it didn't prompt the user, so this leads me to my next question...

    Are there benefits/drawbacks to using GM_LoadRectifiedLayer vs GM_LoadLayerList with the function callback? and vice versa? (other than the convenience of not needing to maintain my own list of layer handles?)

    Thanks a lot!
    Mike
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited October 2008
    Mike,

    Calling GM_SetProjection just sets the projection that your data is viewed/exported in. It has nothing to do with the native projection for a layer on load (except for changing the default projection that a user is prompted with). There is a GM_LoadFlags_UseDefaultProj flag that you can pass to just make the default projection always be accepted, but I would suggest using the more straight-forward GM_LoadRectifiedLayer. It does not have any drawbacks over GM_LoadLayerList other than not being able to load files that contain multiple data files (like some .zip or .tar.gz archives).

    The Terraserver-USA data is free for all to use (it is copyright-free USGS data), so there are no legal issues accessing it from your application.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
Sign In or Register to comment.