/**/
ESRI Developer Summit 2009
Developer's Guide to the Geodatabase
Code Samples
6 April 2009
/**/
开发环境:
- ArcGIS Engine9.3/9.3.1
- VS2008
<p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-itFormBoundaryGdRn5qhD7nx0T4Q7
Content-Disposition: form-data; name=" content"=""
/**/
ESRI Developer Summit 2009
Developer's Guide to the Geodatabase
Code Samples
6 April 2009
/**/
开发环境:
- ArcGIS Engine9.3/9.3.1
- VS2008
关于版本的接口差别参考:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Type_changes_between_9_3_and_10/000100000408000000/
以下代码主要是对拓扑编辑做相关介绍
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using ESRI.ArcGIS.ADF.BaseClasses;
- using ESRI.ArcGIS.ADF.CATIDs;
- using ESRI.ArcGIS.Carto;
- using ESRI.ArcGIS.Controls;
- using ESRI.ArcGIS.Display;
- using ESRI.ArcGIS.Editor;
- using ESRI.ArcGIS.esriSystem;
- using ESRI.ArcGIS.Framework;
- using ESRI.ArcGIS.Geodatabase;
- using ESRI.ArcGIS.Geometry;
-
- namespace TopologyEditDemo
- {
- [Guid("35d59a9d-997c-4536-a003-3c6ed77abb92")]
- [ClassInterface(ClassInterfaceType.None)]
- [ProgId("TopologyEditDemo.TopologyEditCommand")]
- public sealed class TopologyEditCommand : BaseCommand
- {
- #region COM Registration Function(s)
- [ComRegisterFunction()]
- [ComVisible(false)]
- static void RegisterFunction(Type registerType)
- {
- String regKey = String.Format(@"HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID);
- MxCommands.Register(regKey);
- }
-
- [ComUnregisterFunction()]
- [ComVisible(false)]
- static void UnregisterFunction(Type registerType)
- {
- String regKey = String.Format(@"HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID);
- MxCommands.Unregister(regKey);
- }
- #endregion
-
- #region Instance Variables
-
-
-
- private IHookHelper hookHelper = null;
-
-
-
-
- private IApplication application = null;
- #endregion
-
- #region Constructors
-
-
-
- public TopologyEditCommand()
- {
-
- m_category = "2009 DevSummit";
- m_caption = "TopologyEditCommand";
- m_message = "Editing using the Topology Graph";
- m_toolTip = "TopologyEditCommand";
- m_name = String.Format("{0}_{1}", m_category, m_caption);
-
-
- try
- {
- String bitmapResourceName = "TopologyEditCommand.bmp";
- m_bitmap = new Bitmap(GetType(), bitmapResourceName);
- }
- catch (Exception exc)
- {
- Trace.WriteLine(exc.Message, "Invalid Bitmap");
- }
- }
- #endregion
-
- #region Overridden Class Methods
-
-
-
-
- public override void OnCreate(object hook)
- {
-
- hookHelper = new HookHelperClass { Hook = hook };
- application = (IApplication)hook;
- }
-
-
-
-
- public override Boolean Enabled
- {
- get
- {
- IMap map = hookHelper.FocusMap;
- IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection;
- return enumFeature.Next() != null;
- }
- }
-
-
-
-
- public override void OnClick()
- {
- try
- {
-
- IMap map = hookHelper.FocusMap;
- IActiveView activeView = hookHelper.ActiveView;
- IEditor editor = (IEditor)application.FindExtensionByName("ESRI Object Editor");
-
-
- IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection;
- IEnumFeatureSetup enumFeatureSetup = (IEnumFeatureSetup)enumFeature;
- enumFeatureSetup.AllFields = true;
- IFeature feature = enumFeature.Next();
-
-
- Double yMoveDistance = Double.Parse(InputBox.ShowInputBox());
-
-
- ITopologyLayer topologyLayer = map.get_Layer(0) as ITopologyLayer;
- if (topologyLayer != null)
- {
-
- ITopology topology = topologyLayer.Topology;
- ITopologyGraph topologyGraph = topology.Cache;
-
-
- IEnvelope existingGraphEnv = topologyGraph.BuildExtent;
- IEnvelope activeViewEnv = activeView.Extent;
- if (!existingGraphEnv.IsEmpty)
- {
- IClone graphEnvClone = (IClone)existingGraphEnv;
- IClone activeViewExtentClone = (IClone)activeViewEnv;
- if (!graphEnvClone.IsEqual(activeViewExtentClone))
- {
-
-
-
- topologyGraph.Build(activeViewEnv, false);
- }
- }
- else
- {
- topologyGraph.Build(activeViewEnv, false);
- }
-
-
-
- IGeometry geometry = feature.ShapeCopy;
- topologyGraph.SelectByGeometry(
- (int)esriTopologyElementType.esriTopologyNode,
- esriTopologySelectionResultEnum.esriTopologySelectionResultNew,
- geometry);
-
-
- IAffineTransformation2D affine = new AffineTransformation2DClass();
- affine.Move(0, yMoveDistance);
-
-
- IDataset dataset = (IDataset)topology.FeatureDataset;
- editor.StartEditing(dataset.Workspace);
- editor.StartOperation();
-
- topologyGraph.TransformSelection(esriTransformDirection.esriTransformForward, affine, false);
-
-
-
- IEnvelope invalidArea = null;
- topologyGraph.Post(out invalidArea);
-
- editor.StopOperation("Stop operation");
- editor.StopEditing(true);
-
- activeView.Refresh();
- }
- else
- {
- MessageBox.Show("Topology is not the first layer in TOC", "TopologyGraphEditCommand");
- return;
- }
- }
- catch (COMException comExc)
- {
- MessageBox.Show(String.Format("Error ({0}): {1}", comExc.ErrorCode, comExc.Message));
- }
- catch (Exception exc)
- {
- MessageBox.Show(String.Format("Error: {0}", exc.Message));
- }
- }
- #endregion
-
- #region Inputbox Class
-
-
-
- public class InputBox : Form
- {
- #region Instance Variables
-
-
-
- private TextBox textBox = null;
- #endregion
-
- #region Constructors and Initialization
-
-
-
- private InputBox()
- {
- InitializeComponent();
- }
-
-
-
-
- private void InitializeComponent()
- {
-
- textBox = new TextBox()
- {
- Location = new System.Drawing.Point(16, 16),
- Name = "TextBox",
- Size = new Size(256, 20),
- TabIndex = 0,
- Text = "30"
- };
- textBox.KeyDown += new KeyEventHandler(OnKeyDown);
-
- SuspendLayout();
-
-
- AutoScaleBaseSize = new Size(5, 13);
- ClientSize = new Size(292, 53);
- ControlBox = false;
- Controls.AddRange(new Control[] { textBox });
- FormBorderStyle = FormBorderStyle.FixedDialog;
- Name = "InputBox";
- Text = "Enter 2D Transform Vertical Distance";
-
- ResumeLayout(false);
- }
- #endregion
-
- #region Public Methods
-
-
-
- public String Value
- {
- get { return textBox.Text; }
- }
- #endregion
-
- #region Event Handlers
-
-
-
-
-
- private void OnKeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- this.Close();
- }
- #endregion
-
- #region Static Methods
-
-
-
-
- public static String ShowInputBox()
- {
- InputBox box = new InputBox();
- box.ShowDialog();
- return box.Value;
- }
- #endregion
- }
- #endregion
- }
- }