C#AE二次开发 从GeoDatabase数据库中添加矢量数据?
privatevoidbutton2_Click(objectsender,EventArgse){stringFilename="states";//实例化工作空间工厂...
private void button2_Click(object sender, EventArgs e)
{
string Filename = "states";
//实例化工作空间工厂
IWorkspaceFactory pFact=new AccessWorkspaceFactoryClass();
//工作空间
IWorkspace pWorkspace = null;
//geodatabase全路径(含扩展名)
string PathStr = @"D:\二次开发实习\USA.mdb";
//打开geodatabase
pWorkspace = pFact.OpenFromFile(PathStr,0);
IFeatureLayer pFeatureLayer;
IFeatureWorkspace pFWorkspace;
//IGeoFeatureLayer pLayer;
ILayer pLayer;
pFWorkspace = pWorkspace as IFeatureWorkspace;
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFWorkspace.OpenFeatureClass(Filename);
pFeatureLayer.Name = Filename;
pLayer = pFeatureLayer as ILayer;
axMapControl1.AddLayer(pLayer);
}
代码打开D:\二次开发实习\USA.mdb中的states图层,但是调试的时候总是出现错误如下图所示: 展开
{
string Filename = "states";
//实例化工作空间工厂
IWorkspaceFactory pFact=new AccessWorkspaceFactoryClass();
//工作空间
IWorkspace pWorkspace = null;
//geodatabase全路径(含扩展名)
string PathStr = @"D:\二次开发实习\USA.mdb";
//打开geodatabase
pWorkspace = pFact.OpenFromFile(PathStr,0);
IFeatureLayer pFeatureLayer;
IFeatureWorkspace pFWorkspace;
//IGeoFeatureLayer pLayer;
ILayer pLayer;
pFWorkspace = pWorkspace as IFeatureWorkspace;
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFWorkspace.OpenFeatureClass(Filename);
pFeatureLayer.Name = Filename;
pLayer = pFeatureLayer as ILayer;
axMapControl1.AddLayer(pLayer);
}
代码打开D:\二次开发实习\USA.mdb中的states图层,但是调试的时候总是出现错误如下图所示: 展开
2个回答
展开全部
以前做过的添加图层的代码,你试试,可以寻找添加图层的,GeoDatabase数据库中的也可以,,
IGxDialog pgxdialog = default(IGxDialog);
IEnumGxObject pEnumGxobject = null;
IGxObjectFilter pFilter = default(IGxObjectFilter);
pFilter = new GxFilterFeatureDatasetsAndFeatureClasses();
pgxdialog = new GxDialog();
//***Dim pgxobject As IGxObject
pgxdialog.AllowMultiSelect = true;
pgxdialog.StartingLocation = "f:";
pgxdialog.Title = "select files for input";
pgxdialog.ButtonCaption = "OK";
pgxdialog.ObjectFilter = pFilter;
pgxdialog.DoModalOpen(0, pEnumGxobject);
if (pEnumGxobject == null)
return;
IGxDataset pGxObject = default(IGxDataset);
IFeatureLayer pFLayer = default(IFeatureLayer);
pFLayer = new FeatureLayer();
pGxObject = pEnumGxobject.Next;
if (pGxObject == null)
return;
while ((pGxObject != null)) {
//***If TypeOf pGxObject.Dataset Is IFeatureClass Then
pFLayer.FeatureClass = pGxObject.Dataset;
pFLayer.Name = pGxObject.Dataset.Name;
this.AxMapControl1.AddLayer(pFLayer);
pGxObject = pEnumGxobject.Next;
}
IGxDialog pgxdialog = default(IGxDialog);
IEnumGxObject pEnumGxobject = null;
IGxObjectFilter pFilter = default(IGxObjectFilter);
pFilter = new GxFilterFeatureDatasetsAndFeatureClasses();
pgxdialog = new GxDialog();
//***Dim pgxobject As IGxObject
pgxdialog.AllowMultiSelect = true;
pgxdialog.StartingLocation = "f:";
pgxdialog.Title = "select files for input";
pgxdialog.ButtonCaption = "OK";
pgxdialog.ObjectFilter = pFilter;
pgxdialog.DoModalOpen(0, pEnumGxobject);
if (pEnumGxobject == null)
return;
IGxDataset pGxObject = default(IGxDataset);
IFeatureLayer pFLayer = default(IFeatureLayer);
pFLayer = new FeatureLayer();
pGxObject = pEnumGxobject.Next;
if (pGxObject == null)
return;
while ((pGxObject != null)) {
//***If TypeOf pGxObject.Dataset Is IFeatureClass Then
pFLayer.FeatureClass = pGxObject.Dataset;
pFLayer.Name = pGxObject.Dataset.Name;
this.AxMapControl1.AddLayer(pFLayer);
pGxObject = pEnumGxobject.Next;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
展开全部
你的代码可以调试通过啊,我试了没问题,你再仔细检查下,看mdb文件存放位置和你的路径参数是不是相符
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询