shashank99
shashank99

Reputation: 21

Plot rectangle with multiple points. Is it possible?

this is precisely what I want multiple markers and covering them is a rectangle polygonI am having multiple latitude and longitude points. I need to plot a polygon in my Windows form application covering all those specified. Something like this.

It consists of a polygon and rectangle. Avoid polygon I just want the rectangle. 2

Upvotes: 0

Views: 220

Answers (1)

Ashutosh Raghuwanshi
Ashutosh Raghuwanshi

Reputation: 440

As hinted by @Taw, you can draw the rectangle with following co-ordinates:

List<PointF> ptlist = new List<PointF>();

// Add points to the list here

ptlist.Sort((p1, p2) => (p1.X.CompareTo(p2.X))); //Sort by X
float left = ptlist[0].X
float right = ptlist[ptlist.Count - 1].X

ptlist.Sort((p1, p2) => (p1.Y.CompareTo(p2.Y))); //Sort by Y
float top = ptlist[0].Y
float bottom = ptlist[ptlist.Count - 1].Y

// Use left, top and right, bottom to draw your rectangle.

Instead of sort, you may also write a simple code to find minimum and maximum of the list for efficiency.

Upvotes: 1

Related Questions