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.
This outputs: