Draw a line and calculate its length?

usama khanusama khan Global Mapper UserPosts: 19Trusted User
edited May 2014 in SDK
gm.PNG

can someone help me out. i want four things in my application.
1. Import an image(Image can already be georeferenced or it might not be Geofrerenced or digitize).
2. rectify or digitize an image( set scale and coordinate system assigning lat long etc)
3.Draw a line
4.Calculate the length and extract the length of the line or area of polygon in my application.

Can someone tell me from where i will start and what events and methods will i include to get all these four requirements of mine. I am using C# and VS2012. I have seen the sample C# but its very breif and confusing. ?
Is license file necessary for these four requirements?

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    The C++ sample application is much more in depth than the C# sample application. The C# sample is mainly to show how to call the SDK from C#, whereas the C++ sample app demonstrates much more of the functionality.

    For either you can use the GM_LoadRectifiedLayer function to load a layer with a list of control points specifying the position so you can set up any kind of transformation. You can use the GM_CalcDistance function to calculate the distance between 2 points in any projection.

    To add a new line to the map use GM_AddLineToVectorLayer. You can use GM_CreateCustomVectorLayer to first create the layer to add the line to if need be. Then just draw the layer with GM_DrawLayerList like any other layer.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Global Mapper
  • usama khanusama khan Global Mapper User Posts: 19Trusted User
    edited April 2014
    Note: i am totally newbie in the SDK field. so dont mind my silly questions

    Problem 1:
    i couldnot find GM_LoadRectifiedLayer function in GlobalMapperDLL.? now what sir??

    Problem 2:
    I couldnot move one step ahead from this. Can u plz push me from the first step. I dont understand how to call the function yet. I am not a big fan of C++. Just guide me through the code so that i can add the functionality of calculating distance.

    Problem 3:
    everytime i write this. they ask me to create a method Stub for GM_CalcDistance in GlobalMapperDLL. So should i create the method stub or not. If i dont create it gives continious error by saying no overload method etc.

    // i have added the aDist variable in the statusBarPanel as well

    private void button1_Click(object sender, EventArgs e)
    {
    GlobalMapperDLL.GM_CalcDistance(out aDist );
    }
    its not working
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    I've attached updated C# files that include the declarations for GM_LoadRectifiedLayer and GM_RepositionLayer (the 2 functions that set control points for a layer for rectification).

    I've also updated the TestAPI function in the Form1.cs file to demonstrate using the GM_CalcDistance function to measure the distance along a line feature. The GM_CalcDistance function takes 6 parameters, 4 for the start and end point, one to specify whether the points are in lat/lon degrees or the current projection, and the last an output parameter containing the calculated distance in meters.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • usama khanusama khan Global Mapper User Posts: 19Trusted User
    edited April 2014
    error.PNG
    Thanks for the sample sir but When i try to run the sample program. It runs peacefully. But when i try to add the layer , it throws a exception
    i tried to find solution, i totally sucks once again. :(

    Attachment not found.

    AccessVoilationException was unhandled !!

    It Highlight This line.

    heLayerInfo = (GlobalMapperDLLWrapper.GM_LayerInfo_t)Marshal.PtrToStructure(theInfoPtr, typeof(GlobalMapperDLLWrapper.GM_LayerInfo_t));
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited April 2014
    Can you edit the definition of the GM_LayerInfo_t structure and comment out the mGroupName variable at the very end? That was just added to the SDK so your build of the DLL won't create it, but the updated C# wrapper has it in there. Once the SDK is released with all of the latest changes that will sync up.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • usama khanusama khan Global Mapper User Posts: 19Trusted User
    edited May 2014
    yes i have commented out. its working fine. no exception but its not calculating distance because i cant call from the TestAPI, Everynone it gives bunch of errors when i want it to add it under the ClickEvent of the button actually i want to show similar functionality in my aplication as in Orginal software. It draws line and then by left clicking it shows the distance in a dialog box.
    how will i do it. I know i am asking silly questions but i can't pretend myself as the best when i am definately a new born C# learner.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited May 2014
    How are you calling it under your click event? You will need to keep track of the first clicked point and the second clicked point to pass into the GM_CalcDistance function. You can use GM_ProjectPointPixelToGround to convert a clicked pixel location to a real-world ground coordinate. So do that for the first click and the second click, then pass the 2 points into the GM_CalcDistance function to calculate the distance.

    You should probably also draw a line between the 2 points by handling the mouse move and refreshing the display to draw a line between the points. That would outside of the scope of the SDK though, that's just normal Windows C# programming stuff.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • usama khanusama khan Global Mapper User Posts: 19Trusted User
    edited May 2014
    I have used the following code to convert pixel points to meter

    public void distance()
    { double earthradius = 3958.75;
    double dlat = ToRadian(endx - startx);
    double dlng = ToRadian(endy - starty);
    double a = Math.Sin(dlat / 2) * Math.Sin(dlat / 2) + Math.Cos(ToRadian(startx)) * Math.Cos(ToRadian(endx)) * Math.Sin(dlng / 2) * Math.Sin(dlng / 2);
    double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); dist = earthradius * c; dist = dist * 1609.00;
    // dist = ((startx - endx) * (startx - endx)) + ((starty - endy) * (starty - endy)) + dist; }nw can u guide me to the right direction. What should i really need to do to calculate distance of the line other than GM_CalcDistance. and if i want to use GM_CalcDistance , cant i use directly without GM_ProjectPointPixelToGround .??? please i am confused. . i dont have that ability of creating lat long coordinates in C# sample.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited May 2014
    You don't need to do all of that math to convert pixel coordinates to real-world ground coordinates as it is a linear relationship between a pixel coordinates and a ground coordinate in the current projection. That may then involve some heavier math to convert to something like lat/lon, but use the SDK functions for that.

    You would use GM_ProjectPointPixelToGround to convert a pixel location on a map rendered with the SDK to the associated ground coordinates in the current projection (as returned by GM_GetProjection and set with GM_SetProjection). You can pass the ground coordinates in to GM_CalcDistance to calculate the distance between 2 ground coordinates.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
Sign In or Register to comment.