public static Region DrawLineString(System.Drawing.Graphics g, SharpMap.Geometries.LineString line, System.Drawing.Pen pen, SharpMap.Map map) { if (line.Vertices.Count > 1) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); PointF[] points = line.TransformToImage(map); gp.AddLines(points); g.DrawPath(pen, gp); GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] coords = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[points.Length]; for (int i = 0; i < points.Length; i++) coords[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(points[i].X, points[i].Y); GisSharpBlog.NetTopologySuite.Geometries.LineString ls = new GisSharpBlog.NetTopologySuite.Geometries.LineString(coords); GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] linearRingPoints = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[5]; linearRingPoints[0] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(0, 0); linearRingPoints[1] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(map.Size.Width, 0); linearRingPoints[2] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(map.Size.Width, map.Size.Height); linearRingPoints[3] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(0, map.Size.Height); linearRingPoints[4] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(0, 0); GisSharpBlog.NetTopologySuite.Geometries.LinearRing ring = new GisSharpBlog.NetTopologySuite.Geometries.LinearRing(linearRingPoints); GeoAPI.Geometries.IGeometry geom = ls.Intersection(new GisSharpBlog.NetTopologySuite.Geometries.Polygon(ring)); System.Drawing.Drawing2D.GraphicsPath gp2 = new System.Drawing.Drawing2D.GraphicsPath(); Pen p2 = new Pen(Color.Black, pen.Width < 4 ? 4 : pen.Width); if (geom is GisSharpBlog.NetTopologySuite.Geometries.LineString) { GisSharpBlog.NetTopologySuite.Geometries.LineString lineString = geom as GisSharpBlog.NetTopologySuite.Geometries.LineString; System.Drawing.PointF[] v = new System.Drawing.PointF[lineString.Coordinates.Length]; for (int i = 0; i < lineString.Coordinates.Length; i++) v[i] = new PointF((float)lineString.Coordinates[i].X, (float)lineString.Coordinates[i].Y); gp2.AddLines(v); } if (geom is GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection) { GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection geomCollection = geom as GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection; foreach (GisSharpBlog.NetTopologySuite.Geometries.Geometry cGeom in geomCollection) { if (cGeom is GisSharpBlog.NetTopologySuite.Geometries.LineString) { GisSharpBlog.NetTopologySuite.Geometries.LineString lineString = cGeom as GisSharpBlog.NetTopologySuite.Geometries.LineString; System.Drawing.PointF[] v = new System.Drawing.PointF[lineString.Coordinates.Length]; for (int i = 0; i < lineString.Coordinates.Length; i++) v[i] = new PointF((float)lineString.Coordinates[i].X, (float)lineString.Coordinates[i].Y); gp2.AddLines(v); } } } try { gp2.Widen(p2); System.Drawing.Region r = new System.Drawing.Region(gp2); return r; } catch (OutOfMemoryException) { return null; } } return null; }