Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
Can you post the source for the other referenced functions (IsNullOrEmptyGeometry and IsGeometryIntersect)? Also do you have any test data in WKT form that reproduces the error? –  blah238 Feb 28 '13 at 3:50
    
Also, do any/all/none of the geometries have SpatialReferences? –  blah238 Feb 28 '13 at 3:52
    
On your second invocation of GetOverlappedGeometry did you mean GetOverlappedGeometry(geom3, overlapped1) instead of GetOverlappedGeometry(geom3, overlapped2)? –  blah238 Feb 28 '13 at 4:42
    
yes, I meant GetOverlappedGeometry(geom3, overlapped1) –  gkar Feb 28 '13 at 4:51
    
And regarding the other functions, they are irrelevant because they are not generating any errors. The error occur on the call of Intersection –  gkar Feb 28 '13 at 4:52

1 Answer 1

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)
share|improve this answer
    
Appreciate your help. I will try to find what is different. As I told you the code is working on 9.3 –  gkar Feb 28 '13 at 16:06
    
Hi Blah... I am not able to run your code, even it is very simple. I am using the same library you used. I will post my result. –  gkar Feb 28 '13 at 20:09
    
Blah I found the problem. The problem is I am doing intersection between 2 polylines to give result a new polyline, which in 10.1 I cannot do it. I changed my question above. –  gkar Mar 1 '13 at 17:19
    
I addressed that a while ago... you know that the intersection of two lines can be either a line OR a point, right? How can you be sure that the intersection of your two geometries is always going to be a line and not a point? –  blah238 Mar 1 '13 at 17:30
    
so, I don't understand your comment. Does that mean the operation is invalid in 10.1 ? I tested it on 9.3 and it is working. So, what am I supposed to do? –  gkar Mar 1 '13 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.