/// <summary> /// If the feature type is specified, then this will automatically generate a new feature from the specified coordinates. /// This will not work unless the featuretype is specified. /// </summary> /// <param name="self">This IFeatureList</param> /// <param name="points"> /// The list or array of coordinates to build into a new feature. /// If the feature type is point, then this will create separate features for each coordinate. /// For polygons, all the points will be assumed to be in the shell. /// </param> /// <exception cref="UnspecifiedFeaturetypeException">Thrown if the current FeatureType for the shapefile is unspecified.</exception> public static void Add(this IFeatureList self, IEnumerable <Coordinate> points) { switch (self.Parent.FeatureType) { case FeatureType.Unspecified: throw new UnspecifiedFeaturetypeException(); case FeatureType.Point: self.SuspendEvents(); foreach (Coordinate point in points) { self.Add(new Feature(new Point(point))); } self.ResumeEvents(); break; case FeatureType.Line: self.Add(new Feature(new LineString(points as Coordinate[]))); break; case FeatureType.Polygon: self.Add(new Feature(new Polygon(new LinearRing(points as Coordinate[])))); break; case FeatureType.MultiPoint: self.Add(new Feature(new MultiPoint(points.CastToPointArray()))); break; } }
/// <summary> /// If the feature type is specified, then this will automatically generate a new feature from the specified coordinates. /// This will not work unless the featuretype is specified. /// </summary> /// <param name="self">This IFeatureList</param> /// <param name="points"> /// The list or array of coordinates to build into a new feature. /// If the feature type is point, then this will create separate features for each coordinate. /// For polygons, all the points will be assumed to be in the shell. /// </param> /// <exception cref="UnspecifiedFeaturetypeException">Thrown if the current FeatureType for the shapefile is unspecified.</exception> public static void Add(this IFeatureList self, IEnumerable <Coordinate> points) { if (self.Parent.FeatureType == FeatureType.Unspecified) { throw new UnspecifiedFeaturetypeException(); } if (self.Parent.FeatureType == FeatureType.Point) { self.SuspendEvents(); foreach (Coordinate point in points) { self.Add(new Feature(new Point(point))); } self.ResumeEvents(); } if (self.Parent.FeatureType == FeatureType.Line) { self.Add(new Feature(new LineString(points))); } if (self.Parent.FeatureType == FeatureType.Polygon) { self.Add(new Feature(new Polygon(points))); } if (self.Parent.FeatureType == FeatureType.MultiPoint) { self.Add(new Feature(new MultiPoint(points))); } }
/// <summary> /// Creates a new FeatureSet using a given list of IFeatures. /// This will copy the existing features, rather than removing /// them from their parent feature set. /// </summary> /// <param name="inFeatures">The list of IFeatures</param> public FeatureSet(IList<IFeature> inFeatures) { _progressHandler = Components.DataManager.DefaultDataManager.ProgressHandler; _progressMeter = new ProgressMeter(_progressHandler); _dataTable = new DataTable(); _dataTable.RowDeleted += DataTableRowDeleted; if (inFeatures.Count > 0) { FeatureType = inFeatures[0].FeatureType; } _features = new FeatureList(this); if (inFeatures.Count > 0) { if (inFeatures[0].ParentFeatureSet != null) { CopyTableSchema(inFeatures[0].ParentFeatureSet); } else { if (inFeatures[0].DataRow != null) { CopyTableSchema(inFeatures[0].DataRow.Table); } } _features.SuspendEvents(); foreach (IFeature f in inFeatures) { IFeature myFeature = f.Copy(); _features.Add(myFeature); } _features.ResumeEvents(); } }
/// <summary> /// Initializes a new instance of the <see cref="FeatureSet"/> class. /// Creates a new FeatureSet using a given list of IFeatures. /// This will copy the existing features, rather than removing /// them from their parent feature set. /// </summary> /// <param name="inFeatures"> /// The list of IFeatures /// </param> public FeatureSet(IList<IFeature> inFeatures) : this() { _dataTable = new DataTable(); _dataTable.RowDeleted += DataTableRowDeleted; if (inFeatures.Count > 0) { FeatureType = inFeatures[0].FeatureType; } _features = new FeatureList(this); if (inFeatures.Count > 0) { if (inFeatures[0].ParentFeatureSet != null) { CopyTableSchema(inFeatures[0].ParentFeatureSet); } else { if (inFeatures[0].DataRow != null) { CopyTableSchema(inFeatures[0].DataRow.Table); } } _features.SuspendEvents(); foreach (IFeature f in inFeatures) { IFeature myFeature = f.Copy(); _features.Add(myFeature); } _features.ResumeEvents(); } }
protected void FeaturesFromVertices() { _features = new FeatureList(this); _features.IncludeAttributes = false; // load these on demand later. _features.SuspendEvents(); for (int shp = 0; shp < ShapeIndices.Count; shp++) { _features.Add(GetFeature(shp)); } _features.ResumeEvents(); _features.IncludeAttributes = true; // from this point on, any features that get added will also add a datarow to the data-Table. }