/// <summary> /// Gets the features from the selection that are from a given ft class /// </summary> /// <param name="ftClassName">ft class name</param> /// <returns>List of IFeature</returns> public List <ESRI.ArcGIS.Geodatabase.IFeature> GetSelectedFeatures(IFeatureLayer layer) { List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>(); if (layer == null) { return(result); } ESRI.ArcGIS.Carto.IFeatureSelection ftSelection = layer as ESRI.ArcGIS.Carto.IFeatureSelection; if (null != ftSelection && null != ftSelection.SelectionSet) { ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet = ftSelection.SelectionSet; ESRI.ArcGIS.Geodatabase.ICursor cursor = null; try { selectionSet.Search(null, false, out cursor); ESRI.ArcGIS.Geodatabase.IRow ft = cursor.NextRow(); while (null != ft) { result.Add((ESRI.ArcGIS.Geodatabase.IFeature)ft); ft = cursor.NextRow(); } } finally { ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(cursor); } } return(result); }
public void SelectTracedDevices() { // ----------------------------------------------- // Following section of code causes cable, splice // and device features to be selected on the map // using the IFeatureSelection & ISelectionSet // interfaces // ----------------------------------------------- // Remove any previous trace results. _hookHelper.FocusMap.ClearSelection(); Dictionary <string, List <int> > deviceOidLists = new Dictionary <string, List <int> >(); // First get set of OIDs that were traced. foreach (IRow traceItem in this._traceResults) { ESRI.ArcGIS.Geodatabase.IDataset dataset = traceItem.Table as ESRI.ArcGIS.Geodatabase.IDataset; string className = GdbUtils.ParseTableName(dataset); if (ConfigUtil.IsDeviceClassName(className)) { List <int> deviceOids = null; if (deviceOidLists.ContainsKey(className)) { deviceOids = deviceOidLists[className]; } else { deviceOids = new List <int>(); deviceOidLists[className] = deviceOids; } deviceOids.Add(traceItem.OID); } } // Do the actual selections foreach (KeyValuePair <string, List <int> > deviceOidPair in deviceOidLists) { ESRI.ArcGIS.Carto.IFeatureSelection deviceFtSelection = _hookHelper.FindFeatureLayer(deviceOidPair.Key) as ESRI.ArcGIS.Carto.IFeatureSelection; if (null != deviceFtSelection) { ESRI.ArcGIS.Geodatabase.ISelectionSet deviceSelectionSet = deviceFtSelection.SelectionSet; List <int> deviceOidList = deviceOidPair.Value; if (null != deviceSelectionSet && 0 < deviceOidList.Count) { int[] oidList = deviceOidList.ToArray(); deviceSelectionSet.AddList(deviceOidList.Count, ref oidList[0]); } } else { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", deviceOidPair.Key + " not found.", "Layer removed from TOC?"); } } }
public void SelectTracedSpliceClosures() { // ----------------------------------------------- // Following section of code causes cable, splice // and device features to be selected on the map // using the IFeatureSelection & ISelectionSet // interfaces // ----------------------------------------------- List <int> spliceOidList = new List <int>(); // First get set of OIDs that were traced. foreach (IRow traceItem in this._traceResults) { ESRI.ArcGIS.Geodatabase.IDataset dataset = traceItem.Table as ESRI.ArcGIS.Geodatabase.IDataset; string className = GdbUtils.ParseTableName(dataset); if (0 == string.Compare(className, ConfigUtil.SpliceClosureFtClassName, true)) { if (traceItem.HasOID) { spliceOidList.Add(traceItem.OID); } } } // Do the actual selection ESRI.ArcGIS.Carto.IFeatureSelection scFtSelection = _hookHelper.FindFeatureLayer(ConfigUtil.SpliceClosureFtClassName) as ESRI.ArcGIS.Carto.IFeatureSelection; if (scFtSelection == null) { // No selection to be made as layer not in TOC _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", ConfigUtil.SpliceClosureFtClassName + " not found.", "Layer removed from TOC?"); } else { ESRI.ArcGIS.Geodatabase.ISelectionSet scSelectionSet = scFtSelection.SelectionSet; if (null != scSelectionSet && 0 < spliceOidList.Count) { int[] oidList = spliceOidList.ToArray(); scSelectionSet.AddList(spliceOidList.Count, ref oidList[0]); } } }
/// <summary> /// 点击事件 /// </summary> public override void OnClick() { if (DataEditCommon.g_pMyMapCtrl.CurrentTool != null) { DataEditCommon.g_pMyMapCtrl.CurrentTool = null; } IFeatureLayer m_featureLayer = DataEditCommon.g_pLayer as IFeatureLayer; IFeatureSelection m_featureSelection = m_featureLayer as IFeatureSelection; ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = m_featureSelection.SelectionSet;//QI到ISelectionSet if (m_selectionSet.Count < 1) { DataEditCommon.g_pMyMapCtrl.CurrentTool = null; MessageBox.Show("当前图层没有可复制的元素!"); return; } GIS.Common.DataEditCommon.copypaste = 1; DataEditCommon.copypasteLayer = m_featureLayer; m_command.OnClick(); }
/// <summary> /// 点击事件 /// </summary> public override void OnClick() { //if (m_engineEditor.SelectionCount < 1) //DataEditCommon.InitEditEnvironment(); //DataEditCommon.CheckEditState(); IFeatureLayer m_featureLayer = DataEditCommon.g_pLayer as IFeatureLayer; if (m_featureLayer == null) { return; } IFeatureSelection m_featureSelection = m_featureLayer as IFeatureSelection; ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = m_featureSelection.SelectionSet;//QI到ISelectionSet if (m_selectionSet.Count < 1) { MessageBox.Show(@"请选择要旋转的图元。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DataEditCommon.g_pMyMapCtrl.CurrentTool = null; return; } //GIS.GraphicEdit.SnapSetting.StartSnappingEnv(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { m_command.OnClick(); m_hookHelper.ActiveView.Refresh(); IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); IFeatureLayer featureLayer = GIS.Common.DataEditCommon.copypasteLayer; if (featureLayer == null) { return; } IFeatureSelection m_featureSelection = featureLayer as IFeatureSelection; ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = m_featureSelection.SelectionSet; if (m_selectionSet.Count == 0) { return; } IFeatureClass pFeatureClass = featureLayer.FeatureClass; ICursor pCursor = null; m_selectionSet.Search(null, false, out pCursor); IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor; IFeature m_pFeature = pFeatureCursor.NextFeature(); double dx = 0; double dy = 0; if (m_pFeature == null) { return; } DataEditCommon.InitEditEnvironment(); DataEditCommon.CheckEditState(); while (m_pFeature != null) { ITransform2D pTrans2D = m_pFeature.ShapeCopy as ITransform2D; if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry0Dimension) { IPoint pt = m_pFeature.Shape as IPoint; if (dx == 0) { dx = pPoint.X - pt.X; } if (dy == 0) { dy = pPoint.Y - pt.Y; } pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry1Dimension) { IPolyline lPolyline = m_pFeature.Shape as IPolyline; if (dx == 0) { dx = pPoint.X - lPolyline.FromPoint.X; } if (dy == 0) { dy = pPoint.Y - lPolyline.FromPoint.Y; } pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry2Dimension) { if (m_pFeature.FeatureType == esriFeatureType.esriFTAnnotation) { IAnnotationFeature annoFeature = m_pFeature as IAnnotationFeature; IElement element = (IElement)annoFeature.Annotation; ITextElement textElement = new TextElementClass(); IPoint mPoint = element.Geometry as IPoint; pTrans2D = mPoint as ITransform2D; if (dx == 0) { dx = pPoint.X - mPoint.X; } if (dy == 0) { dy = pPoint.Y - mPoint.Y; } pTrans2D.Move(dx, dy); element.Geometry = pTrans2D as IGeometry; annoFeature.Annotation = element; m_pFeature.Store(); } else { IPolygon lPolyline = m_pFeature.Shape as IPolygon; if (dx == 0) { dx = pPoint.X - lPolyline.FromPoint.X; } if (dy == 0) { dy = pPoint.Y - lPolyline.FromPoint.Y; } pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } } else { } m_pFeature = pFeatureCursor.NextFeature(); } DataEditCommon.g_engineEditor.StopOperation("editpaste"); GIS.Common.DataEditCommon.copypaste = 0; DataEditCommon.copypasteLayer = null; m_hookHelper.ActiveView.Refresh(); //IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); //IFeatureLayer featureLayer = DataEditCommon.g_pLayer as IFeatureLayer; //if (featureLayer == null) return; //if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == featureLayer.FeatureClass.ShapeType && DataEditCommon.MyCopy.m_featureLayer.FeatureClass.FeatureType == featureLayer.FeatureClass.FeatureType) //{ // ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = DataEditCommon.MyCopy.m_selectionSet; // for (int i = 0; i < m_selectionSet.Count; i++) // { // } //} //else if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && featureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTAnnotation) //{ //} //else if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && DataEditCommon.MyCopy.m_featureLayer.FeatureClass.FeatureType!=esriFeatureType.esriFTAnnotation&& featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //{ //} //DataEditCommon.InitEditEnvironment(); //DataEditCommon.CheckEditState(); }
private void button_Import_Click(object sender, System.EventArgs e) { // point to the first selected feature: ESRI.ArcGIS.Animation.IAGImportPathOptions AGImportPathOptionsCls = new ESRI.ArcGIS.Animation.AGImportPathOptionsClass(); // Set properties for AGImportPathOptions AGImportPathOptionsCls.BasicMap = (ESRI.ArcGIS.Carto.IBasicMap)globe; // Explicit Cast AGImportPathOptionsCls.AnimationTracks = (ESRI.ArcGIS.Animation.IAGAnimationTracks)globe; // Explicit Cast AGImportPathOptionsCls.AnimationType = new ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass(); AGImportPathOptionsCls.AnimatedObject = globe.GlobeDisplay.ActiveViewer.Camera; if (this.radioButton_flyby.Checked == true) { AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathObsAndTarget; AGImportPathOptionsCls.PutAngleCalculationMethods(esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative); AGImportPathOptionsCls.PutAngleCalculationValues(0.0, 0.0, 0.0); } else if (this.radioButton_currentTarget.Checked == true) { AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathObserver; } else if (this.radioButton_currentObserver.Checked == true) { AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathTarget; } double pAzimuth, pInclination, pRollVal; AGImportPathOptionsCls.GetAngleCalculationValues(out pAzimuth, out pInclination, out pRollVal); AGImportPathOptionsCls.LookaheadFactor = this.trackBarSimplificationFactor.Value / 100; AGImportPathOptionsCls.TrackName = this.textBox_TrackName.Text; AGImportPathOptionsCls.OverwriteExisting = Convert.ToBoolean(this.checkBox_Overwrite.CheckState); AGImportPathOptionsCls.VerticalOffset = Convert.ToDouble(this.textBox_VertOffset.Text); AGImportPathOptionsCls.ReversePath = Convert.ToBoolean(this.checkBox_ReverseOrder.CheckState); // get the layer selected in the combo box if (this.comboBoxLayers.SelectedIndex == -1) { MessageBox.Show("Please select a layer before you proceed"); } else { //set the layer based on the item selected in the combo box ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)layerArray.get_Element(this.comboBoxLayers.SelectedIndex); // Explicit Cast // Get the line feature selected in the layer ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)layer; // Explicit Cast ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = (ESRI.ArcGIS.Carto.IFeatureSelection)layer; // Explicit Cast ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet = featureSelection.SelectionSet; ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass; string shapeField = featureClass.ShapeFieldName; ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilterCls = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass(); IScene scene = globe.GlobeDisplay.Scene; ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = scene.SpatialReference; spatialFilterCls.GeometryField = shapeField; spatialFilterCls.set_OutputSpatialReference(shapeField, spatialReference); ESRI.ArcGIS.Geodatabase.ICursor cursor; selectionSet.Search(spatialFilterCls, true, out cursor); ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = (ESRI.ArcGIS.Geodatabase.IFeatureCursor)cursor; // Explicit Cast ESRI.ArcGIS.Geodatabase.IFeature lineFeature; lineFeature = featureCursor.NextFeature(); if (lineFeature == null) { MessageBox.Show("Please select a feature in the feature layer selected"); } else { CreateFlybyFromPathAnimation(globe, lineFeature, AGImportPathOptionsCls); } } this.Close(); }