Read the GdB method
private void Btn_click (object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog ();
Dlg. Description = "Open gdb folder";
if (DialogResult.OK = = dlg. ShowDialog ())
{
if (Directory.Exists (DLG). SelectedPath))
{
if (dlg. Selectedpath.toupper (). Contains (". GDB "))
{
Gdbtextbox.text = dlg. SelectedPath;
}
}
}
}
#region Get Featureclass directly
string filePath = Gdbtextbox.text;
Filegdbworkspacefactoryclass fac=new Filegdbworkspacefactoryclass ();
Ifeatureworkspace space = (ifeatureworkspace) FAC. Openfromfile (FilePath, 0);
Ifeatureclass Ppointfclass = space. Openfeatureclass ("Zhongxindian"); Get Featureclass
#endregion
#region added to the ComboBox, get Featureclass
Iworkspacefactory m_pworkspacefactory = new Filegdbworkspacefactoryclass ();
Iworkspace pworkspace = m_pworkspacefactory.openfromfile (gdbtextbox.text, 0);
Ifeatureworkspace m_pfeatureworkspace = pworkspace as Ifeatureworkspace;
Ienumdatasetname featureenumdatasetname = Pworkspace.get_datasetnames (Esridatasettype.esridtfeatureclass);
if (Featureenumdatasetname = = null) return;
Featureenumdatasetname.reset ();
Idatasetname pdatasetname = Featureenumdatasetname.next ();
while (pdatasetname! = null)
{
TCCOMBOX.ITEMS.ADD (pdatasetname.name);//Add to the ComboBox
Pdatasetname = Featureenumdatasetname.next ();
}
Ifeatureclass M_pfeatureclass2=null;
private void Tccombox_selectedindexchanged (object sender, EventArgs e)
{
M_pfeatureclass2 = M_pfeatureworkspace.openfeatureclass (tccombox.text);//combobox select layer, Get Featureclass
}
#endregion
#region Traverse GDB
Iworkspace pcarworkspace = m_pworkspacefactory.openfromfile (gdbtextbox.text, 0);
Ienumdataset Featureenumdataset = pcarworkspace.get_datasets (Esridatasettype.esridtfeatureclass);
if (Featureenumdataset = = null) return;
Featureenumdataset.reset ();
Idataset Pdataset = Featureenumdataset.next ();
while (pdataset! = null)
{
Ifeatureclass FC = Pdataset as ifeatureclass;//get Featureclass
Operation on the Featureclass
For example, add fields to Featureclass, code as follows
if (PPolygonFClass.Fields.FindField ("field") >-1) return;//if a field exists
IClass ptable = Ppolygonfclass as IClass;
Ifieldedit pfieldedit = new Fieldclass ();
pfieldedit.name_2 = "Field";
pfieldedit.type_2 = Esrifieldtype.esrifieldtypeinteger;
Ptable.addfield ((Ifield) pfieldedit);
int countindex = PPolygonFClass.Fields.FindField ("field");//Get field Index
Pdataset = Featureenumdataset.next ();
}
#endregion
#region Traverse Featureclass
Ifeaturecursor Cur = FC. Search (null, FALSE);//null can be replaced by queryfilter
IFeature pfeature = Cur.nextfeature ();
while (pfeature! = null)
{
Working with the feature
Pfeature = Cur.nextfeature ();
}
Read Shapefiles
private void Btn_click (object sender, EventArgs e)
{
OpenFileDialog Filedlg = new OpenFileDialog ();
Filedlg.filter = "Shape File | *.shp ";
Filedlg.multiselect = false;
if (filedlg.showdialog () = = System.Windows.Forms.DialogResult.OK)
{
Try
{
Iworkspacefactory pworkspacefactory = new Shapefileworkspacefactory ();
Iworkspace pworkspace = Pworkspacefactory.openfromfile (System.IO.Path.GetDirectoryName (Filedlg.filename), 0);
Ifeatureworkspace pfeatureworkspace = pworkspace as Ifeatureworkspace;
Ifeatureclass Laypolygon = Pfeatureworkspace.openfeatureclass (System.IO.Path.GetFileNameWithoutExtension ( Filedlg.filename));//Get Featureclass
_rowcount = (Laypolygon as ITable). RowCount (null);//Get Featureclass Quantity
Shapefiletextbox.text = filedlg.filename;//is displayed in a textbox
}
catch (Exception exp)
{
MessageBox.Show (exp. Message);
}
}
}
The reading of GDB and shapefiles in AE development and related operation to Featureclass