[GIS] Intersect, Union are failing on 10.1

arcgis-10.1arcobjectsc

After a huge help from Blah238.

I found exactly what is the problem.

I wasted few days checking our data, and trying many things.

The problem that I cannot do intersection between two polylines to give a result a new polyline.

It was working on 9.3. So I am not sure if it is not supposed to work , or why it is not working on 10.1

So, I modified the code to this.
Now this code is generating COM exception on my machine.

Blah can you please help if you can

        static void Main(string[] args)
    {
        //ESRI License Initializer generated code.
        m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced },
        new esriLicenseExtensionCode[] { });

        var geom1 = "LINESTRING (2 1, 7 1)".ToGeometry();
        var geom2 = "LINESTRING (3 1, 6 1)".ToGeometry();
        var targetOperator = (ITopologicalOperator)geom1;
        targetOperator.Simplify();

        IGeometry intersectGeometry = targetOperator.Intersect(geom2, geom2.Dimension);
        Console.WriteLine(overlapped1.ToWellKnownText());


        m_AOLicenseInitializer.ShutdownApplication();

    }

    static IGeometry GetOverlappedGeometry(IGeometry sourceGeometry, IGeometry targetGeometry, esriGeometryDimension dimension)
    {
        IGeometry overlappedGeometry = null;

        IGeometry localSourceGeometry;
        IGeometry localTargetGeometry;

        if (sourceGeometry.GeometryType > targetGeometry.GeometryType)
        {
            localSourceGeometry = targetGeometry;
            localTargetGeometry = sourceGeometry;
        }
        else
        {
            localSourceGeometry = sourceGeometry;
            localTargetGeometry = targetGeometry;
        }

        var targetOperator = (ITopologicalOperator)localTargetGeometry;

        if (targetOperator != null)
        {
            targetOperator.Simplify();

            IGeometry intersectGeometry = targetOperator.Intersect(localSourceGeometry, dimension);

            overlappedGeometry = intersectGeometry;
        }

        return overlappedGeometry;
    }

Please notice that the code is different that Blah code down , that I am using the dimension 1 is the intersection, and not dim0
Because I want a polyline
What the problem with 10.1?

Why I was able to do it on 9.3?

Best Answer

Update: Apparently this is fixed at 10.2: ITopologicalOperator::Intersect() fails with overlapping horizontal or vertical polylines in ArcGIS 10.1.

If I modify your method signature to allow me to specify the expected dimension of intersection I get the expected output given my test cases (given in WKT below).

I adapted the WKT extension methods (GitHub repo here) from the DNRGPS source. LINQPad 4 query Gist here.

using System;
using DnrGps_Wkt;
using ESRI.ArcGIS.Geometry;

namespace WKTTest
{
    class Program
    {
        static void Main(string[] args)
        {
            if (ESRI.ArcGIS.RuntimeManager.ActiveRuntime == null)
                ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

            var geom1 = "LINESTRING (0 0, 2 2)".ToGeometry();
            var geom2 = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))".ToGeometry();
            var geom3 = "LINESTRING (0 1, 1 0)".ToGeometry();
            var overlapped1 = GetOverlappedGeometry(geom1, geom2, esriGeometryDimension.esriGeometry1Dimension);
            Console.WriteLine(overlapped1.ToWellKnownText());
            var overlapped2 = GetOverlappedGeometry(geom3, overlapped1, esriGeometryDimension.esriGeometry0Dimension);
            Console.WriteLine(overlapped2.ToWellKnownText());
        }

        static IGeometry GetOverlappedGeometry(IGeometry sourceGeometry, IGeometry targetGeometry, esriGeometryDimension dimension)
        {
            IGeometry overlappedGeometry = null;

            IGeometry localSourceGeometry;
            IGeometry localTargetGeometry;

            if (sourceGeometry.GeometryType > targetGeometry.GeometryType)
            {
                localSourceGeometry = targetGeometry;
                localTargetGeometry = sourceGeometry;
            }
            else
            {
                localSourceGeometry = sourceGeometry;
                localTargetGeometry = targetGeometry;
            }

            var targetOperator = (ITopologicalOperator)localTargetGeometry;

            if (targetOperator != null)
            {
                targetOperator.Simplify();

                IGeometry intersectGeometry = targetOperator.Intersect(localSourceGeometry, dimension);

                overlappedGeometry = intersectGeometry;
            }

            return overlappedGeometry;
        }
    }
}

This outputs:

LINESTRING (0 0,1.00000190734863 1.00000190734863)
MULTIPOINT (0.500001907348633 0.500001907348633)
Related Question