ArcGis的FeatureClass是否就是对应一个图层呢 一个图层是否就是相同要素的集合呢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcGis的FeatureClass是否就是对应一个图层呢 一个图层是否就是相同要素的集合呢相关的知识,希望对你有一定的参考价值。

FeatureClass就相当于一个shapeFile,你在ArcGIS下面可以new shapefile 在数据库里面就是new featureclass可以称之为一个图层,是同一几何类型、相同属性结构的要素集合。 参考技术A 是对应一个图层,这个图层的类型是相同的,如都是点层,或者都是面层等,而且它们具有相同的坐标系统和投影系统。 参考技术B 是的,ArcGis中一个FeatureClass就对应一个图层。但一个FeatureClass或图层并不一定是相同要素的集合。比如一个FeatureClass中可以有点要素,也可以有线要素及面要素。

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);
}
}
}



以上是关于ArcGis的FeatureClass是否就是对应一个图层呢 一个图层是否就是相同要素的集合呢的主要内容,如果未能解决你的问题,请参考以下文章

ArcGIS Pro二次开发(19):创建要素类(FeatureClass)

C# arcgis engine 怎么对属性表,添加一行数据,删除一行数据,以及修改一行数据。

如何用arcgis制作公里网格

要素类的概念 在ArcGIS中的要素类和要素数据集

如何在ArcGIS中绘制矢量网格图

AE中如何由IFeature 如何获取所对应的FeatureClass