您的位置:首页 > 移动开发 > Objective-C

c#,arcengine,Arcobjects建立拓扑的完整例子

2008-04-20 17:30 323 查看
public void ValidateTopology(ITopology topology, IEnvelope envelope)
{
// Get the dirty area within the provided envelope.
IPolygon locationPolygon = new PolygonClass();
ISegmentCollection segmentCollection = (ISegmentCollection)locationPolygon;
segmentCollection.SetRectangle(envelope);
IPolygon polygon = topology.get_DirtyArea(locationPolygon);

// If a dirty area exists, validate the topology.
if (!polygon.IsEmpty)
{
// Define the area to validate and validate the topology.
IEnvelope areaToValidate = polygon.Envelope;
IEnvelope areaValidated = topology.ValidateTopology(areaToValidate);
}
}
public void AddRuleToTopology(ITopology topology, esriTopologyRuleType ruleType,
String ruleName, IFeatureClass originClass, int originSubtype, IFeatureClass
destinationClass, int destinationSubtype)
{
// Create a new topology rule.
ITopologyRule topologyRule = new TopologyRuleClass();
topologyRule.TopologyRuleType = ruleType;
topologyRule.Name = ruleName;
topologyRule.OriginClassID = originClass.FeatureClassID;
topologyRule.AllOriginSubtypes = false;
topologyRule.OriginSubtype = originSubtype;
topologyRule.DestinationClassID = destinationClass.FeatureClassID;
topologyRule.AllDestinationSubtypes = false;
topologyRule.DestinationSubtype = destinationSubtype;

// Cast the topology to the ITopologyRuleContainer interface and add the rule.
ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)
topology;
if (topologyRuleContainer.get_CanAddRule(topologyRule))
{
topologyRuleContainer.AddRule(topologyRule);
}
else
{
throw new ArgumentException("Could not add specified rule to the topology.")
;
}
}
public void AddRuleToTopology(ITopology topology, esriTopologyRuleType ruleType,
String ruleName, IFeatureClass featureClass)
{
// Create a new topology rule.
ITopologyRule topologyRule = new TopologyRuleClass();
topologyRule.TopologyRuleType = ruleType;
topologyRule.Name = ruleName;
topologyRule.OriginClassID = featureClass.FeatureClassID;
topologyRule.AllOriginSubtypes = true;

// Cast the topology to the ITopologyRuleContainer interface and add the rule.
ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)
topology;
if (topologyRuleContainer.get_CanAddRule(topologyRule))
{
topologyRuleContainer.AddRule(topologyRule);
}
else
{
throw new ArgumentException("Could not add specified rule to the topology.")
;
}
}
public void ValidateTopology(ITopology topology, IEnvelope envelope)
{
// Get the dirty area within the provided envelope.
IPolygon locationPolygon = new PolygonClass();
ISegmentCollection segmentCollection = (ISegmentCollection)locationPolygon;
segmentCollection.SetRectangle(envelope);
IPolygon polygon = topology.get_DirtyArea(locationPolygon);

// If a dirty area exists, validate the topology.
if (!polygon.IsEmpty)
{
// Define the area to validate and validate the topology.
IEnvelope areaToValidate = polygon.Envelope;
IEnvelope areaValidated = topology.ValidateTopology(areaToValidate);
}
}
public void CreateTopology()
{
// Open the workspace and the required datasets.
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
IWorkspace workspace = workspaceFactory.OpenFromFile(@
"C:/arcgis/ArcTutor/BuildingaGeodatabase/Montgomery.gdb", 0);
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(
"Landbase");
IFeatureClass blocksFC = featureWorkspace.OpenFeatureClass("Blocks");
IFeatureClass parcelsFC = featureWorkspace.OpenFeatureClass("Parcels");

// Attempt to acquire an exclusive schema lock on the feature dataset.
ISchemaLock schemaLock = (ISchemaLock)featureDataset;
try
{
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

// Create the topology.
ITopologyContainer2 topologyContainer = (ITopologyContainer2)featureDataset;
ITopology topology = topologyContainer.CreateTopology("Landbase_Topology",
topologyContainer.DefaultClusterTolerance, - 1, "");

// Add feature classes and rules to the topology.
topology.AddClass(blocksFC, 5, 1, 1, false);
topology.AddClass(parcelsFC, 5, 1, 1, false);
AddRuleToTopology(topology, esriTopologyRuleType.esriTRTAreaNoOverlap,
"No Block Overlap", blocksFC);
AddRuleToTopology(topology,
esriTopologyRuleType.esriTRTAreaCoveredByAreaClass,
"ResParcels Covered by ResBlocks", parcelsFC, 1, blocksFC, 1);

// Get an envelope with the topology's extents and validate the topology.
IGeoDataset geoDataset = (IGeoDataset)topology;
IEnvelope envelope = geoDataset.Extent;
ValidateTopology(topology, envelope);
}
catch (COMException comExc)
{
throw new Exception(String.Format(
"Error creating topology: {0} Message: {1}", comExc.ErrorCode,
comExc.Message), comExc);
}
finally
{
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
}
}

来自:arcengine的帮助
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: