Hi,
The below given snippet may be useful.
IMap pMap = null;IMxDocument pDoc = null;
pDoc = clsGlobal.pApp.Document as IMxDocument; pMap = pDoc.FocusMap;
IGraphicsContainer graphicsContainer ; pMap = pDoc.FocusMap; graphicsContainer = pMap.Layer[0] as IGraphicsContainer;//Assuming that layer[0] will be a graphic layer graphicsContainer.Reset(); IElement element = graphicsContainer.Next(); while (element != null) { if (element is IPolygonElement) {
IElement polyElm = element as IElement;
IGeometry geom = polyElm.Geometry;//add the task to do } element = graphicsContainer.Next(); }
var layer = this.MyMap.Layers["MyLayer"] as ArcGISLocalFeatureLayer; FeatureTemplate lineLayerTemplate = null; if (layer.LayerInfo.Templates != null && layer.LayerInfo.Templates.Count > 0) { lineLayerTemplate = layer.LayerInfo.Templates.FirstOrDefault().Value; } var featureSet = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Line); if (lineLayerTemplate != null && lineLayerTemplate.PrototypeAttributes != null) { foreach (var prototypeAttribute in lineLayerTemplate.PrototypeAttributes) { // the purpose of this is to create the columns that will apper in the shp file featureSet.DataTable.Columns.Add(new DataColumn(prototypeAttribute.Key as String)); } } foreach (var graphic in layer.Graphics) { var newPaths = new List<LineString>(); foreach (var path in (graphic.Geometry as Polyline).Paths) { var vertices = new List<Coordinate>(); for (int i = 0; i < path.Count; i++) { vertices.Add(new Coordinate(path.X,path.Y,path.Z,path.M)); } // LineString is from DotSpatial...like a PolyLine in Runtime var newPath = new LineString(vertices); newPaths.Add(newPath); } // Multiline is from DotSpatial var geom = new MultiLineString(newPaths); var feature = featureSet.AddFeature(geom); feature.DataRow.BeginEdit(); foreach (var attribute in graphic.Attributes) { feature.DataRow[attribute.Key] = attribute.Value; } feature.DataRow.EndEdit(); } featureSet.Projection = ProjectionInfo.FromEpsgCode(layer.SpatialReference.WKID); featureSet.SaveAs(@C:\shptest.shp,true);
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.