Select to view content in your preferred language

How Intersect (Analysis) works - So How Do I Use It?

839
7
06-13-2011 11:55 AM
DougMarquardt
Emerging Contributor
Found this link in the docs that talks about exactly what I need to do:


http://edndoc.esri.com/arcobjects/9.2/NET/shared/geoprocessing/analysis_tools/how_intersect_analysis...

But I can't find any code examples, etc on actually doing this?

I have a polygon and a polyline and I want to get the intersects between the two.

Is this functionality even available with .Net and ArcGISEngine 10?

Can someone please point me in the right direction here.



Doug.
0 Kudos
7 Replies
DougMarquardt
Emerging Contributor
Well, I did find some info on ESRI.ArcGIS.AnalysisTools.Intersect but no code examples.
I tried this but nothing happens...



                    Dim shpL As New List(Of Object)
                    shpL.Add(plyLine)
                    shpL.Add(plyGon)

                    Dim shpLI As Object = Nothing
                    Dim isect As New ESRI.ArcGIS.AnalysisTools.Intersect(shpL, shpLI)
                    shpLI = isect.out_feature_class


Can someone provide a code example on using ESRI.ArcGIS.AnalysisTools.Intersect?

Doug.
0 Kudos
KenBuja
MVP Esteemed Contributor
Take a look at this thread on how to set up the Geoprocessor for the Analysis Tools. If I ever have trouble in setting up the code to run a tool, I run the tool manually and examine the results page to see what the syntax looks like.
0 Kudos
ESRICustomer
Occasional Contributor
Found this link in the docs that talks about exactly what I need to do:


http://edndoc.esri.com/arcobjects/9.2/NET/shared/geoprocessing/analysis_tools/how_intersect_analysis...

But I can't find any code examples, etc on actually doing this?

I have a polygon and a polyline and I want to get the intersects between the two.

Is this functionality even available with .Net and ArcGISEngine 10?

Can someone please point me in the right direction here.



Doug.



I don't know anything about Analysis services, but I am calculating intersections, overlapping areas, etc, with ITopologicalOperator4, IRelationalOperator, IProximityOperator, and IGeometry5.  For an intersection for example, I simply take an IFeature.Shape and intersect it with another IFeature.Shape...

Friend Function GetIntersectedPolygon(ByVal OtherPolygon As IGeometry5) As IGeometry5
Dim intersectedGeometry As IGeometry5 = Nothing
intersectedGeometry = ITopologicalOperator4.Intersect(OtherPolygon, esriGeometryDimension.esriGeometry2Dimension)
Return intersectedGeometry
End Function
0 Kudos
DougMarquardt
Emerging Contributor
Hi kenbuja,

I can't run any tool manually as I am only licensed for ArcGISEngine.

The example helped a bit, but I still need to know how to pass a 'list' of objects in to the in_features parameter....


Doug.
0 Kudos
DougMarquardt
Emerging Contributor
I finally got this thing working 😄

Here is code example of what I did in case it helps anyone else:

                Dim gp As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
                gp.SetEnvironmentValue("workspace", wksp.PathName)

                Dim s As String = ""
                Dim vt As ESRI.ArcGIS.Geoprocessing.IGpValueTableObject = New ESRI.ArcGIS.Geoprocessing.GpValueTableObjectClass()
                vt.SetColumns(2)
                s = GetPathForALayer(MyPolygonLayer)
                vt.AddRow("'" & s & "' 1")
                s = GetPathForALayer(MyPolylineLayer)
                vt.AddRow("'" & s & "' 2")

                Dim fcname As String = "my_intersect_" & MyID & "_" & Guid.NewGuid.ToString.Replace("-", "")  'Uses a guid to ensure unique name
                s = System.IO.Path.Combine(wksp.PathName, fcName)
                Dim pVarArray As IVariantArray = New VarArrayClass()
                pVarArray.Add(vt)
                pVarArray.Add(s)

                gp.Execute("intersect_analysis", pVarArray, Nothing)

                Dim fWk As IFeatureWorkspace = wksp
                Dim fcTmp = fWk.OpenFeatureClass(fcname)


Cheers!
0 Kudos
DougMarquardt
Emerging Contributor
I don't know anything about Analysis services, but I am calculating intersections, overlapping areas, etc, with ITopologicalOperator4, IRelationalOperator, IProximityOperator, and IGeometry5.  For an intersection for example, I simply take an IFeature.Shape and intersect it with another IFeature.Shape...

Friend Function GetIntersectedPolygon(ByVal OtherPolygon As IGeometry5) As IGeometry5
Dim intersectedGeometry As IGeometry5 = Nothing
intersectedGeometry = ITopologicalOperator4.Intersect(OtherPolygon, esriGeometryDimension.esriGeometry2Dimension)
Return intersectedGeometry
End Function


I've posted a solution that I finally got working, but your solution seems interesting and I will check it out.

Thanks.
0 Kudos
KenBuja
MVP Esteemed Contributor
Here's another way to do it

       IGPUtilities2 gpUtils = new GPUtilitiesClass();
       IFeatureClass inFeature1 = gpUtils.OpenFeatureClassFromString(@" ");//path of the 1st Input Feature Class
       IFeatureClass inFeature2 = gpUtils.OpenFeatureClassFromString(@" ");//path of the 2nd Input Feature Class
       IFeatureClass inFeature3 = gpUtils.OpenFeatureClassFromString(@" ");//path of the 3rd Input Feature Class
       Test(inFeature1, inFeature2, inFeature3);


       private void Test(IFeatureClass pf1,IFeatureClass pf2,IFeatureClass pf3)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                GP.OverwriteOutput = true;
                IGPUtilities2 gpUtils = new GPUtilitiesClass();
                IGpValueTableObject vt = new GpValueTableObjectClass();
                
                vt.SetColumns(2);
                object weight;
                weight = 1 as object;

                object obj1 = pf1;
                vt.AddRow(ref obj1);
                vt.SetValue(0, 1, ref weight);

                object obj2 = pf2;
                vt.AddRow(ref obj2);
                vt.SetValue(1, 1, ref weight);

                object obj3 = pf3;
                vt.AddRow(ref obj3);
                vt.SetValue(2, 1, ref weight);

                ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                intersect.in_features = vt;
                intersect.out_feature_class = @"D:\Neil'sData\Output\New1.shp";//Specify The Output path
                GP.Execute(intersect, null);
                MessageBox.Show("Intersection is Successfull!!!!!!");
            }
            catch (Exception e1)
            {
                MessageBox.Show("error!!!!");
             }
        }
0 Kudos