public SharpMap.Geometries.MultiLineString SplitLineString( SharpMap.Geometries.LineString lineString, System.Double length) { if (lineString == null || lineString.IsEmpty()) { throw new System.ArgumentException("Linestring is null or Empty", "lineString"); } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ntsLine = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(lineString, gf); var ret = new SharpMap.Geometries.MultiLineString(); var lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(ntsLine); double currentLength = 0d; while (currentLength < ntsLine.Length) { var tmpLine = (NetTopologySuite.Geometries.LineString) lil.ExtractLine(currentLength, currentLength + length); ret.LineStrings.Add((SharpMap.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToSharpMapGeometry(tmpLine)); currentLength += length; } return(ret); }
protected override void OnMouseDoubleClick(MouseEventArgs e) { base.OnMouseDoubleClick(e); if (m_ActiveTool == Tools.DrawPolygon) { if (GeometryDefined != null) { SharpMap.Geometries.LinearRing ExtRing = new SharpMap.Geometries.LinearRing(); for (int i = 0; i < pointArray.GetUpperBound(0); i++) { ExtRing.Vertices.Add(Map.ImageToWorld(new PointF(pointArray[i].X, pointArray[i].Y))); } ExtRing.Vertices.Add(Map.ImageToWorld(new PointF(pointArray[0].X, pointArray[0].Y))); GeometryDefined(new SharpMap.Geometries.Polygon(ExtRing)); } ActiveTool = Tools.None; } else if (m_ActiveTool == Tools.DrawLine) { if (GeometryDefined != null) { SharpMap.Geometries.LineString Line = new SharpMap.Geometries.LineString(); for (int i = 0; i <= pointArray.GetUpperBound(0); i++) { Line.Vertices.Add(Map.ImageToWorld(new PointF(pointArray[i].X, pointArray[i].Y))); } GeometryDefined(Line); } ActiveTool = Tools.None; } }
public static void EnsureVisible(SharpMap.Map map, SharpMap.Geometries.Point pt) { const double ensureVisibleRatio = 0.1d; //Get current map envelope var bb = map.Envelope; System.Console.WriteLine(string.Format("Map envelope: {0}", bb)); //Set valid envelope var evbb = bb.Grow(-ensureVisibleRatio * bb.Width, -ensureVisibleRatio * bb.Height); System.Console.WriteLine(string.Format("Valid envelope: {0}", evbb)); //Test if Point is in valid envelope if (evbb.Contains(pt)) { return; } //It is not System.Console.WriteLine(string.Format("Valid envelope does not contain {0}", pt)); //LineString from Map.Center -> to Point var ls = new SharpMap.Geometries.LineString(new[] { evbb.GetCentroid(), pt }); System.Console.WriteLine(string.Format("LineString Map.Center -> Point: {0}", ls)); //Setup Linestring from BoundingBox var gf = new NetTopologySuite.Geometries.GeometryFactory(); var evbbpts = new System.Collections.Generic.List <SharpMap.Geometries.Point>( new[] { evbb.TopLeft, evbb.TopRight, evbb.BottomRight, evbb.BottomLeft, evbb.TopLeft }); var evbblinearring = new SharpMap.Geometries.LineString(evbbpts); System.Console.WriteLine(string.Format("Linestring of valid envelope: {0}", evbblinearring)); // convert geometries to NTS var ntsevbb = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(evbblinearring, gf); var ntsls = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(ls, gf); // Get intersection point var intGeo = ntsevbb.Intersection(ntsls); var intPt = (NetTopologySuite.Geometries.Point)intGeo; System.Console.WriteLine(string.Format("Intersection point is: {0}", intPt)); //Compute offset var dx = pt.X - intPt.X; var dy = pt.Y - intPt.Y; System.Console.WriteLine(string.Format("Map.Center needs to be shifted by: [{0}, {1}]", dx, dy)); //Set new center Center map.Center = new SharpMap.Geometries.Point(map.Center.X + dx, map.Center.Y + dy); }
public void TestLengthIndexedLine() { var l = new SharpMap.Geometries.LineString( new SharpMap.Geometries.Point[] { new SharpMap.Geometries.Point(0, 0), new SharpMap.Geometries.Point(300, 100), }); System.Console.WriteLine(SplitLineString(l, 20d)); }
public void TestLengthIndexedLine() { var l = new SharpMap.Geometries.LineString( new SharpMap.Geometries.Point[] { new SharpMap.Geometries.Point(0, 0), new SharpMap.Geometries.Point(300, 100),}); System.Console.WriteLine(SplitLineString(l, 20d)); }
public void TestMapDecorationTest() { var m = new Map(new Size(780, 540)) { BackColor = Color.White }; var p = new GeometryProvider(new List <SharpMap.Geometries.Geometry>()); var pts = new [] { new GeoPoint(0, 0), new GeoPoint(779, 539) }; var ls = new SharpMap.Geometries.LineString(new List <GeoPoint>(pts)); p.Geometries.Add(ls); m.Layers.Add(new VectorLayer("t", p)); m.ZoomToExtents(); m.Decorations.Add(new TestDecoration { Anchor = MapDecorationAnchor.LeftTop, BorderColor = Color.Green, BackgroundColor = Color.LightGreen, BorderWidth = 2, Location = new Point(10, 10), BorderMargin = new Size(5, 5), RoundedEdges = true, Opacity = 0.6f }); m.Decorations.Add(new TestDecoration { Anchor = MapDecorationAnchor.RightTop, BorderColor = Color.Red, BackgroundColor = Color.LightCoral, BorderWidth = 2, Location = new Point(10, 10), BorderMargin = new Size(5, 5), RoundedEdges = true, Opacity = 0.2f }); m.Decorations.Add(new ScaleBar { Anchor = MapDecorationAnchor.Default, BorderColor = Color.Blue, BackgroundColor = Color.CornflowerBlue, BorderWidth = 2, Location = new Point(10, 10), BorderMargin = new Size(5, 5), RoundedEdges = true, BarWidth = 4, ScaleText = ScaleBarLabelText.RepresentativeFraction, NumTicks = 2, Opacity = 1f }); var bmp = m.GetMap(); bmp.Save("TestMapDecorationTest.bmp"); }
/// <summary> /// Convert WellKnownText to linestrings /// </summary> /// <param name="WKT"></param> /// <returns></returns> private SharpMap.Geometries.LineString WktToLineString(string WKT) { SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString(); WKT = WKT.Substring(WKT.LastIndexOf('(') + 1).Split(')')[0]; string[] strPoints = WKT.Split(','); foreach (string strPoint in strPoints) { string[] coord = strPoint.Split(' '); line.Vertices.Add(new SharpMap.Geometries.Point(double.Parse(coord[0], SharpMap.Map.numberFormat_EnUS), double.Parse(coord[1], SharpMap.Map.numberFormat_EnUS))); } return(line); }
private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder) { SharpMap.Geometries.LineString l = new SharpMap.Geometries.LineString(); //l.Vertices.AddRange(ReadCoordinates(reader, byteOrder)); Point[] arrPoint = ReadCoordinates(reader, byteOrder); for (int i = 0; i < arrPoint.Length; i++) { l.Vertices.Add(arrPoint[i]); } return(l); }
public void TestMapDecorationTest() { var m = new Map(new Size(780, 540)) {BackColor = Color.White}; var p = new GeometryProvider(new List<SharpMap.Geometries.Geometry>()); var pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)}; var ls = new SharpMap.Geometries.LineString(new List<GeoPoint>(pts)); p.Geometries.Add(ls); m.Layers.Add(new VectorLayer("t",p)); m.ZoomToExtents(); m.Decorations.Add(new TestDecoration { Anchor = MapDecorationAnchor.LeftTop, BorderColor = Color.Green, BackgroundColor = Color.LightGreen, BorderWidth = 2, Location = new Point(10, 10), BorderMargin = new Size(5, 5), RoundedEdges = true, Opacity = 0.6f }); m.Decorations.Add(new TestDecoration { Anchor = MapDecorationAnchor.RightTop, BorderColor = Color.Red, BackgroundColor = Color.LightCoral, BorderWidth = 2, Location = new Point(10, 10), BorderMargin = new Size(5, 5), RoundedEdges = true, Opacity = 0.2f }); m.Decorations.Add(new ScaleBar { Anchor = MapDecorationAnchor.Default, BorderColor = Color.Blue, BackgroundColor = Color.CornflowerBlue, BorderWidth = 2, Location = new Point(10, 10), BorderMargin = new Size(5, 5), RoundedEdges = true, BarWidth = 4, ScaleText =ScaleBarLabelText.RepresentativeFraction, NumTicks = 2, Opacity = 1f }); var bmp = m.GetMap(); bmp.Save("TestMapDecorationTest.bmp"); }
public static void EnsureVisible(SharpMap.Map map, SharpMap.Geometries.Point pt) { const double ensureVisibleRatio = 0.1d; //Get current map envelope var bb = map.Envelope; System.Console.WriteLine(string.Format("Map envelope: {0}", bb)); //Set valid envelope var evbb = bb.Grow(- ensureVisibleRatio * bb.Width, -ensureVisibleRatio * bb.Height ); System.Console.WriteLine(string.Format("Valid envelope: {0}", evbb)); //Test if Point is in valid envelope if (evbb.Contains(pt)) return; //It is not System.Console.WriteLine(string.Format("Valid envelope does not contain {0}", pt)); //LineString from Map.Center -> to Point var ls = new SharpMap.Geometries.LineString(new[] {evbb.GetCentroid(), pt}); System.Console.WriteLine(string.Format("LineString Map.Center -> Point: {0}", ls)); //Setup Linestring from BoundingBox var gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); var evbbpts = new System.Collections.Generic.List<SharpMap.Geometries.Point>( new[] {evbb.TopLeft, evbb.TopRight, evbb.BottomRight, evbb.BottomLeft, evbb.TopLeft }); var evbblinearring = new SharpMap.Geometries.LineString(evbbpts); System.Console.WriteLine(string.Format("Linestring of valid envelope: {0}", evbblinearring)); // convert geometries to NTS var ntsevbb = (GisSharpBlog.NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(evbblinearring, gf); var ntsls = (GisSharpBlog.NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(ls, gf); // Get intersection point var intGeo = ntsevbb.Intersection(ntsls); var intPt = (GisSharpBlog.NetTopologySuite.Geometries.Point)intGeo; System.Console.WriteLine(string.Format("Intersection point is: {0}", intPt)); //Compute offset var dx = pt.X - intPt.X; var dy = pt.Y - intPt.Y; System.Console.WriteLine(string.Format("Map.Center needs to be shifted by: [{0}, {1}]", dx, dy)); //Set new center Center map.Center = new SharpMap.Geometries.Point(map.Center.X + dx, map.Center.Y + dy); }
private SharpMap.Rendering.Label CreateLabel(SharpMap.Geometries.Geometry feature, string text, float rotation, SharpMap.Styles.LabelStyle style, Map map, System.Drawing.Graphics g) { System.Drawing.SizeF size = g.MeasureString(text, style.Font); System.Drawing.PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid()); position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f; position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f; if (position.X - size.Width > map.Size.Width || position.X + size.Width < 0 || position.Y - size.Height > map.Size.Height || position.Y + size.Height < 0) { return(null); } else { SharpMap.Rendering.Label lbl; if (!style.CollisionDetection) { lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, null, style); } else { //Collision detection is enabled so we need to measure the size of the string lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, new SharpMap.Rendering.LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width, position.Y + size.Height * 0.5f + style.CollisionBuffer.Height, size.Width + 2f * style.CollisionBuffer.Width, size.Height + style.CollisionBuffer.Height * 2f), style); } if (feature.GetType() == typeof(SharpMap.Geometries.LineString)) { SharpMap.Geometries.LineString line = feature as SharpMap.Geometries.LineString; if (line.Length / map.PixelSize > size.Width) //Only label feature if it is long enough { CalculateLabelOnLinestring(line, ref lbl, map); } else { return(null); } } return(lbl); } }
private void CalculateLabelOnLinestring(SharpMap.Geometries.LineString line, ref SharpMap.Rendering.Label label, Map map) { double dx, dy; double tmpx, tmpy; double angle = 0.0; // first find the middle segment of the line int midPoint = (line.Vertices.Count - 1) / 2; if (line.Vertices.Count > 2) { dx = line.Vertices[midPoint + 1].X - line.Vertices[midPoint].X; dy = line.Vertices[midPoint + 1].Y - line.Vertices[midPoint].Y; } else { midPoint = 0; dx = line.Vertices[1].X - line.Vertices[0].X; dy = line.Vertices[1].Y - line.Vertices[0].Y; } if (dy == 0) { label.Rotation = 0; } else if (dx == 0) { label.Rotation = 90; } else { // calculate angle of line angle = -Math.Atan(dy / dx) + Math.PI * 0.5; angle *= (180d / Math.PI); // convert radians to degrees label.Rotation = (float)angle - 90; // -90 text orientation } tmpx = line.Vertices[midPoint].X + (dx * 0.5); tmpy = line.Vertices[midPoint].Y + (dy * 0.5); label.LabelPoint = map.WorldToImage(new SharpMap.Geometries.Point(tmpx, tmpy)); }
/// <summary> /// Reads and parses the geometry with ID 'oid' from the ShapeFile /// </summary> /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks> /// <param name="oid">Object ID</param> /// <returns>geometry</returns> private SharpMap.Geometries.Geometry ReadGeometry(uint oid) { brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length ShapeType type = (ShapeType)brShapeFile.ReadInt32(); //Shape type if (type == ShapeType.Null) { return(null); } if (_ShapeType == ShapeType.Point || _ShapeType == ShapeType.PointM || _ShapeType == ShapeType.PointZ) { SharpMap.Geometries.Point tempFeature = new SharpMap.Geometries.Point(); return(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } else if (_ShapeType == ShapeType.Multipoint || _ShapeType == ShapeType.MultiPointM || _ShapeType == ShapeType.MultiPointZ) { brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box SharpMap.Geometries.MultiPoint feature = new SharpMap.Geometries.MultiPoint(); int nPoints = brShapeFile.ReadInt32(); // get the number of points if (nPoints == 0) { return(null); } for (int i = 0; i < nPoints; i++) { feature.Points.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } return(feature); } else if (_ShapeType == ShapeType.PolyLine || _ShapeType == ShapeType.Polygon || _ShapeType == ShapeType.PolyLineM || _ShapeType == ShapeType.PolygonM || _ShapeType == ShapeType.PolyLineZ || _ShapeType == ShapeType.PolygonZ) { brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box int nParts = brShapeFile.ReadInt32(); // get number of parts (segments) if (nParts == 0) { return(null); } int nPoints = brShapeFile.ReadInt32(); // get number of points int[] segments = new int[nParts + 1]; //Read in the segment indexes for (int b = 0; b < nParts; b++) { segments[b] = brShapeFile.ReadInt32(); } //add end point segments[nParts] = nPoints; if ((int)_ShapeType % 10 == 3) { SharpMap.Geometries.MultiLineString mline = new SharpMap.Geometries.MultiLineString(); for (int LineID = 0; LineID < nParts; LineID++) { SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString(); for (int i = segments[LineID]; i < segments[LineID + 1]; i++) { line.Vertices.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } mline.LineStrings.Add(line); } if (mline.LineStrings.Count == 1) { return(mline[0]); } return(mline); } else //(_ShapeType == ShapeType.Polygon etc...) { //First read all the rings List <SharpMap.Geometries.LinearRing> rings = new List <SharpMap.Geometries.LinearRing>(); for (int RingID = 0; RingID < nParts; RingID++) { SharpMap.Geometries.LinearRing ring = new SharpMap.Geometries.LinearRing(); for (int i = segments[RingID]; i < segments[RingID + 1]; i++) { ring.Vertices.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } rings.Add(ring); } bool[] IsCounterClockWise = new bool[rings.Count]; int PolygonCount = 0; for (int i = 0; i < rings.Count; i++) { IsCounterClockWise[i] = rings[i].IsCCW(); if (!IsCounterClockWise[i]) { PolygonCount++; } } if (PolygonCount == 1) //We only have one polygon { SharpMap.Geometries.Polygon poly = new SharpMap.Geometries.Polygon(); poly.ExteriorRing = rings[0]; if (rings.Count > 1) { for (int i = 1; i < rings.Count; i++) { poly.InteriorRings.Add(rings[i]); } } return(poly); } else { SharpMap.Geometries.MultiPolygon mpoly = new SharpMap.Geometries.MultiPolygon(); SharpMap.Geometries.Polygon poly = new SharpMap.Geometries.Polygon(); poly.ExteriorRing = rings[0]; for (int i = 1; i < rings.Count; i++) { if (!IsCounterClockWise[i]) { mpoly.Polygons.Add(poly); poly = new SharpMap.Geometries.Polygon(rings[i]); } else { poly.InteriorRings.Add(rings[i]); } } mpoly.Polygons.Add(poly); return(mpoly); } } } else { throw (new ApplicationException("Shapefile type " + _ShapeType.ToString() + " not supported")); } }
internal static GisSharpBlog.NetTopologySuite.Geometries.LineString ToNTSLineString(SharpMap.Geometries.LineString lineString, GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory) { GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] coordinates = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[lineString.NumPoints]; int index = 0; foreach (SharpMap.Geometries.Point point in lineString.Vertices) { coordinates[index++] = ToNTSCoordinate(point, factory); } return(factory.CreateLineString(coordinates) as GisSharpBlog.NetTopologySuite.Geometries.LineString); }
/// <summary> /// Convert WellKnownText to linestrings /// </summary> /// <param name="WKT"></param> /// <returns></returns> private SharpMap.Geometries.LineString WktToLineString(string WKT) { SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString(); WKT = WKT.Substring(WKT.LastIndexOf('(') + 1).Split(')')[0]; string[] strPoints = WKT.Split(','); foreach (string strPoint in strPoints) { string[] coord = strPoint.Split(' '); line.Vertices.Add(new SharpMap.Geometries.Point(double.Parse(coord[0], SharpMap.Map.numberFormat_EnUS), double.Parse(coord[1], SharpMap.Map.numberFormat_EnUS))); } return line; }
private static void SharpMapLineStringToSqlGeometry(SqlGeometryBuilder geomBuilder, SMLineString lineString) { geomBuilder.BeginGeometry(OpenGisGeometryType.LineString); SMPoint point = lineString.StartPoint; geomBuilder.BeginFigure(point.X, point.Y); for (int i = 1; i < lineString.NumPoints; i++) { point = lineString.Point(i); geomBuilder.AddLine(point.X, point.Y); } geomBuilder.EndFigure(); geomBuilder.EndGeometry(); }
/// <summary> /// Reads and parses the geometry with ID 'oid' from the ShapeFile /// </summary> /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks> /// <param name="oid">Object ID</param> /// <returns>geometry</returns> private SharpMap.Geometries.Geometry ReadGeometry(uint oid) { brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length ShapeType type = (ShapeType)brShapeFile.ReadInt32(); //Shape type if (type == ShapeType.Null) return null; if (_ShapeType == ShapeType.Point || _ShapeType==ShapeType.PointM || _ShapeType==ShapeType.PointZ) { SharpMap.Geometries.Point tempFeature = new SharpMap.Geometries.Point(); return new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()); } else if (_ShapeType == ShapeType.Multipoint || _ShapeType == ShapeType.MultiPointM || _ShapeType == ShapeType.MultiPointZ) { brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box SharpMap.Geometries.MultiPoint feature = new SharpMap.Geometries.MultiPoint(); int nPoints = brShapeFile.ReadInt32(); // get the number of points if (nPoints == 0) return null; for (int i = 0; i < nPoints; i++) feature.Points.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); return feature; } else if ( _ShapeType == ShapeType.PolyLine || _ShapeType == ShapeType.Polygon || _ShapeType == ShapeType.PolyLineM || _ShapeType == ShapeType.PolygonM || _ShapeType == ShapeType.PolyLineZ || _ShapeType == ShapeType.PolygonZ) { brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box int nParts = brShapeFile.ReadInt32(); // get number of parts (segments) if (nParts == 0) return null; int nPoints = brShapeFile.ReadInt32(); // get number of points int[] segments = new int[nParts + 1]; //Read in the segment indexes for (int b = 0; b < nParts; b++) segments[b] = brShapeFile.ReadInt32(); //add end point segments[nParts] = nPoints; if ((int)_ShapeType%10 == 3) { SharpMap.Geometries.MultiLineString mline = new SharpMap.Geometries.MultiLineString(); for (int LineID = 0; LineID < nParts; LineID++) { SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString(); for (int i = segments[LineID]; i < segments[LineID + 1]; i++) line.Vertices.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); mline.LineStrings.Add(line); } if (mline.LineStrings.Count == 1) return mline[0]; return mline; } else //(_ShapeType == ShapeType.Polygon etc...) { //First read all the rings List<SharpMap.Geometries.LinearRing> rings = new List<SharpMap.Geometries.LinearRing>(); for (int RingID = 0; RingID < nParts; RingID++) { SharpMap.Geometries.LinearRing ring = new SharpMap.Geometries.LinearRing(); for (int i = segments[RingID]; i < segments[RingID + 1]; i++) ring.Vertices.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); rings.Add(ring); } bool[] IsCounterClockWise = new bool[rings.Count]; int PolygonCount = 0; for (int i = 0; i < rings.Count;i++) { IsCounterClockWise[i] = rings[i].IsCCW(); if (!IsCounterClockWise[i]) PolygonCount++; } if (PolygonCount == 1) //We only have one polygon { SharpMap.Geometries.Polygon poly = new SharpMap.Geometries.Polygon(); poly.ExteriorRing = rings[0]; if (rings.Count > 1) for (int i = 1; i < rings.Count; i++) poly.InteriorRings.Add(rings[i]); return poly; } else { SharpMap.Geometries.MultiPolygon mpoly = new SharpMap.Geometries.MultiPolygon(); SharpMap.Geometries.Polygon poly = new SharpMap.Geometries.Polygon(); poly.ExteriorRing = rings[0]; for (int i = 1; i < rings.Count;i++) { if (!IsCounterClockWise[i]) { mpoly.Polygons.Add(poly); poly = new SharpMap.Geometries.Polygon(rings[i]); } else poly.InteriorRings.Add(rings[i]); } mpoly.Polygons.Add(poly); return mpoly; } } } else throw (new ApplicationException("Shapefile type " + _ShapeType.ToString() + " not supported")); }