/// <summary>
/// 创建拓朴
/// </summary>
/// <param name="featureWorkspace">要素集工作空间</param>
/// <param name="featuredatasetName"></param>
/// <param name="featureClassName"></param>
/// <returns></returns>
public ITopology Create_Topology(IFeatureWorkspace featureWorkspace, string featuredatasetName, string featureClassName, string topologyName)
{
try
{
//1.---打开拓朴所在的要素数据集,并创建拓朴
IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(featuredatasetName);
if (featureDataset != null)
{
ITopologyContainer topologyContainer = (ITopologyContainer)featureDataset;
ITopology topology = topologyContainer.CreateTopology("topo", topologyContainer.DefaultClusterTolerance, -1, ""); //在这个地方报错
//2.---给拓朴加入要素集
IFeatureClassContainer featureclassContainer = (IFeatureClassContainer)featureDataset;
IFeatureClass featureClass = featureclassContainer.get_ClassByName(featureClassName);
topology.AddClass(featureClass, 5, 1, 1, false); // Parameters: AddClass(IClass, double weight, int xyrank, int zrank, Boolean EventNotificationOnValidate).
//3.---返回拓朴
return topology;
}
}
catch (Exception ex)
{
//System.Diagnostics.Debug.WriteLine(ex.ToString());
MessageBox.Show(ex.ToString());
}
return null;
}
private void CreateTopButton_Click(object sender, EventArgs e)
{
//打开目标数据库
IWorkspace fWorkspace = open_pGDB_Workspace("e:\\Topo.mdb");
IFeatureWorkspace fW = fWorkspace as IFeatureWorkspace;
//启动编辑
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)fWorkspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
//调用创建拓朴的方法
ITopology topology = Create_Topology(fW, "HN_DS", "HN", "Polygon_Topo");
//停止编辑
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
if (topology != null)
{
MessageBox.Show("创建拓朴成功!");
}
}
启动编辑是后来加上去的,若不启动编辑,则提示没有权限执行操作,