⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geometry.cs

📁 实现SHP
💻 CS
📖 第 1 页 / 共 3 页
字号:
		/// </summary>
		/// <param name="g">Graphics object to draw ellipse</param>
		/// <param name="p">Pen for drawing</param>
		/// <param name="b">Brush for drawing</param>
		public override void DrawGraphics(ref Graphics g, ref Pen p, ref Brush b)
		{
			float ex,ey;
			if(Item.GetType()==typeof(gml.CoordinatesType))
			{
				gml.CoordinatesType ct = (gml.CoordinatesType)this.Item;
				ex = (float) ct.doubleArray[0];
				ey = (float) ct.doubleArray[1];
			}
			else
			{
				ex=(float)((gml.CoordType)this.Item).X;
				ey=(float)((gml.CoordType)this.Item).Y;
			}
			float frad = (float)this.PointRadius;
			g.DrawEllipse(p,ex-0.5F*frad,ey-0.5F*frad,2.0F*frad,2.0F*frad);
			g.FillEllipse(b,ex-0.5F*frad,ey-0.5F*frad,2.0F*frad,2.0F*frad);
		}
	}

	/// <summary>
	/// Geometry type for 2 or more coordinate tuples, with linear interpolation between them.
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	[XmlRoot("LineString", Namespace="http://www.opengis.net/gml", IsNullable=false)]
	public class LineStringType : AbstractGeometryType 
	{
		[XmlElement("coord", typeof(CoordType))]	//minOccurs=2
		[XmlElement("coordinates", typeof(CoordinatesType))] //maxOccurs=1
		public gml.CoordWrapper[] Items;

		/// <summary>
		/// Constructs LineStringType with empty coordinate tuples
		/// </summary>
		public LineStringType()		{}

		/// <summary>
		/// Constructs LineStringType using specified CoordinatesType as Item
		/// </summary>
		/// <param name="coordinates">CoordinatesType to extract tuples from</param>
		public LineStringType(CoordinatesType coordinates)
		{
			Items = new gml.CoordinatesType[1]{coordinates};
		}

		/// <summary>
		/// Constructs LineStringType using specified array of CoordType as Item
		/// </summary>
		/// <param name="coords">array of CoordType to extract tuples from</param>
		public LineStringType(CoordType[] coords)
		{
			if(coords.Length<2) throw new System.ArgumentException("must be array of 2 or more gml.CoordType","coords");
			Items=coords;
		}

		/// <summary>
		/// Gets path data from this LineString coordinate tuples
		/// </summary>
		/// <returns>path data for svg path object</returns>
		public string getPathString()
		{
			string str="";
			if(Items[0].GetType()==typeof(gml.CoordinatesType))
			{
				str = ((gml.CoordinatesType)Items[0]).getPathString(); 
			}
			else
			{
				System.Text.StringBuilder sb=new System.Text.StringBuilder(); 
				sb.Append("M "); 
				for(int i=0;i<Items.Length;i++ )
				{
					if(i==1) sb.Append(" L");
					sb.Append(((gml.CoordType) Items[i]).getPointString()+" ");
				}
				str=sb.ToString(); 
			}
			return str;
		}

		/// <summary>
		/// Gets polyline data from this LineString coordinate tuples
		/// </summary>
		/// <returns>polyline data for svg path object</returns>
		public string getPointsString()
		{
			string str="";
			if(Items[0].GetType()==typeof(gml.CoordinatesType))
			{
				str = ((gml.CoordinatesType)Items[0]).getPointsString(); 
			}
			else
			{
				System.Text.StringBuilder sb=new System.Text.StringBuilder(); 
				for(int i=0;i<Items.Length;i++ )
				{
					sb.Append(((gml.CoordType) Items[i]).getPointString()+" ");
				}
				str=sb.ToString(); 
			}
			return str;
		}

		/// <summary>
		/// Creates svg polyline from this LineString coordinate tuples
		/// </summary>
		/// <returns>svg polyline object</returns>
		public override svg.SvgElement createSvgObject()
		{
			//return new svg.path(this.getPathString());
			return new svg.polyline(this.getPointsString());  
		}

		/// <summary>
		/// Gets array of PointF from this LineString coordinate tuples
		/// </summary>
		/// <returns>array of PointF for drawing shapes.</returns>
		public PointF[] getPointFArray()
		{	
			if(Items[0].GetType()==typeof(gml.CoordinatesType))
			{
				return ((gml.CoordinatesType)Items[0]).getPointFArray(); 
			}
			else
			{
				PointF[] pfs = new PointF[Items.Length];
				for(int i=0;i<Items.Length;i++ )
				{
					pfs[i]=((gml.CoordType) Items[i]).getPointF();
				}
				return pfs;
			}
		}

		/// <summary>
		/// Draws line using this LineString coordinate tuples
		/// </summary>
		/// <param name="g">Graphics to draw Line</param>
		/// <param name="p">Pen for drawing</param>
		/// <param name="b">Brush for drawing</param>
		public override void DrawGraphics(ref Graphics g, ref Pen p, ref Brush b)
		{
			PointF[] pfs = getPointFArray();
			if(pfs.Length<2) 
			{
				System.Console.WriteLine("invalid LineString data : PointF[] length < 2  - bypassed."); 
				return;
			}
			g.DrawLines(p,pfs);
		}
	}

	/// <summary>
	/// Geometry type for 4 or more coordinate tuples, with linear interpolation between them; 
	/// The first and last coordinates must be coincident
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	[XmlRoot("LinearRing", Namespace="http://www.opengis.net/gml", IsNullable=false)]
	public class LinearRingType : AbstractGeometryType 
	{
		[XmlElement("coord", typeof(CoordType))]	//minOccurs=4
		[XmlElement("coordinates", typeof(CoordinatesType))]
		public gml.CoordWrapper[] Items;

		/// <summary>
		/// Constructs LinearRing with empty coordinates
		/// </summary>
		public LinearRingType(){}

		/// <summary>
		/// Constructs LinearRing using array of CoordType as Item
		/// </summary>
		/// <param name="coords">array of CoordType to extract coordinates from</param>
		public LinearRingType(gml.CoordType[] coords)
		{
			if(coords.Length<4) throw new System.ArgumentException("must be array of 4 or more gml.CoordType","coords"); 
			Items=coords;
		}
		/// <summary>
		/// Constructs LinearRing using a CoordinatesType as Item
		/// </summary>
		/// <param name="coordinates">CoordinatesType to extract coordinates from</param>
		public LinearRingType(gml.CoordinatesType coordinates)
		{
			Items=new gml.CoordinatesType[1]{coordinates};
		}

		/// <summary>
		/// Gets path data from this LinearRing coordinates
		/// </summary>
		/// <returns>path data for svg path object</returns>
		public string getPathString()
		{
			string str="";
			if(Items[0].GetType()==typeof(gml.CoordinatesType))
			{
				str = ((gml.CoordinatesType)Items[0]).getPathString(); 
			}
			else
			{
				System.Text.StringBuilder sb=new System.Text.StringBuilder(); 
				for(int i=0;i<Items.Length;i++ )
				{
					sb.Append(((gml.CoordType) Items[i]).getPointString()+" ");
				}
				str=sb.ToString();
			}
			return str;
		}

		/// <summary>
		/// Creates svg Path object from this LinearRing
		/// </summary>
		/// <returns>svg Path object</returns>
		public override svg.SvgElement createSvgObject()
		{
			return new svg.path(this.getPathString());
		}

		/// <summary>
		/// Gets array of PointF from this LinearRing coordinates.
		/// </summary>
		/// <returns>array of PointF used for drawing</returns>
		public PointF[] getPointFArray()
		{	
			if(Items[0].GetType()==typeof(gml.CoordinatesType))
			{
				return ((gml.CoordinatesType)Items[0]).getPointFArray();
			}
			else
			{
				PointF[] pfs=new PointF[Items.Length];
				for(int i=0;i<Items.Length;i++ )
				{
					pfs[i]=((gml.CoordType)Items[i]).getPointF();
				}
				return pfs;
			}
		}

		/// <summary>
		/// Draws polygon from this LinearRing
		/// </summary>
		/// <param name="g">Graphics to draw polygon</param>
		/// <param name="p">Pen for drawing</param>
		/// <param name="b">Brush for drawing</param>
		public override void DrawGraphics(ref Graphics g, ref Pen p, ref Brush b)
		{
			g.DrawPolygon(p,getPointFArray());
		}
	}


	/// <summary>
	/// Geometry type for sequence of LinearRings, one as outer boundary and zero or more as inner boundaries.
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	[XmlRoot("Polygon", Namespace="http://www.opengis.net/gml", IsNullable=false)]
	public class PolygonType : AbstractGeometryType 
	{
		/// <summary>
		/// Constructs empty PolygonType
		/// </summary>
		public PolygonType(){	}

		/// <summary>
		/// Constructs new PolygonType with specified outer boundary.
		/// </summary>
		/// <param name="cdt">CoordinatesType as the outer boundary</param>
		public PolygonType(gml.CoordinatesType cdt)
		{
			outerBoundaryIs=new PolygonTypeOuterBoundaryIs(cdt);
		}

		//polygon with one innerboundary
		/// <summary>
		/// Constructs new PolygonType with specified outer boundary and one inner boundary.
		/// </summary>
		/// <param name="outerC">Outer boundary</param>
		/// <param name="innerC">Inner boundary</param>
		public PolygonType(gml.CoordinatesType outerC,gml.CoordinatesType innerC)
		{
			outerBoundaryIs=new PolygonTypeOuterBoundaryIs(outerC);
			innerBoundaryIs=new PolygonTypeInnerBoundaryIs[1]{new PolygonTypeInnerBoundaryIs(innerC)} ;
		}

		/// <summary>
		/// LinearRing which defines outer boundary of the polygon.
		/// </summary>
		[XmlElement("outerBoundaryIs")]
		public PolygonTypeOuterBoundaryIs outerBoundaryIs;	//minOccurs=1

		/// <summary>
		/// Array of LinearRings which defines inner boundaries of the polygon.
		/// </summary>
		[XmlElement("innerBoundaryIs", IsNullable=false)]
		public PolygonTypeInnerBoundaryIs[] innerBoundaryIs=new PolygonTypeInnerBoundaryIs[0]; //minOccurs=0

		/// <summary>
		/// Creates svg Path object from this PolygonType
		/// </summary>
		/// <returns>SVG Path object</returns>
		public override svg.SvgElement createSvgObject()
		{
			svg.path p = new svg.path(outerBoundaryIs.LinearRing.getPathString()+"z "); 
			for (int i=0;i<this.innerBoundaryIs.Length;i++)
			{
				p.d+= " " + this.innerBoundaryIs[i].LinearRing.getPathString()+"z ";
			}
			//check the effects of fill-rule (nonzero,evenodd) property on holes(doughnuts) / islands.
			return p;
		}

		/// <summary>
		/// Draws GraphicsPath from this PolygonType
		/// </summary>
		/// <param name="g">Graphics to draw path</param>
		/// <param name="p">Pen for drawing</param>
		/// <param name="b">Brush for drawing</param>
		public override void DrawGraphics(ref Graphics g, ref Pen p, ref Brush b)
		{
			System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
			gp.AddPolygon(outerBoundaryIs.LinearRing.getPointFArray());	
			for (int i=0;i<this.innerBoundaryIs.Length;i++)
			{
				gp.AddPolygon(innerBoundaryIs[i].LinearRing.getPointFArray());
			}
			g.FillPath(b,gp);
			g.DrawPath(p,gp);
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -