Intersection of two feature

3199
6
02-26-2013 04:21 AM
FilippaFideria
New Contributor
Hi forum

I need your help.
I would like to create a function that calculates the intersection area of two features.
I use ArcMap 9.3.1, ArcObjects 9.3 and .NET language (particularly C#).
I would create a Tool Command that interset two Feauture of two different Personal Geodatabase (MDB).
I have no idea how to do it and I did not find code examples on the forum.
Could you suggest some code or some link, please?

Thanks in advance!
0 Kudos
6 Replies
LeoDonahue
Occasional Contributor III
ITopologicalOperator has an intersect method.
0 Kudos
FilippaFideria
New Contributor
Hi,
thanks for replay!
I have read the link posted
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//002m000003vs000000
but refer to ArcObject 10 and I use ArcObject 9.3.
In the link above there isn't an example to try intersection between two feature.

Can someone suggest me how use ITopologicalOperator.Intersct?
Please?

thanks in advance!
0 Kudos
LeoDonahue
Occasional Contributor III
Hi,
thanks for replay!
I have read the link posted
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//002m000003vs000000
but refer to ArcObject 10 and I use ArcObject 9.3.

I'm sorry. With a quick google search I'm sure you can find the 9.3 arcobjects help.


Can someone suggest me how use ITopologicalOperator.Intersct?
Please?

Ok, let's look at this together:

public IGeometry Intersect (     IGeometry other,     esriGeometryDimension resultDimension );


You have a public method that has a return type of IGeometry.  So, that means the result of calling this method must be assigned to some other variable, I would venture a guess it is something that implements the IGeometry Interface.

Some pseudocode may look like this:

IGeometry polygonOne = some feature geometry;
ITopologicalOperator topOp = (ITopologicalOperator) some feature geometry;
IGeometry resultPolygon = (IPolygon) to.intersect(polygonOne, one of these);
0 Kudos
WeifengHe
Occasional Contributor II
In order to get the area of intersection, both input geometries have to be polygon type geometry, and you need to choose the result dimenstion to be esriGeometry2Dimension.  And you will need IArea interface to get the area.

ITopologicalOperator t = polygon1
IGeometry g = t.Intersect(polygon2, esriGeometry2Dimension)
IArea a = g
a.Area is what you want.

There is no behavior change between 9.3 and 10 for Intersect method.
0 Kudos
FilippaFideria
New Contributor
In order to get the area of intersection, both input geometries have to be polygon type geometry, and you need to choose the result dimenstion to be esriGeometry2Dimension.  And you will need IArea interface to get the area.

ITopologicalOperator t = polygon1
IGeometry g = t.Intersect(polygon2, esriGeometry2Dimension)
IArea a = g
a.Area is what you want.

There is no behavior change between 9.3 and 10 for Intersect method.


Thanks thanks thanks a lot for reply!!!
I'm not an expert with ArcObjects development and I think that the argument of intersectios is very difficult!
I have tested your code and something happens but I don't understand if the result is correct.

How can I pass to the code suggested by you, a selected feature?
I know how select a feature but I don't know how assign a selected feature to:
ITopologicalOperator t = (ITopologicalOperator)Feat.Shape;
Instead of (ITopologicalOperator)Feat.Shape there should be (ITopologicalOperator)selectedFeature.

How can I do this?

Thank thanks thanks so much!
0 Kudos
WeifengHe
Occasional Contributor II
You can store the result geometry to database or draw in ArcMap to verify whether or not the output is correct.

There is code snippet in ArcObjects SDK to select map features by attribute query.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000088000000

You can also select the feature using IFeatureClass::Search with query filter set, this will return a feature cursor.  Call IFeatureCursor::NextFeature gets the feature object you want.
0 Kudos