AE开发中对GDB以及shapefile的读取对FeatureClass的相关操作

Posted 总要有点追求吧

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AE开发中对GDB以及shapefile的读取对FeatureClass的相关操作相关的知识,希望对你有一定的参考价值。

读取gdb方法
private void btn_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.Description = "打开GDB文件夹";
if (DialogResult.OK == dlg.ShowDialog())
{
if (Directory.Exists(dlg.SelectedPath))
{
if(dlg.SelectedPath.ToUpper().Contains(".GDB"))
{
GDBTextBox.Text = dlg.SelectedPath;
}
}
}
}
#region 直接获取FeatureClass
string filePath = GDBTextBox.Text;
FileGDBWorkspaceFactoryClass fac=new FileGDBWorkspaceFactoryClass();
IFeatureWorkspace space = (IFeatureWorkspace)fac.OpenFromFile(filePath, 0);
IFeatureClass pPointFClass = space.OpenFeatureClass("zhongxindian"); //获取FeatureClass
#endregion

#region 添加到comboBox里面、获取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);//添加到comboBox里面
pDatasetName = FeatureEnumDatasetName.Next();
}
IFeatureClass m_pFeatureClass2=null;
private void tcCombox_SelectedIndexChanged(object sender, EventArgs e)
{
m_pFeatureClass2 = m_pFeatureWorkspace.OpenFeatureClass(tcCombox.Text);//comboBox里选择图层,获取FeatureClass
}
#endregion

#region 遍历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;//获取FeatureClass

//对FeatureClass的操作
//比如给FeatureClass添加字段、代码如下
if (pPolygonFClass.Fields.FindField("字段") > -1) return;//如果存在字段
IClass pTable = pPolygonFClass as IClass;
IFieldEdit pFieldEdit = new FieldClass();
pFieldEdit.Name_2 = "字段";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
pTable.AddField((IField)pFieldEdit);
int countIndex = pPolygonFClass.Fields.FindField("字段");//获取字段索引

pDataset = FeatureEnumDataset.Next();
}
#endregion

#region 遍历FeatureClass
IFeatureCursor Cur = fc.Search(null, false);//null可替换为QueryFilter
IFeature pFeature = Cur.NextFeature();
while (pFeature != null)
{
//对Feature进行操作
pFeature = Cur.NextFeature();
}

读取shapefile
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));//获取FeatureClass
//_rowCount = (layPolygon as ITable).RowCount(null);//获取FeatureClass数量
shapefileTextBox.Text = fileDlg.FileName;//在TextBox中显示
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
}



以上是关于AE开发中对GDB以及shapefile的读取对FeatureClass的相关操作的主要内容,如果未能解决你的问题,请参考以下文章

R:在 shapefile 中的多边形上绘制 .gdb 文件中的点

skyline开发——读取Shapefile要素属性

C++中怎么读取shapefile格式的文件

使用 GeoPandas/Fiona 从 shapefile 读取 M 值

如何用python读取arcgis中shapefile文件的属性表?可以输出为excel格式吗

Spring中对资源的读取支持