Cant make ProjToPixel to work how to bypss this error?

May 29, 2013 at 3:55 AM
Edited May 29, 2013 at 3:57 AM
Hello dear reader

I am trying to make a tool to calculate the length of a line the user draws on the map but get this error

__Error 1 Overload resolution failed because no accessible 'ProjToPixel' can be called with these arguments:
'Public Function ProjToPixel(env As DotSpatial.Data.Extent) As System.Drawing.Rectangle': Value of type 'Double' cannot be converted to 'DotSpatial.Data.Extent'.
'Public Function ProjToPixel(location As DotSpatial.Topology.Coordinate) As System.Drawing.Point': Value of type 'Double' cannot be converted to 'DotSpatial.Topology.Coordinate'.  D:\C__VISUAL STUDIO\DMC Swing Swung\Form1.vb    1746    30  DMC SWUNG viewer 1.0__
And it happends at this line of code

How do I convert the coordinates in my array to a coordinate for my mapwindow?
 Xstart = myVenster.ProjToPixel(LineaalPuntenLijst(lin).LineaalX)
I make a class of points, where the X and Y of each point is a double...
May 31, 2013 at 9:55 AM
Are you sure you need projtopixel? As far as I know proj refers to the coordinate value in your coordinate system (say UTM-WGS84...) while pixel refers to the pixel in your map visualization area (it refers to system.drawing.point). If the distance you need is in coordinate system you don't need to convert by using projtopixel but from pixeltoproj and pass from say the mouse position on your map to the coordinate of your point in your coordinate system.

I don't understand what your lineaalpuntenlijst(lin).lineaalX rapresents... however you need to create a new coordinate variable

dim coord as new coordinate

assign to the x and y field the value you want

coord.x= your value for x
coord.y= your value for y


then get your point
            Dim point As new System.Drawing.Point

            point = myVenster.ProjToPixel(coord)
I guess "myVenster" is your map

However I think I am missing something from your explanation, since to get a line length I would think to do exactly the opposite, get coord from point in map canvas.

As an example, in my code I get the mouse position coordinate in this way in a mouseclick event sub

Private Sub Map1_Mouseclick(sender As Object, e As MouseEventArgs) Handles Map1.Mouseclick
   Dim coord As Coordinate = Map1.PixelToProj(e.Location) 
...
End sub

"e" contains the pixel in your map canvas at the moment you right click the mouse so to convert it to coordinate you use pixeltoproj function

Hope what I said is not too much messy

Oscar
May 31, 2013 at 12:00 PM
True Oscar thx for helping in this discussion btw :O)

Its just that i want to draw a normal line (so no line-shape-thingy) on myVenster (=my map) and for that i need the coordinates of teh visualisation of myVenster (?)

SO I want my project-coordinate turned into a visualisation-coordinate.....

or am i thinking to complex?



as i said i just want to draw a line on the map consisting of several coordinates and the user get an idea of the total length of this line.....

so with every click i store the coordinate in an array

and calculate the length towards the former position

but i also want to draw the lines between the positions in this array on screen......

(i must admit that i never tried to do it with lines in a maplayer and deleting this layer when its not needed anymore..... , but still i want to learn to draw llines on a screen without using layers....)

Joska
May 31, 2013 at 12:30 PM
I think you may take advantage of the measure plugin code. If you download dotspatial sources you find it. It is written in C#, not in vb.net, but I think you may be able to understand what it does

Oscar
May 31, 2013 at 12:47 PM
Looking into it its very professional code i hope i understand it ..... i am not a programmer but learned to programm to make thinsg easier in my job.....

thx so far Oscar!
Jun 19, 2013 at 3:02 AM
Edited Jun 19, 2013 at 3:03 AM
Hmmm stil it aint working Oscar..... and i have tried 10's of options....

Lets say i have an array of digitized points

X1 = 100000 Y1 = 123456
X2 = 200000 Y2 = 124456
X3 = 300000 Y3 = 125456
X4 = 400000 Y4 = 126456

and i want to show this on the screen as a single line, what code makes this work....? How do i convert these to pixels on a map...?

how to use myMap.ProjToPixel? whats needed to make this work?

myMap.CreateGraphics.DrawLine(BlackPen, X1converted, Y1converted, X2converted, Y2converted)
myMap.CreateGraphics.DrawLine(BlackPen, X2converted, Y2converted, X3converted, Y3converted)
myMap.CreateGraphics.DrawLine(BlackPen, X3converted, Y3converted, X4converted, Y4converted)

thx for all help provided
Editor
Jun 19, 2013 at 9:56 AM
Edited Jun 19, 2013 at 10:05 AM
You should be doing your drawing in an overriden OnDraw method.
public class MapFunctionMeasure
{
  List<Coordinate> _points = new List<Coordinate>(); 
  /*
   all sort of other things
   */
   public override void OnDraw(MapDrawArgs e)
   {
       if (_points.Count == 0) return
       var points = new Point[_points.Count];
       for (var i = 0; i < _points.Count; i++)
       {
           points[i] = e.ProjToPixel(_points[i]);
       }
       e.Graphics.DrawLines(Pens.Red, points);
   }
  /*
   even more useful stuff
   */
}
Hth FObermaier
Jun 28, 2013 at 3:40 PM
thx will work this out

c code contains n error says my converter

An error occured converting your code, probably due to a syntax error:
-- line 10 col 12: ";" expected
Editor
Jun 29, 2013 at 5:52 AM
That may very well be, as the code has not seen a compiler.
But your converter is right, there should be a ";" after the return statement.