The reading of GDB and shapefiles in AE development and related operation to Featureclass

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.