Arcengine topology (zz)

Source: Internet
Author: User
[Code]
C #, arcengine, and ArcObjects
Public void validatetopology (itopology topology, ienvelope envelope)
{
// Get the dirty area within the provided envelope.
Ipolympus Gon locationpolygon = new polygonclass ();
Isegmentcollection segmentcollection = (isegmentcollection) locationpolygon;
Segmentcollection. setrectangle (envelope );
Ipolympus Gon 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 addruletopology (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 ("cocould not add specified rule to the topology .")
;
}
}
Public void addruletopology (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 ("cocould not add specified rule to the topology .")
;
}
}
Public void validatetopology (itopology topology, ienvelope envelope)
{
// Get the dirty area within the provided envelope.
Ipolympus Gon locationpolygon = new polygonclass ();
Isegmentcollection segmentcollection = (isegmentcollection) locationpolygon;
Segmentcollection. setrectangle (envelope );
Ipolympus Gon 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);
addruletopology (topology, esritopologyruletype. esritrtareanooverlap,
"no block overlap", blocksfc );
addruletopology (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 );
}
}

[/Code]

 

 

Topology is a set of topological relationships between feature classes under the same feature set (featuredataset. Therefore, to participate in all the element classes of a topology, the topology check must be accurate within the same element set (that is, with the same spatial reference. One element set can have multiple topologies, but each element class can only participate in one topology. Multiple rules can be defined in one topology. Topology analysis process: 1. Create a topology (add topology Rules) ii. Verify Topology 3. Ensure correct topology during editing 4. query the existing topology in the system ******************** **************************************** * ******************* 1. Topology creation method: 1: Use the arccatalog desktop; 2: Use Program (Arcengine) develops and establishes a topology. The implementation interface for establishing a topology in the engine is itopologycontainer: createtopology; itopologycontainer: createtopology to create a topology. Interface Description: itopologycontainer is a platform container used to create, add, and manage topologies. Through this interface, you can understand the topology information of the current element set, such as the name; if you only want to obtain the topology information of a feature set, we recommend that you use the ifeaturedatasetnames: topologynames method instead of using this interface to open the topology. Once the topology is created using the createtopology method, the parameters of this topology cannot be changed. To change the topology, You need to delete or re-create a new topology. Defaultclustertolerance is the default "tolerance" for topology creation; maximumclustertolerance indicates the maximum "tolerance"; minimumclustertolerance indicates the minimum "tolerance "; if the tolerance parameter you use when creating a topology is between the maximum and minimum, the parameter is valid. For example, if the tolerance parameter is between the maximum and minimum, the process is based on the extreme values (the maximum and the minimum; note that the default tolerance is the same as the minimum tolerance. To create a topology rule, use the itopologyrulecontainer interface. Interface Description: The irule interface is the interface for defining rules in the engine, the Type attribute includes the following types: esrirttopology is used to create topology rules, and Topology rules are implemented through the itopologyrule interface. And add the defined rule to the current topology through the itopologyrulecontainer interface (addrule method ). The itopology interface and the itopologyrulecontainer interface inherit from the topology class, so they can be Qi. Note the problems that may occur when you create a topology: 1. When all elements in the element set have participated in the creation of other topologies, an error occurs when you use the used element class to create a new topology; 2: When the element has been involved in the geometry network operation, the topology creation error also occurs. 3: The target element class is a note layer or multi-dimensional layer, and the topology cannot be created; 4: The target element category has been registered as a version, so no topology can be created. 2. Topology verification (validate) method: 1: After the topology is created in arccatalog, you can select direct verification. 2. You can also verify the created topology In ArcMap (the elements must be in the edit state start edit), and then you can edit the topology. 3: the program is used for verification. The itopology method validatetopology is used to verify the topology in the specified region. Note that topology without a version can be verified at any time. A version topology must be verified in the edit session. After verification, the current topology can check the corresponding topology error and generate the topology layer itopologylayeritopologylayer, which is actually a layer that inherits from the layer class. Interface Description: The itopologylayer interface has a method for rendering Renderer. You can perform classification rendering based on the topology error information (esritopologyrenderer. 3. Topology Editing: after verifying the topology analysis, you need to edit and change the current topology error. During topology editing, we need to know the concept of topologygraph. What is topologygraph? In fact, after topology analysis, we need to edit the wrong line and point (because the polygon is also composed of wired and vertex) to modify the current element error. The topologygraph topology is generated before editing. The topology graph displays the nodes, edges, and other information to be modified. The edits we make are actually performed on topologygraph. As mentioned above, when the itopologylayer is created, the cache exists in the memory. The topologygraph is created using the itopologylayer cache. The method is as follows: // topolayer is an open topology layer. itopologygraph PTG = topolayer. topology. cache; PTG. build (Pa. extent, false); Create a topology, where pa. extent is the scope to be analyzed. Interface Description: In the interface attribute method, we can see many operations on element editing. That's right. A large part of topology editing is actually done using this method. Such as cutting, rebuilding, and deleting. The hittest method is used to obtain the edges and nodes that you click. You can use itopologynode and itopologyedge to obtain edges and vertices. You can use the itopologyerrorfeature interface to obtain the element feature that produces errors. It inherits from the feature class. The itopologyerrorselection interface operates on the current topologylayer to check whether errors are available. The itopologyextension is an extension of the current topology, including setting the style symbol of error elements. Note: This interface can only be obtained under the desktop license, and the engine cannot be used. Then someone will ask: "If we change the color of the topology layer and Topology elements, the engine will not be able to do it ?" Oh, of course not. Don't forget the itopologylayer interface I mentioned earlier. Using this interface, we can also perform Renderer rendering on the layer. For more information, see the Help help documentation! Topology elements (node and edges) after editing, we can submit the changes. Itopologygraph: the post method submits the edits. Partially edited Code : **************************************** * ********* Set ptopologygraph = ptopology. cacheptopologygraph. build pmxdoc. activeview. extent, falseset penumtopologyedge = ptopologygraph. edgesset ptopologyedge = penumtopologyedge. nextbsel = ptopologygraph. select (esritopologyselectionresultnew, ptopologyedge) set paffine = new affinetransformation2dpaffine. move 10, 10ptopologygraph. transformselection esritra Nsformforward, paffine, falseptopologygraph. post pgdset. extent '''submit and edit *********************************** * *************** This completes the entire topology creation, verification, and editing process. If you want to view the topology, you can use the itopologyworkspace: opentopology method to open the topology. Important: if we are not satisfied with the current topology and need to delete it, we should first clear the element class removeclass (itopology Interface) in the current topology, and then delete (Dataset Interface) the topology, otherwise, an error occurs. Appendix: 1. Topology Error Type in the topology data layer (itopologylayer): As a layer, Renderer rendering can be performed. The following types can also be rendered. esritrareaerrors0 area error Renderer. esritrlineerrors1 Line Error Renderer. esritrpointerrors2 point error Renderer. esritrareaexceptions3 polygon exception Renderer. esritrlineexceptions4 line exception Renderer. esritrpointexceptions 5 point exception Renderer. esritrdirtyareas6 dirty area Renderer 2. Geodatabase topology rule: polygon topology rule 1. must not overlay: single element class, polygon elements cannot overlap. must not have gaps: Single-element class. There cannot be blank areas (non-data areas) in the consecutive polygon areas. contains point: polygon + point. The boundary of each element of the polygon element class must contain at least one point in the vertex layer. boundary must be covered by: polygon + line. The Boundary Layer boundary overlaps with the line layer (the line layer can have more non-overlapping elements. must be covered by feature class of: polygon + polygon, the first polygon layer must be completely covered by the second (the relationship between the Province and the country) 6. must be covered by: polygon + polygon. The first polygon layer must completely overwrite the second one (the relationship between the nation and the province. must not overlay with: polygon + polygon. Two Polygon Layers cannot have a pair of elements that overlap with each other. must cover each other: polygon + polygon. The elements of the two polygon must overlap completely. area boundary must be covered by boundary of: polygon + polygon. Each element of the first polygon must cover 10 of the second polygon. must be properly inside polygons: points + polygon. All elements of the Point layer must be within the polygon 11. must be covered by boundary of: Point + polygon. points must be added to the boundary of the polygon. Rule 1. must not have dangle: line, no hanging Node 2. must not have pseudo-node: line, cannot have pseudo Node 3. must not overlay: line, cannot overlap (between different elements) 4. must not self overlay: line. One element cannot overwrite itself. must not intersect: line, cannot line * (between different elements) 6. must not self intersect: line, cannot be wired * 7. must not intersect or touch interrior: line. There must be no intersection or overlap. must be single part: Line, a line element can only consist of one path 9. must not covered with: line + line, two layers of lines cannot overlap 10. must be covered by feature class of: line + line, two lines completely overlap 11. endpoint must be covered by: line + point. The end point in the line layer must overlap with some (or all) points in the point layer. must be covered by boundary of: line + polygon, line overlapped by Polygon boundary 13. must be covered by endpoint of: Point + line, point completely overlapped by line end 14. point must be covered by line: Point + line, all online

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yzg686/archive/2009/12/24/5071129.aspx

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.