//红色线 public static void ViewPolylines(IMapControl4 pMapControl, List <CPolyline> cpllt) { //设置线段属性 ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 1; pSimpleLineSymbol.Color = CHelpFunc.GenerateIRgbColor(255, 0, 0) as IColor; //生成线段 IElementCollection pEleCol = new ElementCollectionClass(); for (int i = 0; i < cpllt.Count; i++) { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; IElement pElement = pLineElement as IElement; pElement.Geometry = cpllt[i].pPolyline; pEleCol.Add(pElement, 0); } //显示线段 IGraphicsContainer pGra = pMapControl.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; pGra.AddElements(pEleCol, 5); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void LabelQueryInfo(string name, string strContent, IPoint pt, IMap pMap, bool isRemoveLast) { //获取并激活Graphic标注图层 if (pt == null) { return; } IActiveView pActiveView = pMap as IActiveView; ICompositeGraphicsLayer pCompositeGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer; //WeatherLabel标记组,通过ArcMap的Layers Properties的Annotation group可以看到 IGraphicsLayer pGraphicsLayer = pCompositeGraphicsLayer.FindLayer("WeatherLabel"); pMap.ActiveGraphicsLayer = pGraphicsLayer as ILayer; pGraphicsLayer.Activate(pActiveView.ScreenDisplay); IGraphicsContainer pGraphicsContainer = pGraphicsLayer as IGraphicsContainer;//转换到图形容器接口 IElementCollection pElementCollection = new ElementCollectionClass(); AddBalloonCalloutLabel(name, strContent, pt, pElementCollection);//我们需要一个新的私有函数来实现设置标签元素背景,BalloonCallout对象 //添加标注 if (isRemoveLast == true) { pGraphicsContainer.DeleteAllElements(); } pGraphicsContainer.AddElements(pElementCollection, 1000); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds); }
// ********************* // Author: Erika Kamptner // Created Date: 3/13/2017 // Description: The LabelFeatures function is used throughout the LoadCSCLFeatureClass method by applying a string // expression to the pGeoFeatureLayer. // // ************************** public static void LabelFeatures(IGeoFeatureLayer pGeoFeatureLayer, string strExpression) { IAnnotateLayerPropertiesCollection pAnnoLayer; pAnnoLayer = pGeoFeatureLayer.AnnotationProperties; IAnnotateLayerProperties pAnnoLayerProps; pAnnoLayerProps = new LabelEngineLayerProperties() as IAnnotateLayerProperties; IElementCollection placedElements = new ElementCollectionClass(); IElementCollection unplacedElements = new ElementCollectionClass(); pAnnoLayer.QueryItem(0, out pAnnoLayerProps, out placedElements, out unplacedElements); ILabelEngineLayerProperties pLabelProps; pLabelProps = (ILabelEngineLayerProperties)pAnnoLayerProps; pLabelProps.Symbol.Color = SetColor(0, 0, 0); pLabelProps.Expression = strExpression; }
public void LabelQueryInfo(string name, string strContent, IPoint pt, IMap pMap, bool isRemoveLast) { //获取并激活Graphic标注图层 if (pt == null) return; IActiveView pActiveView = pMap as IActiveView; ICompositeGraphicsLayer pCompositeGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer; //WeatherLabel标记组,通过ArcMap的Layers Properties的Annotation group可以看到 IGraphicsLayer pGraphicsLayer = pCompositeGraphicsLayer.FindLayer("WeatherLabel"); pMap.ActiveGraphicsLayer = pGraphicsLayer as ILayer; pGraphicsLayer.Activate(pActiveView.ScreenDisplay); IGraphicsContainer pGraphicsContainer = pGraphicsLayer as IGraphicsContainer;//转换到图形容器接口 IElementCollection pElementCollection = new ElementCollectionClass(); AddBalloonCalloutLabel(name, strContent, pt, pElementCollection);//我们需要一个新的私有函数来实现设置标签元素背景,BalloonCallout对象 //添加标注 if (isRemoveLast == true) { pGraphicsContainer.DeleteAllElements(); } pGraphicsContainer.AddElements(pElementCollection, 1000); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds); }
private void BuildDisplacementLinks() { try { if (_App == null) { // Get the actual underlying COM type Type t = Type.GetTypeFromCLSID(typeof(AppRefClass).GUID); System.Object obj = Activator.CreateInstance(t); _App = obj as IApplication; } string masterText = this._form.cbMaster.SelectedItem.ToString(); string secondaryText = this._form.cbSecondLayer.SelectedItem.ToString(); DataTable mainTbl = MainErrorTable("MainTable", ""); string filter = "fClass = '" + masterText + "'"; DataRow[] foundRowsTo; foundRowsTo = mainTbl.Select(filter); int rowsCount = foundRowsTo.Length; string msg = "You have selected to process '" + rowsCount.ToString() + "' coordinates. Depending on your hardware configuration this process may take several minutes.\n Click on the 'OK' button to continue or the 'Cancel' button to terminate the process."; if (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { IsdutHourGlass theHourGlass = new IsdutHourGlass(this._App); theHourGlass.start("Processing " + rowsCount.ToString() + " Coordinates..."); double _fromX = 0; double _fromY = 0; double _toX = 0; double _toY = 0; string _toFClass = ""; int _objId = 0; IMxDocument mxDocument = _App.Document as IMxDocument; IMap map = mxDocument.FocusMap; IGraphicsContainer graphicsContainer = util.GraphicsHelper.get_GraphicsContainer(map); graphicsContainer.Reset(); graphicsContainer.DeleteAllElements(); //Get the link symbol from the adjustment extension IAdjustment adjustment = _App.FindExtensionByName("ESRI Adjustment Tools") as IAdjustment; IAdjustProperties adjustmentProperties = adjustment as IAdjustProperties; ILineSymbol linkSymbol = adjustmentProperties.DisplacementLinkSymbol; IElementCollection elements = new ElementCollectionClass(); for (int i = 0; i < adjustment.TransformationMethodCount; i++) { if (adjustment.get_TransformationMethod(i).Name == "Edge Snap") { adjustment.CurrentTransformationMethod = adjustment.get_TransformationMethod(i); break; } } foreach (DataRow dRowTo in foundRowsTo) { _objId = Convert.ToInt32(dRowTo[mainTbl.Columns.IndexOf("objId")]); _f1_id = Convert.ToInt32(dRowTo[mainTbl.Columns.IndexOf("fId")]); _toFClass = Convert.ToString(dRowTo[mainTbl.Columns.IndexOf("fClass")]); _toX = Convert.ToDouble(dRowTo[mainTbl.Columns.IndexOf("x")]); _toY = Convert.ToDouble(dRowTo[mainTbl.Columns.IndexOf("y")]); filter = "objId = " + _objId; filter = filter + " AND fClass = '" + secondaryText + "'"; DataRow[] foundRowsFrom; foundRowsFrom = mainTbl.Select(filter); foreach (DataRow dRowFrom in foundRowsFrom) { _fromX = Convert.ToDouble(dRowFrom[mainTbl.Columns.IndexOf("x")]); _fromY = Convert.ToDouble(dRowFrom[mainTbl.Columns.IndexOf("y")]); } //Create the polyline from two points IPoint fromPoint = new PointClass(); IPoint toPoint = new PointClass(); IPolyline polyLine = new PolylineClass(); IDisplacementLinkElement link = new DisplacementLinkElementClass(); fromPoint.ID = toPoint.ID = _objId; fromPoint.PutCoords(_fromX, _fromY); polyLine.FromPoint = fromPoint; toPoint.PutCoords(_toX, _toY); polyLine.ToPoint = toPoint; //Instantiate a new displacement link and set symbology link.Symbol = linkSymbol; IElement element = link as IElement; //Set the geometry and add to the elements collections element.Geometry = polyLine; elements.Add(element, 0); /* #region DELETE this - for testing only string line = ""; line = _objId.ToString() + "\t" + secondaryText + "\t" + _fromX.ToString() + "\t" + _fromY.ToString() + "\t" + this.cbMaster.SelectedItem.ToString() + "\t" + _toX.ToString() + "\t" + _toY.ToString(); tw.WriteLine(line); #endregion */ } this.CreateErrorLayer(masterText, secondaryText); graphicsContainer.AddElements(elements, 0); mxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); theHourGlass.end(); this._form.Close(); } } catch (Exception ex) { if (this._form != null) { this._form.Dispose(); this._form = null; } string msg = "Exception caught building the spacial adjustment links layer: " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace; MessageBox.Show(msg,"Build Links Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); util.Logger.Write(msg); } }
/// <summary> /// this method handles the call to update, delete or create a new feature from the windows form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CompilationFormEventHandler(object sender, CompilationLogEventArgs e) { IFeatureCursor pFeatureCursor = null; try { Debug.WriteLine(e.Action.ToString() + " " + e.LogNote); IFeatureClass pFeatureClass = m_pFeatureLayer.FeatureClass; IQueryFilter pQueryFilter = null; IEnumIDs pEnumIDs = null; IFeature pFeature = null; IGraphicsContainerSelect pGraphicsContSel = null; IEnumElement pEnumElement = null; IGeometry pGeom = null; IGeoDataset pGeodataset = null; IFeatureBuffer pFeatureBuffer = null; IFeatureSelection pFeatureSelection = null; IElementCollection pElemCollection = new ElementCollectionClass(); switch(e.Action) { case enumCompilationLogAction.create: try { pGraphicsContSel = (IGraphicsContainerSelect)m_pISDUTExt.FocusMap; //pMxDoc.FocusMap; pEnumElement = pGraphicsContSel.SelectedElements; pGeom = get_GraphicShape(pEnumElement,2,true,ref pElemCollection); pGeom.SpatialReference = m_pISDUTExt.FocusMap.SpatialReference; pGeodataset = (IGeoDataset)pFeatureClass; pGeom.Project(pGeodataset.SpatialReference); pFeatureCursor = pFeatureClass.Insert(false); pFeatureBuffer = pFeatureClass.CreateFeatureBuffer(); pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("OPERATIONAL_DATASET_NAME"),e.OperationalDS); pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("LOG_NOTE"),e.LogNote); pFeatureBuffer.Shape = pGeom; pFeatureCursor.InsertFeature(pFeatureBuffer); // cleanup: delete source graphics used to create new polygon if (pElemCollection.Count > 0) { IGraphicsContainer pGC = (IGraphicsContainer)m_pISDUTExt.FocusMap; for(int x = 0; x < pElemCollection.Count; x++) { IElement pElem; int i; pElemCollection.QueryItem(x,out pElem,out i); pGC.DeleteElement(pElem); } } } catch(Exception ex) { throw new Exception("Unable to create log polygon. " + ex.Message); } break; case enumCompilationLogAction.delete: try { pFeatureSelection = (IFeatureSelection)m_pFeatureLayer; pEnumIDs = pFeatureSelection.SelectionSet.IDs; pFeature = pFeatureClass.GetFeature(pEnumIDs.Next()); pQueryFilter = new SpatialFilterClass(); pQueryFilter.WhereClause = pFeatureClass.OIDFieldName + " = " + pFeature.OID; pFeatureCursor = pFeatureClass.Update(pQueryFilter,false); pFeatureCursor.NextFeature(); pFeatureCursor.DeleteFeature(); } catch (Exception ex) { throw new Exception("Unable to delete log polygon. " + ex.Message); } break; case enumCompilationLogAction.update: try { DialogResult diagRes = DialogResult.No; MessageBoxButtons buttons = MessageBoxButtons.YesNo; // if yes, we'll use the graphic to update the geometry, otherwise // we'll only update the attributes if (m_graphicSelected == true && m_featureSelected == true) { diagRes = MessageBox.Show("Do you want to replace the currently selected \n" + "feature geometry with the currently selected graphics?", "SUITT Question", buttons); } pFeatureSelection = (IFeatureSelection)m_pFeatureLayer; pEnumIDs = pFeatureSelection.SelectionSet.IDs; pFeature = pFeatureClass.GetFeature(pEnumIDs.Next()); pQueryFilter = new SpatialFilterClass(); pQueryFilter.WhereClause = pFeatureClass.OIDFieldName + " = " + pFeature.OID; pFeatureCursor = pFeatureClass.Update(pQueryFilter,false); IFeature pFeatureUp = pFeatureCursor.NextFeature(); pFeatureUp.set_Value(pFeatureUp.Fields.FindField("OPERATIONAL_DATASET_NAME"),e.OperationalDS); pFeatureUp.set_Value(pFeatureUp.Fields.FindField("LOG_NOTE"),e.LogNote); if (diagRes == DialogResult.Yes) { pGraphicsContSel = (IGraphicsContainerSelect)m_pISDUTExt.FocusMap; pEnumElement = pGraphicsContSel.SelectedElements; pGeom = get_GraphicShape(pEnumElement,2,true,ref pElemCollection); pGeom.SpatialReference = m_pISDUTExt.FocusMap.SpatialReference; pGeodataset = (IGeoDataset)pFeatureClass; pGeom.Project(pGeodataset.SpatialReference); pFeatureUp.Shape = pGeom; } pFeatureCursor.UpdateFeature(pFeatureUp); // cleanup: delete source graphics used to create new polygon if (pElemCollection.Count > 0) { IGraphicsContainer pGC = (IGraphicsContainer)m_pISDUTExt.FocusMap; for(int x = 0; x < pElemCollection.Count; x++) { IElement pElem; int i; pElemCollection.QueryItem(x,out pElem,out i); pGC.DeleteElement(pElem); } } } catch(Exception ex) { throw new Exception("Unable to update log polygon. " + ex.Message); } break; } IActiveView pActiveView = null; pActiveView = (IActiveView)m_pISDUTExt.FocusMap; pActiveView.Refresh(); if (pFeatureSelection != null) pFeatureSelection.Clear(); } catch(Exception ex) { util.Logger.Write(" Descrip : Handling the user action on the form (edit,update or delete). " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug); MessageBox.Show(e.Action.ToString() + " failed: " + ex.Message, "SUITT Error"); } finally { //util.Utils.Release(pMxDoc); util.Utils.Release(pFeatureCursor); } }
private void CopyPasteLayoutElements(IPageLayout pPLdest, IPageLayout pPLtemplate) { try { pPLdest.Page.Units = pPLtemplate.Page.Units; pPLdest.Page.Orientation = pPLtemplate.Page.Orientation; pPLdest.Page.PageToPrinterMapping = pPLtemplate.Page.PageToPrinterMapping; pPLdest.Page.IsPrintableAreaVisible = pPLtemplate.Page.IsPrintableAreaVisible; pPLdest.Page.StretchGraphicsWithPage = pPLtemplate.Page.StretchGraphicsWithPage; IGraphicsContainerSelect pGCSdest = (IGraphicsContainerSelect)pPLdest; IGraphicsContainer pGCdest = (IGraphicsContainer)pPLdest; IGraphicsContainerSelect pGCStemplate = (IGraphicsContainerSelect)pPLtemplate; IGraphicsContainer pGCtemplate = (IGraphicsContainer)pPLtemplate; pGCStemplate.SelectAllElements(); IElementCollection pElementCollection = new ElementCollectionClass(); // get a collection of all elements in the template IEnumElement pEnumElementTemplate = pGCStemplate.SelectedElements; IElement pElementTemplate = pEnumElementTemplate.Next(); while (pElementTemplate != null) { pElementCollection.Add(pElementTemplate,-1); pElementTemplate = pEnumElementTemplate.Next(); } // delete all elements except map frame pGCSdest.SelectAllElements(); IEnumElement pEnumElementDest = pGCSdest.SelectedElements; IElement pElementDest = pEnumElementDest.Next(); System.Collections.Generic.List<IElement> pMapFramesToDelete = new System.Collections.Generic.List<IElement>(); while (pElementDest != null) { IMapFrame pMapFrame = pElementDest as IMapFrame; if (pMapFrame == null) { pGCdest.DeleteElement(pElementDest); } else { // add any map frames in the current document to a List collection pMapFramesToDelete.Add(pElementDest); } pElementDest = pEnumElementDest.Next(); } // add the elements to the destination (current) pagelayout for (int x = pElementCollection.Count - 1; x >= 0; x-- ) { IElement pElemSelected; int linkID; pElementCollection.QueryItem(x,out pElemSelected,out linkID); pGCdest.AddElement(pElemSelected, x); } pGCSdest.UnselectAllElements(); // remove the original maps from the current document foreach (IElement pElem in pMapFramesToDelete) { pGCdest.DeleteElement(pElem); } } catch (Exception ex) { Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); util.Logger.Write(" Descrip : copying and pasting elements " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace, util.Logger.LogLevel.Debug); } }