private void OpenLayer() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Shapefiles|*.shp"; if (ofd.ShowDialog() != DialogResult.OK) return; FeatureSet fs = new FeatureSet(); fs.Open(ofd.FileName); geoMap1.Layers.Add(fs); FeatureSet newFeature = new FeatureSet(); newFeature.CopyTableSchema(fs); foreach(Feature f in fs.Features) { newFeature.Features.Add(f); } bool stop = true; }
/// <summary> /// As an example, choosing myFeatureLayer.SelectedFeatures.ToFeatureSet creates a new set. /// </summary> /// <returns>An in memory featureset that has not yet been saved to a file in any way.</returns> public FeatureSet ToFeatureSet() { FeatureSet fs = new FeatureSet(ToList()); // the output features will be copied. if (fs.Features.Count == 0) { if (_filter.FeatureList.Count > 0) { fs.CopyTableSchema(_filter.FeatureList[0].ParentFeatureSet); } } return fs; }
/// <summary> /// This tests each feature of the input /// </summary> /// <param name="self">This featureSet</param> /// <param name="other">The featureSet to perform intersection with</param> /// <param name="joinType">The attribute join type</param> /// <param name="progHandler">A progress handler for status messages</param> /// <returns>An IFeatureSet with the intersecting features, broken down based on the join Type</returns> public static IFeatureSet Intersection(this IFeatureSet self, IFeatureSet other, FieldJoinType joinType, IProgressHandler progHandler) { IFeatureSet result = null; ProgressMeter pm = new ProgressMeter(progHandler, "Calculating Intersection", self.Features.Count); if (joinType == FieldJoinType.All) { result = CombinedFields(self, other); // Intersection is symetric, so only consider I X J where J <= I int i=0; foreach(IFeature selfFeature in self.Features) { List<IFeature> potentialOthers = other.Select(selfFeature.Envelope); foreach (IFeature otherFeature in potentialOthers) { selfFeature.Intersection(otherFeature, result, joinType); } pm.CurrentValue = i; i++; } pm.Reset(); } if (joinType == FieldJoinType.LocalOnly) { result = new FeatureSet(); result.CopyTableSchema(self); result.FeatureType = self.FeatureType; IFeature union; pm = new ProgressMeter(progHandler, "Calculating Union", other.Features.Count); if(other.Features != null && other.Features.Count > 0) { union = other.Features[0]; for(int i = 1; i < other.Features.Count; i++) { union = union.Union(other.Features[i]); pm.CurrentValue = i; } pm.Reset(); pm = new ProgressMeter(progHandler, "Calculating Intersections", self.NumRows()); Extent otherEnvelope = new Extent(union.Envelope); for (int shp = 0; shp < self.ShapeIndices.Count; shp++) { if (!self.ShapeIndices[shp].Extent.Intersects(otherEnvelope)) continue; IFeature selfFeature = self.GetFeature(shp); selfFeature.Intersection(union, result, joinType); pm.CurrentValue = shp; } pm.Reset(); } } if (joinType == FieldJoinType.ForeignOnly) { result = new FeatureSet(); result.CopyTableSchema(other); IFeature union; if (self.Features != null && self.Features.Count > 0) { pm = new ProgressMeter(progHandler, "Calculating Union", self.Features.Count); union = self.Features[0]; for (int i = 1; i < self.Features.Count; i++) { union = union.Union(self.Features[i]); pm.CurrentValue = i; } pm.Reset(); if (other.Features != null) { pm = new ProgressMeter(progHandler, "Calculating Intersection", other.Features.Count); int j = 0; foreach (IFeature otherFeature in other.Features) { IFeature test = otherFeature.Intersection(union, result, joinType); if (test.BasicGeometry != null) { result.Features.Add(test); } pm.CurrentValue = j; j++; } } pm.Reset(); } } return result; }
/// <summary> /// Handles the situation for exporting the layer as a new source. /// </summary> protected override void OnExportData() { ExportFeature frmExport = new ExportFeature(); frmExport.Filename = DataSet.Filename; if (frmExport.ShowDialog() != DialogResult.OK) return; if (frmExport.FeaturesIndex == 0) { DataSet.SaveAs(frmExport.Filename, true); } else if (frmExport.FeaturesIndex == 1) { FeatureSet fs = _selection.ToFeatureSet(); fs.SaveAs(frmExport.Filename, true); } else if (frmExport.FeaturesIndex == 2) { List<IFeature> features = DataSet.Select(MapFrame.Extents); FeatureSet fs = new FeatureSet(features); if (fs.Features.Count == 0) { fs.CopyTableSchema(DataSet); } fs.SaveAs(frmExport.Filename, true); } AddToMapDialog dlgAddLayer = new AddToMapDialog(); if (dlgAddLayer.ShowDialog() != DialogResult.OK) return; if (dlgAddLayer.AddLayer == false) return; IFeatureLayer newLayer = OpenFile(frmExport.Filename) as IFeatureLayer; IGroup parent = GetParentItem() as IGroup; if (parent != null) { int index = parent.IndexOf(this); if (newLayer != null) { parent.Insert(index + 1, newLayer); } } }