public static ESRI.ArcGIS.Geodatabase.ICursor obterCursor(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace, string tables, string subFields, string whereClause) { ESRI.ArcGIS.Geodatabase.IQueryDef queryDef = featureWorkspace.CreateQueryDef(); queryDef.Tables = tables; queryDef.SubFields = subFields; queryDef.WhereClause = whereClause; return(queryDef.Evaluate()); }
/// <summary> /// 删除要素类 /// </summary> /// <param name="featureWorkspace"></param> /// <param name="featureClassName"></param> public static void DelAeFeatureclass(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace, string featureClassName) { try { ESRI.ArcGIS.Geodatabase.IFeatureClass tmpfeatureclass = featureWorkspace.OpenFeatureClass(featureClassName); ESRI.ArcGIS.Geodatabase.IDataset set = tmpfeatureclass as ESRI.ArcGIS.Geodatabase.IDataset; set.CanDelete(); set.Delete(); } catch { } }
/// <summary> /// 使用全AE方法获取AE要素类 /// </summary> /// <param name="featureWorkspace"></param> /// <param name="featureClassName"></param> /// <returns></returns> public static ESRI.ArcGIS.Geodatabase.IFeatureClass OpenAeFeatureclass(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace, string featureClassName) { try { ESRI.ArcGIS.Geodatabase.IFeatureClass tmpfeatureclass = featureWorkspace.OpenFeatureClass(featureClassName); if (tmpfeatureclass != null) { return(tmpfeatureclass); } } catch { } return(null); }
public ESRI.ArcGIS.Geodatabase.IFeatureClass CreateFeatureClass(string name, ESRI.ArcGIS.Geometry.ISpatialReference spatialReference, string workspacename) { ESRI.ArcGIS.Geodatabase.IWorkspace w = WorkSpace.CreateInMemoryWorkspace(workspacename); ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fw = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)w; ESRI.ArcGIS.Geodatabase.IFields2 fields = CreateFields(spatialReference); ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UID(); ESRI.ArcGIS.Geodatabase.IFeatureClassDescription fcDesc = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); ESRI.ArcGIS.Geodatabase.IObjectClassDescription ocDesc = (ESRI.ArcGIS.Geodatabase.IObjectClassDescription)fcDesc; ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fw.CreateFeatureClass(name, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, "Shape", ""); return(fc); }
//#### ArcGIS Snippets #### #region "Add Shapefile Using OpenFileDialog" ///<summary>Add a shapefile to the ActiveView using the Windows.Forms.OpenFileDialog control.</summary> /// ///<param name="activeView">An IActiveView interface</param> /// ///<remarks></remarks> public void AddShapefileUsingOpenFileDialog(ESRI.ArcGIS.Carto.IActiveView activeView) { //parameter check if (activeView == null) { return; } // Use the OpenFileDialog Class to choose which shapefile to load. System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "Shapefiles (*.shp)|*.shp"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // The user chose a particular shapefile. // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp" string shapefileLocation = openFileDialog.FileName; if (shapefileLocation != "") { // Ensure the user chooses a shapefile // Create a new ShapefileWorkspaceFactory CoClass to create a new workspace ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory(); // System.IO.Path.GetDirectoryName(shapefileLocation) returns the directory part of the string. Example: "C:\test\" ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(shapefileLocation), 0); // Explicit Cast // System.IO.Path.GetFileNameWithoutExtension(shapefileLocation) returns the base filename (without extension). Example: "cities" ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation)); ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = new ESRI.ArcGIS.Carto.FeatureLayer(); featureLayer.FeatureClass = featureClass; featureLayer.Name = featureClass.AliasName; featureLayer.Visible = true; activeView.FocusMap.AddLayer(featureLayer); // Zoom the display to the full extent of all layers in the map activeView.Extent = activeView.FullExtent; activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null); } else { // The user did not choose a shapefile. // Do whatever remedial actions as necessary // System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #1", // System.Windows.Forms.MessageBoxButtons.OK, // System.Windows.Forms.MessageBoxIcon.Exclamation); } } else { // The user did not choose a shapefile. They clicked Cancel or closed the dialog by the "X" button. // Do whatever remedial actions as necessary. // System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #2", // System.Windows.Forms.MessageBoxButtons.OK, // System.Windows.Forms.MessageBoxIcon.Exclamation); } }
void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove) { if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) { return; } ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset; // Remove only elements contained in a specific Schematic dataset if (esriData.Name != SampleDatasetName) { return; } // Remove only elements contained in a specific type of diagram if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName) { return; } canRemove = false; // can't remove SubStation if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation") { return; } ISchematicDiagramClass schemDiagramClass; schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass; // For this specific diagram type, we retrieve the datasource // and the tables where the elements are stored ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource; string tableName = ""; switch (inMemoryFeature.SchematicElementClass.SchematicElementType) { case esriSchematicElementType.esriSchematicNodeType: tableName = TableNameNodes; break; case esriSchematicElementType.esriSchematicLinkType: tableName = TableNameLinks; break; case esriSchematicElementType.esriSchematicDrawingType: return; break; } // Retrieve Feature Workspace ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace; // Get Attributes values ISchematicAttributeContainer schemAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent; if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) || !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null))) { int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID); int OID = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer); //Get table and row ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName); ESRI.ArcGIS.Geodatabase.IRow esriRow = esriTable.GetRow(OID); // When the row is identified in the table, it is deleted and // the CanRemove returns True so that the associated // schematic element is graphically removed from the active diagram if (!(esriRow == null)) { esriRow.Delete(); canRemove = true; } } }
private void browseButton_Click(object sender, EventArgs e) { ESRI.ArcGIS.CatalogUI.IGxDialog browser = new ESRI.ArcGIS.CatalogUI.GxDialog(); browser.ObjectFilter = new GxFilterFeatureClassesClass(); browser.Title = "Name of Feature Class to Create"; if (!browser.DoModalSave((int)Handle)) return; if (browser.ReplacingObject) { MessageBox.Show(@"Cannot overwrite an existing feature class.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // shapefile folder if (browser.FinalLocation is IGxFolder) { Dataset = null; ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory(); Workspace = wsf.OpenFromFile(browser.FinalLocation.FullName, 0) as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace; } // geodatabase (root level) var database = browser.FinalLocation as IGxDatabase; if (database != null) { Dataset = null; Workspace = database.Workspace as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace; } // feature dataset in a geodatabase var dataset = browser.FinalLocation as IGxDataset; if (dataset != null) { Dataset = dataset.Dataset as ESRI.ArcGIS.Geodatabase.IFeatureDataset; Workspace = dataset.Dataset.Workspace as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace; var geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)Dataset; if (geoDataset != null) spatialReferenceTextBox.Text = geoDataset.SpatialReference.Name; } if (Workspace == null) { MessageBox.Show(@"Location is not a valid feature workspace.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); outputPathTextBox.Text = ""; saveButton.Enabled = false; } else { FeatureClassName = browser.Name; outputPathTextBox.Text = browser.FinalLocation.FullName + @"\" + FeatureClassName; saveButton.Enabled = true; } spatialReferenceTextBox.Text = (Dataset == null) ? @"Unknown" : ((ESRI.ArcGIS.Geodatabase.IGeoDataset)Dataset).SpatialReference. Name; } }