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

📄 feature.cs

📁 实现SHP
💻 CS
📖 第 1 页 / 共 2 页
字号:
///GeoCon, free tool to create gml & svg from gis files. 
///Copyright(C) 2005 Amri Rosyada
///Distributed under GNU-LGPL, see a copy of the license in root directory
 
using System;
using System.Xml;  
using System.Xml.Schema;
using System.Xml.Serialization;

namespace gml
{

	#region absract feature types
	/// <summary>
	/// All features must derived from this abstract class.
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	//[XmlIncludeAttribute(typeof(AbstractFeatureCollectionBaseType))]
	public abstract class AbstractFeatureType //: MarshalByRefObject
	{
		/// <summary>
		/// Description about this feature
		/// </summary>
		[XmlElement("description")] public string description;	//minOccurs=0
		/// <summary>
		/// Name of the feature
		/// </summary>
		[XmlElement("name")] public string name;				//minOccurs=0

		/// <summary>
		/// Bounding box of the feature
		/// </summary>
		[XmlElement("boundedBy", typeof(gml.BoundingShapeType))]
		public gml.BoundingShapeType boundedBy;					//minOccurs=0

		/// <summary>
		/// ID of the feature
		/// </summary>
		[XmlAttribute(DataType="ID")] public string fid;		//optional

		//add additional properties here in derived class (e.g non-geometry feature data)

		/// <summary>
		/// Constructs empty feature
		/// </summary>
		public AbstractFeatureType(){	}

		/// <summary>
		/// Constructs empty feature with specified bounding.
		/// </summary>
		/// <param name="bound">Bounding type of this feature</param>
		public AbstractFeatureType(gml.BoundingShapeType bound)
		{
			boundedBy=bound;
		}
	}

	/// <summary>
	/// Feature Collection base type with mandatory bounding shape property.
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	public abstract class AbstractFeatureCollectionBaseType : gml.AbstractFeatureType 
	{
		/// <summary>
		/// Constructs AbstractFeatureCollectionBaseType with bounding type set to NullType
		/// </summary> 
		public AbstractFeatureCollectionBaseType()
		{
			//since boundedBy is mandatory here, assign default value of 'unknown'
			boundedBy = new gml.BoundingShapeType(new gml.NullType());
		}
		/// <summary>
		/// Constructs AbstractFeatureCollectionBaseType with specified bounding type.
		/// </summary>
		/// <param name="bound">Bounding shape type of this collection</param>
		public AbstractFeatureCollectionBaseType(gml.BoundingShapeType bound)
		{
			boundedBy = bound;
		}
	}

	/// <summary>
	/// A feature collection contains zero or more featureMember elements.
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	//[XmlIncludeAttribute(typeof(AbstractFeatureType))]
	public abstract class AbstractFeatureCollectionType : gml.AbstractFeatureCollectionBaseType 
	{
		/// <summary>
		/// Members of this collection
		/// </summary>
		[XmlElement("featureMember")]
		public FeatureAssociationType[] featureMember=null; 

		/// <summary>
		/// Constructs AbstractFeatureCollectionType with default bounding type.
		/// </summary>
		public AbstractFeatureCollectionType():base()	{	}
		/// <summary>
		/// Constructs AbstractFeatureCollectionType with specified bounding type.
		/// </summary>
		/// <param name="bound">Bounding type of the collection</param>
		public AbstractFeatureCollectionType(gml.BoundingShapeType bound) : base(bound)	{}
		/// <summary>
		/// Constructs AbstractFeatureCollectionType with specified bounding type and members.
		/// </summary>
		/// <param name="bound">Bounding type of the collection</param>
		/// <param name="features">Members of this collection</param>
		public AbstractFeatureCollectionType(gml.BoundingShapeType bound,gml.FeatureAssociationType[] features) : base(bound)
		{
			setMembers(features);
		}
		/// <summary>
		/// Constructs AbstractFeatureCollectionType with default bounding type and specified members.
		/// </summary>
		/// <param name="features">Members of this collection</param>
		public AbstractFeatureCollectionType(gml.FeatureAssociationType[] features) : base()
		{
			setMembers(features);
		}
		/// <summary>
		/// Sets members of this collection to specified features.
		/// </summary>
		/// <param name="features">features which will be the members</param>
		public void setMembers(gml.FeatureAssociationType[] features)
		{
			featureMember=features;
		}
		/// <summary>
		/// Adds specified features to existing members of this collection.
		/// </summary>
		/// <param name="features">feature members to add to the collection</param>
		public void addMembers(gml.FeatureAssociationType[] features)
		{
			if(featureMember==null) 
			{
				featureMember=features;
				return;
			}
			long total= featureMember.Length + features.Length;
			gml.FeatureAssociationType[] temp = new FeatureAssociationType[total]; 
			featureMember.CopyTo(temp,0);
			features.CopyTo(temp,featureMember.Length);
			featureMember=temp;
		}
	}
	#endregion

	#region feature association
	/// <summary>
	/// Array of this class instances serve as items on
	/// gml.AbstractFeatureCollectionType.featureMember
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	[XmlRoot("featureMember", Namespace="http://www.opengis.net/gml", IsNullable=false)]
	//must include any derived custom class here or at runtime later
	public class FeatureAssociationType : gml.AssociationAttributeGroup 
	{
		
		/// <summary>
		/// enclose either gml.Feature or gml.FeatureCollection as a member
		/// </summary>
		public gml.AbstractFeatureType Item;
		//and ... any derivation of gml.AbstractFeatureType?
	
		/// <summary>
		/// Constructs empty FeatureAssociationType
		/// </summary>
		public FeatureAssociationType(){}
		/// <summary>
		/// Constructs FeatureAssociationType with new member
		/// </summary>
		/// <param name="newItem">FeatureType to be set as member</param>
		public FeatureAssociationType(gml.AbstractFeatureType newItem)
		{
			Item = newItem;
		}
	}
	#endregion

	#region basic geometry properties

	//TODO : create superclass for GeometryProperty, this is not really a correct derivation by restriction

	/// <summary>
	/// simple geometric property encapsulates a geometry element
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	[XmlRoot("geometryProperty", Namespace="http://www.opengis.net/gml", IsNullable=false)]
	[XmlIncludeAttribute(typeof(MultiGeometryPropertyType))]
	[XmlIncludeAttribute(typeof(MultiPolygonPropertyType))]
	[XmlIncludeAttribute(typeof(MultiLineStringPropertyType))]
	[XmlIncludeAttribute(typeof(MultiPointPropertyType))]
	[XmlIncludeAttribute(typeof(LineStringPropertyType))]
	[XmlIncludeAttribute(typeof(PolygonPropertyType))]
	[XmlIncludeAttribute(typeof(PointPropertyType))]
//	[XmlIncludeAttribute(typeof(NullGeometryPropertyType))] //not gml spec
	public class GeometryPropertyType : gml.AssociationAttributeGroup , IComparable 
	{
		/// <summary>
		/// Geometry element encapsulated by this property.
		/// </summary>
		[XmlElement("Point", typeof(gml.PointType))]
		[XmlElement("LineString", typeof(gml.LineStringType))]
		[XmlElement("LinearRing", typeof(gml.LinearRingType))]
		[XmlElement("Polygon", typeof(gml.PolygonType))]
		[XmlElement("MultiPoint", typeof(gml.MultiPointType))]
		[XmlElement("MultiLineString", typeof(gml.MultiLineStringType))]
		[XmlElement("MultiPolygon", typeof(gml.MultiPolygonType))]
		//or any derivation of gml.AbstractGeometryType
		public gml.AbstractGeometryType Item;

		/// <summary>
		/// Constructs empty GeometryPropertyType
		/// </summary>
		public GeometryPropertyType()	{}
		/// <summary>
		/// Constructs GeometryPropertyType which encapsulates a GeometryType
		/// </summary>
		/// <param name="geom">GeometryType as Item of this property</param>
		public GeometryPropertyType(gml.AbstractGeometryType geom)
		{
			Item = geom;
		}

		[XmlIgnore]
		protected virtual int objcomp
		{
			get{return 0;}
		}
		public int CompareTo(object obj)
		{
			if(obj==null || obj==System.DBNull.Value) return -1;
			if(!typeof(GeometryPropertyType).IsInstanceOfType(obj)) return -1;
			if(this.objcomp > ((GeometryPropertyType)obj).objcomp) 
			{
				return 1;
			}
			else if(this.objcomp == ((GeometryPropertyType)obj).objcomp) 
			{
				return 0;
			}
			return -1;
		}
		public override bool Equals(object obj)
		{
			if(CompareTo(obj)==0) return true;
			return false;
		}
		public override int GetHashCode()
		{
			return base.GetHashCode ();
		}
		public override string ToString()
		{
			return this.GetType().Name;
		}

	}

//	/// <summary>
//	/// this is not gml spec
//	/// </summary>
//	[Serializable]
//	[XmlType(Namespace="http://www.opengis.net/gml",IncludeInSchema = false)]
//	[XmlRoot("empty", Namespace="http://www.opengis.net/gml", IsNullable=false)]
//	public class NullGeometryPropertyType : GeometryPropertyType 
//	{
//		public NullGeometryPropertyType()	{}
//	}

	/// <summary>
	/// Encapsulates a single point to represent position, location, or centerOf properties.
	/// </summary>
	[Serializable]
	[XmlType(Namespace="http://www.opengis.net/gml")]
	[XmlRoot("pointProperty", Namespace="http://www.opengis.net/gml", IsNullable=false)]
	public class PointPropertyType : GeometryPropertyType 
	{
		//Item already in the base class
		/// <summary>
		/// Constructs empty PointProperty
		/// </summary>
		public PointPropertyType()	{	}
		/// <summary>
		/// Constructs PointProperty which encapsulates a PointType.
		/// </summary>
		/// <param name="aPoint">PointType to be set as Item for this property</param>
		public PointPropertyType(gml.PointType aPoint) : base(aPoint){}

		[XmlIgnore]
		protected override int objcomp{get{return 10;}}	
	}
	/// <summary>
	/// Encapsulates a single point to represent location property. Alias for pointProperty
	/// </summary>
	public class location : PointPropertyType {	public location(){ } }
	/// <summary>
	/// Encapsulates a single point to represent centerOf property. Alias for pointProperty
	/// </summary>
	public class centerOf : PointPropertyType {	public centerOf(){ } }
	/// <summary>
	/// Encapsulates a single point to represent position property. Alias for pointProperty
	/// </summary>
	public class position : PointPropertyType {	public position(){ } }

⌨️ 快捷键说明

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