public override bool DeCompose(out IArray iarray_0) { bool flag; iarray_0 = null; IGeometryCollection mPGeometry = this.m_pGeometry as IGeometryCollection; if (mPGeometry.GeometryCount <= 1) { flag = false; } else { iarray_0 = new ESRI.ArcGIS.esriSystem.Array(); object value = Missing.Value; bool zAware = false; bool mAware = false; double zMin = 0; try { zAware = (mPGeometry as IZAware).ZAware; zMin = (mPGeometry as IZ).ZMin; } catch { } try { mAware = (mPGeometry as IMAware).MAware; } catch { } for (int i = 0; i < mPGeometry.GeometryCount; i++) { IGeometry geometry = mPGeometry.Geometry[i]; IGeometryCollection polylineClass = new Polyline() as IGeometryCollection; (polylineClass as IZAware).ZAware = zAware; (polylineClass as IMAware).MAware = mAware; polylineClass.AddGeometry(geometry, ref value, ref value); if (zAware) { (polylineClass as IZ).SetConstantZ(zMin); } (polylineClass as ITopologicalOperator).Simplify(); iarray_0.Add(polylineClass); } flag = true; } return(flag); }
public override void OnClick() { IHookActions hookActions = null; IBasicMap basicMap = null; //Get basic map and set hook actions if (m_hookHelper != null) { basicMap = m_hookHelper.FocusMap as IBasicMap; hookActions = m_hookHelper as IHookActions; } else if (m_globeHookHelper != null) { basicMap = m_globeHookHelper.Globe as IBasicMap; hookActions = m_globeHookHelper as IHookActions; } //Get feature selection ISelection selection = basicMap.FeatureSelection; //Get enumerator IEnumFeature enumFeature = selection as IEnumFeature; enumFeature.Reset(); //Set first feature IFeature feature; feature = enumFeature.Next(); //Loop though the features IArray array = new ESRI.ArcGIS.esriSystem.Array(); IStringArray sArray = new StrArray(); while (feature != null) { //Add feature to array array.Add(feature.Shape); //Add the value of the first field to the string array sArray.Add(feature.get_Value(0).ToString()); //Set next feature feature = enumFeature.Next(); } //If the action is supported perform the action if (hookActions.get_ActionSupportedOnMultiple(array, esriHookActions.esriHookActionsLabel)) { hookActions.DoActionWithNameOnMultiple(array, sArray, esriHookActions.esriHookActionsLabel); } }
public override void OnClick() { IHookActions hookActions = null; IBasicMap basicMap = null; //Get basic map and set hook actions if (m_hookHelper != null) { basicMap = m_hookHelper.FocusMap as IBasicMap; hookActions = m_hookHelper as IHookActions; } else if (m_globeHookHelper != null) { basicMap = m_globeHookHelper.Globe as IBasicMap; hookActions = m_globeHookHelper as IHookActions; } //Get feature selection ISelection selection = basicMap.FeatureSelection; //Get enumerator IEnumFeature enumFeature = selection as IEnumFeature; enumFeature.Reset(); //Set first feature IFeature feature; feature = enumFeature.Next(); //Loop though the features IArray array = new ESRI.ArcGIS.esriSystem.Array(); while (feature != null) { //Add feature to array array.Add(feature.Shape); //Set next feature feature = enumFeature.Next(); } //If the action is supported perform the action if (hookActions.get_ActionSupportedOnMultiple(array, esriHookActions.esriHookActionsFlash)) hookActions.DoActionOnMultiple(array, esriHookActions.esriHookActionsFlash); }
public override void OnClick() { int i; IFeature feature; if (Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate == null || Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer == null) { return; } IFeatureLayer featureLayer = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer; esriGeometryType shapeType = featureLayer.FeatureClass.ShapeType; CmdEditCopy.m_pEnumFeature.Reset(); IFeature item = CmdEditCopy.m_pEnumFeature.Next(); IFeatureClass featureClass = featureLayer.FeatureClass; IWorkspaceEdit workspace = (featureClass as IDataset).Workspace as IWorkspaceEdit; workspace.StartEditOperation(); IArray arrayClass = new ESRI.ArcGIS.esriSystem.Array(); object value = Missing.Value; for (i = 0; i < CmdEditCopy.m_pFeatureList.Count; i++) { item = CmdEditCopy.m_pFeatureList[i]; if (item.Shape.GeometryType == shapeType) { feature = featureClass.CreateFeature(); try { Yutai.ArcGIS.Common.Editor.Editor.CopyRowEx(item, feature); feature.Store(); arrayClass.Add(feature); } catch (Exception exception) { CErrorLog.writeErrorLog(this, exception, ""); } } else if ((item.Shape.GeometryType != esriGeometryType.esriGeometryPolygon ? false : shapeType == esriGeometryType.esriGeometryPolyline)) { feature = featureClass.CreateFeature(); try { IPolyline polylineClass = new Polyline() as IPolyline; IPolygon shape = item.Shape as IPolygon; for (int j = 0; j < (shape as IGeometryCollection).GeometryCount; j++) { ISegmentCollection geometry = (shape as IGeometryCollection).Geometry[j] as ISegmentCollection; IPath pathClass = new Path() as IPath; (pathClass as ISegmentCollection).AddSegmentCollection(geometry); (polylineClass as IGeometryCollection).AddGeometry(pathClass, ref value, ref value); } feature.Shape = polylineClass; Yutai.ArcGIS.Common.Editor.Editor.CopyRow(item, feature); feature.Store(); arrayClass.Add(feature); } catch (Exception exception1) { CErrorLog.writeErrorLog(this, exception1, ""); } } item = CmdEditCopy.m_pEnumFeature.Next(); } workspace.StopEditOperation(); _context.FocusMap.ClearSelection(); for (i = 0; i < arrayClass.Count; i++) { _context.FocusMap.SelectFeature(Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer, arrayClass.Element[i] as IFeature); } _context.ActiveView.Refresh(); }
public void ChangelayoutAndSave(string mxdPath, string templatePath, string savePath) { // IMapDocument pDoc = new MapDocumentClass(); IMxdContents pMxdC; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(mxdPath, ""); pMxdC = pMapDocument.PageLayout as IMxdContents; IMap pMap = pMxdC.ActiveView.FocusMap; //this.axPageLayoutControl1.ActiveView.FocusMap; IPageLayout pPageLayout = pMxdC.PageLayout; //this.axPageLayoutControl1.PageLayout; //读取新模板 IMapDocument pNewDoc = new MapDocumentClass(); pNewDoc.Open(templatePath, ""); IMap pTempMap; IPageLayout pTempPagelayout = pNewDoc.PageLayout; pTempMap = pNewDoc.get_Map(0); IPage pTempPage = pTempPagelayout.Page; IPage pCurPage = pPageLayout.Page; //替换单位 pCurPage.Units = pTempPage.Units; //exchange page orientation pCurPage.Orientation = pTempPage.Orientation; //替换页面尺寸 Double dWidth = 0; Double dHeight = 0; pTempPage.QuerySize(out dWidth, out dHeight); pCurPage.PutCustomSize(dWidth, dHeight); //删除当前Layout中除了mapframe外的所有elements IGraphicsContainer pGraphicsCont; IElement pElement; pGraphicsCont = pPageLayout as IGraphicsContainer; pGraphicsCont.Reset(); pElement = pGraphicsCont.Next(); IMapFrame pMapFrame = null; IElement pMapFrameElement = null; while (pElement != null) { if (pElement is IMapFrame) { // Console.WriteLine(pElement.Geometry.GeometryType.ToString() + '0'); pMapFrameElement = pElement; pMapFrame = pElement as IMapFrame; pMapFrame.Border = null; } else { pGraphicsCont.DeleteElement(pElement); pGraphicsCont.Reset(); } pElement = pGraphicsCont.Next(); } //遍历模板的PageLayout中的所有元素,并且替换当前PageLayout中的所有元素 IGraphicsContainer pTempGraphicsCont; pTempGraphicsCont = pTempPagelayout as IGraphicsContainer; pTempGraphicsCont.Reset(); pElement = pTempGraphicsCont.Next(); IArray pArray; pArray = new ESRI.ArcGIS.esriSystem.Array(); while (pElement != null) { if (pElement is IMapFrame) { pMapFrameElement.Geometry = pElement.Geometry; } else { if (pElement is IMapSurroundFrame) { IMapSurround pTempMapSurround; IMapSurroundFrame pTempMapSurroundFrame = pElement as IMapSurroundFrame; pTempMapSurroundFrame.MapFrame = pMapFrame; pTempMapSurround = pTempMapSurroundFrame.MapSurround; pMap.AddMapSurround(pTempMapSurround); } pArray.Add(pElement); } pElement = pTempGraphicsCont.Next(); } int pElementCount = pArray.Count; //将模板PageLayout中的其它元素(除了MapFrameElement和MapSurroundFrame外的元素)添加到当前PageLayout中去 for (int i = 0; i < pElementCount; i++) { pGraphicsCont.AddElement(pArray.get_Element(pElementCount - 1 - i) as IElement, 0); // this.axPageLayoutControl1.ActiveView.Refresh(); } // pMxdC.ActiveView.Refresh(); pNewDoc.Close(); pMapDocument = new MapDocumentClass(); pMapDocument.New(savePath); // IActiveView pActiveView = this.axPageLayoutControl1.ActiveView.FocusMap as IActiveView; pMapDocument.ReplaceContents(pMxdC); pMapDocument.Save(true, true); pMapDocument.Close(); }
//找到包含所要移动的节点的图形,在该过程里面对m_FeatArray进行了赋值 public static void SelectByShapeTop(IFeatureLayer pFeaturelayer, IGeometry pGeo, esriSpatialRelEnum SpatialRel, bool blnShow, esriSelectionResultEnum Method) { ITopologicalOperator pTopo = null; //对于非要素层不能进行选择 m_inUse = blnShow; //用来查找的图形的复制品,避免对图形的修改(SimplyFy会更改结点顺序) IGeometry pGeometry = default(IGeometry); IClone pClone = pGeo as IClone; pGeometry = pClone.Clone() as IGeometry; IFeatureSelection pFeatureSelection = pFeaturelayer as IFeatureSelection; //判断是否跳出过程 bool pBlnExit = false; //输入对象为空时清空选择集 if (pGeometry == null) { pBlnExit = true; } //输入图形为空时清空选择集 if (pGeometry.IsEmpty) { pBlnExit = true; } switch (pGeometry.GeometryType) { case esriGeometryType.esriGeometryEnvelope: IEnvelope pEnve = null; pEnve = pGeometry as IEnvelope; if (pEnve.Height == 0 | pEnve.Width == 0) { pBlnExit = true; } break; case esriGeometryType.esriGeometryPolygon: IPolygon pPolygon = null; pPolygon = pGeometry as IPolygon; if (pPolygon.Length == 0) { pBlnExit = true; } break; case esriGeometryType.esriGeometryPolyline: IPolyline pPolyLine = null; pPolyLine = pGeometry as IPolyline; if (pPolyLine.Length == 0) { pBlnExit = true; } break; } if (pBlnExit == true) { if (blnShow == true) { if (Method == esriSelectionResultEnum.esriSelectionResultNew) { //在每次选择前清空上次的选择集 pFeatureSelection.Clear(); } } else { if (Method == esriSelectionResultEnum.esriSelectionResultNew) { m_featArray = new ESRI.ArcGIS.esriSystem.Array(); } } return; } if (pGeometry is ITopologicalOperator) { pTopo = pGeometry as ITopologicalOperator; pTopo.Simplify(); } //构造空间查询条件 ISpatialFilter pSpatialfilter = null; pSpatialfilter = new SpatialFilter(); pSpatialfilter.Geometry = pGeometry; pSpatialfilter.GeometryField = pFeaturelayer.FeatureClass.ShapeFieldName; pSpatialfilter.SpatialRel = SpatialRel; IFeatureCursor pFeatCursor = null; if (blnShow) { //高亮显示 pFeatureSelection.SelectFeatures(pSpatialfilter, Method, false); } else { //将结果加到FeaureCursor中 pFeatCursor = pFeaturelayer.Search(pSpatialfilter, false); IFeature pFeature = null; pFeature = pFeatCursor.NextFeature(); int i = 0; IArray pTempArray = null; switch (Method) { case esriSelectionResultEnum.esriSelectionResultNew: m_featArray = new ESRI.ArcGIS.esriSystem.Array(); while (pFeature != null) { m_featArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } break; case esriSelectionResultEnum.esriSelectionResultAdd: while (pFeature != null) { for (i = 0; i <= m_featArray.Count - 1; i++) { if (object.ReferenceEquals(m_featArray.get_Element(i), pFeature)) { break; } } if (i == m_featArray.Count) { m_featArray.Add(pFeature); } pFeature = pFeatCursor.NextFeature(); } break; case esriSelectionResultEnum.esriSelectionResultSubtract: while ((pFeature != null)) { for (i = 0; i <= m_featArray.Count - 1; i++) { if (object.ReferenceEquals(m_featArray.get_Element(i), pFeature)) { break; } } if (i < m_featArray.Count) { m_featArray.Remove(i); } pFeature = pFeatCursor.NextFeature(); } break; case esriSelectionResultEnum.esriSelectionResultAnd: pTempArray = new ESRI.ArcGIS.esriSystem.Array(); while ((pFeature != null)) { for (i = 0; i <= m_featArray.Count - 1; i++) { if (object.ReferenceEquals(m_featArray.get_Element(i), pFeature)) { pTempArray.Add(pFeature); break; } } pFeature = pFeatCursor.NextFeature(); } m_featArray = pTempArray; break; case esriSelectionResultEnum.esriSelectionResultXOR: while ((pFeature != null)) { for (i = 0; i <= m_featArray.Count - 1; i++) { if (object.ReferenceEquals(m_featArray.get_Element(i), pFeature)) { break; } } if (i == m_featArray.Count) { m_featArray.Add(pFeature); } else { m_featArray.Remove(i); } pFeature = pFeatCursor.NextFeature(); } break; default: m_featArray = new ESRI.ArcGIS.esriSystem.Array(); break; } } }
public static void ShowAllVertex(IFeatureLayer pFeatLyr) { m_vertexGeoBag = null; if (pFeatLyr == null) { return; } IFeatureCursor pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr); if (pFeatureCursor == null) { return; } IFeature pTFeature = null; //得到要显示节点的地物 pTFeature = pFeatureCursor.NextFeature(); if (pTFeature == null) { return; } //只选中一个地物进行节点移动 m_Map.ClearSelection(); m_Map.SelectFeature(pFeatLyr as ILayer, pTFeature); m_activeView.Refresh(); //如果为点状地物,不显示节点 if (pTFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { return; } IArray pFeatureArray = null; pFeatureArray = new ESRI.ArcGIS.esriSystem.Array(); pFeatureArray.Add(pTFeature); //绘图符号初始化 SymbolInit(); IFeature pFeature = default(IFeature); IPointCollection pPointCol = default(IPointCollection); IPoint pPoint = default(IPoint); int i = 0; int j = 0; m_vertexGeoBag = new GeometryBagClass(); for (i = 0; i <= pFeatureArray.Count - 1; i++) { pFeature = pFeatureArray.get_Element(i) as IFeature; //获取图形边界的点集 pPointCol = pFeature.ShapeCopy as IPointCollection; for (j = 0; j <= pPointCol.PointCount - 1; j++) { pPoint = pPointCol.get_Point(j); if (j == 0 | j == pPointCol.PointCount - 1) { //两个端点的ID设为10 pPoint.ID = 10; } else { //中间点的ID设为100 pPoint.ID = 100; } IColor pColor = null; object obj = Type.Missing; //显示节点 if (pPoint == pHitPnt) { DisplayGraphic(pPoint, pColor, m_selPointSym as ISymbol); } if (j == 0 || j == pPointCol.PointCount - 1) { DisplayGraphic(pPoint, pColor, m_endPointSym as ISymbol); } else { DisplayGraphic(pPoint, pColor, m_vertexSym as ISymbol); } m_vertexGeoBag.AddGeometry(pPoint, ref obj, ref obj); } } }
private IArray method_2(IGeometry igeometry_0, IGeometry igeometry_1) { IArray array; if (!(igeometry_0 == null ? false : igeometry_1 != null)) { array = null; } else if (igeometry_0.GeometryType == esriGeometryType.esriGeometryPolyline) { IGeometry geometry = ((ITopologicalOperator)igeometry_0).Intersect(igeometry_1, esriGeometryDimension.esriGeometry0Dimension); if (geometry != null) { ((ITopologicalOperator)geometry).Simplify(); IEnumVertex enumVertices = ((IPointCollection)geometry).EnumVertices; if (enumVertices != null) { IPolycurve2 igeometry0 = (IPolycurve2)igeometry_0; if (igeometry0.SplitAtPoints(enumVertices, true, true, -1).SplitHappened) { IGeometryCollection geometryCollection = (IGeometryCollection)igeometry0; IArray arrayClass = new ESRI.ArcGIS.esriSystem.Array(); try { bool zAware = false; bool mAware = false; double zMin = 0; try { zAware = (igeometry_0 as IZAware).ZAware; zMin = (igeometry_0 as IZ).ZMin; } catch { } try { mAware = (igeometry_0 as IMAware).MAware; } catch { } for (int i = 0; i < geometryCollection.GeometryCount; i++) { IGeometry geometry1 = geometryCollection.Geometry[i]; IGeometryCollection polylineClass = new Polyline() as IGeometryCollection; (polylineClass as IZAware).ZAware = zAware; (polylineClass as IMAware).MAware = mAware; polylineClass.AddGeometries(1, ref geometry1); if (zAware) { (polylineClass as IZ).SetConstantZ(zMin); } (polylineClass as ITopologicalOperator).Simplify(); arrayClass.Add(polylineClass); } } catch (Exception exception) { Trace.WriteLine(exception); } array = arrayClass; } else { array = null; } } else { array = null; } } else { array = null; } } else { array = null; } return(array); }