Creating a GraphicsPath object from a bunch of points

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a whole collection of points, they are actually Latitude and
Longitude points that make up a specific area. The points that I have make
up the outer edge of the are as well as the interior of the region. What I'm
looking to do is create a Path object that will completely bound all of these
points, and the path object should be as small as possible to bound each of
these points, in otherwords I not looking to make a big square that will
encompass all of the points I am looking to make an irregular shaped objects
that will exactly bound all of the points.
 
Sounds like an excersise in rasterization to me.

Sort all the points for Y, and then for X within each of the Y boundaries
then create rectangles for each Y value and each pair of X values such that
you create an array of rectangles that attempt to cover the area. Similar to
the rectangles in a region.

If all Y points are not covered, ie there are horizontal lines in the
resulting set, you'll need to extrapolate ans fill in the blanks somehow.
Possibly by doing a bresenham line-drawing algorithm in between the points
and thenn re-creating and re-sorting the array until you can't add any more
Y lines.

Finally create a region from the rectangle set by taking the union of a
blank region and all the rectangles in the set, use this region to clip the
output of your GraphicsPath.

To draw a line around it for a border you'll have to find one of the many
winding edge-walking algorithms that exist on the net and implement that.

You'll excuse me for not including code, you can see that it'd be a little
too much work for a complete answer.

See the article on extracting a region from a bitmap for at least some of
the techniques mentioned above.

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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top