Groups | Blog | Home
all groups > dotnet drawing api > july 2003 >

dotnet drawing api : GIS/Map/Point Plotting



ML
7/4/2003 9:17:10 AM
Does anyone know of a control or have sample code that would allow the
plotting of points based on lat long within a given area?
Just looking for something simple to plot a number of points within a
bounding area.

ML
7/4/2003 11:32:09 AM
Do you have any samples of doing this?

[quoted text, click to view]

ML
7/4/2003 12:34:34 PM
Thank you very much. It seems to plot some points outside the box but I
think I get the point.

[quoted text, click to view]

ML
7/4/2003 1:00:45 PM
Disregard that last post. I see what it does now. Thanks again.

[quoted text, click to view]

Bob Powell [MVP]
7/4/2003 3:39:33 PM

Just convert the minutes and seconds into fractional degrees and plot using
the floating point representation.

By using a RectangleF as the bounds, you can determine whether to plot by
seeing if the rectangle contains the point.

--
Bob Powell [MVP]
C#, System.Drawing

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

Get the NEW must-have UI component. The .NET RectTracker
Enables CRectTracker like functionality for WindowsForms.
User defined layouts are a breeze.
http://www.bobpowell.net/recttracker.htm

[quoted text, click to view]

Bob Powell [MVP]
7/4/2003 5:15:53 PM
See the sample application below my signature. It paints lat-longs in a
bounded box. To refresh the screen , click the form.

--
Bob Powell [MVP]
C#, System.Drawing

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

Get the NEW must-have UI component. The .NET RectTracker
Enables CRectTracker like functionality for WindowsForms.
User defined layouts are a breeze.
http://www.bobpowell.net/recttracker.htm

-------------------------------------------------------------------
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace latlong

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;



struct LatLong

{

public float Degrees;

public float Minutes;

public float Seconds;

}



public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();



//

// TODO: Add any constructor code after InitializeComponent call

//

}



/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(384, 325);

this.Name = "Form1";

this.Text = "Form1";

this.Click += new System.EventHandler(this.Form1_Click);

this.Paint += new
System.Windows.Forms.PaintEventHandler(this.Form1_Paint);



}

#endregion



/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}



private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)

{

Random r = new Random();

LatLong[] latlongs = new LatLong[10];

for(int i=0; i<10; i++)

{

latlongs[i].Degrees=r.Next(360);

latlongs[i].Minutes=r.Next(60);

latlongs[i].Seconds=r.Next(60);

}



RectangleF bounds = new RectangleF(30,30,300,300);




e.Graphics.DrawRectangle(Pens.Green,bounds.X,bounds.Y,bounds.Width,bounds.He
ight);



for(int i=0; i<10; i+=2)

{

PointF p = new PointF(

(float)(latlongs[i].Degrees+

(latlongs[i].Minutes/60)+

(latlongs[i].Seconds/3600)),

(float)(latlongs[i+1].Degrees+

(latlongs[i+1].Minutes/60)+

(latlongs[i+1].Seconds/3600)));



if(bounds.Contains(p))

e.Graphics.DrawEllipse(Pens.Black,p.X-2,p.Y-2,4,4);

else

e.Graphics.DrawEllipse(Pens.Red,p.X-2,p.Y-2,4,4);





}







}



private void Form1_Click(object sender, System.EventArgs e)

{

this.Invalidate();

}

}

}



-------------------------------------------------------------------

[quoted text, click to view]

AddThis Social Bookmark Button