# Draw a line and calculate its length?

usama khan
Global Mapper UserPosts:

**19**Trusted User
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?

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

17,238For 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

19Trusted UserProblem 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

17,238I'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

19Trusted UserThanks 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));

17,238Thanks,

Mike

Global Mapper Guru

geohelp@bluemarblegeo.com

Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation

19Trusted Userhow 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.

17,238You 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

19Trusted Userpublic 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.

17,238You 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