In this topic
Creating a multipoint using the ConstructIntersectionEx method
The following shows how to use the ConstructIntersectionEx method to create a multipoint.
Intersecting two straight lines to generate a multipoint
Do the following steps to intersect two straight lines to generate a multipoint:
- Create two points, fromPoint0 and toPoint0.
- Create a line (line0) by calling PutCoords of fromPoint0 and toPoint0.
- Create two points, fromPoint1 and toPoint1.
- Create a line (line1) by calling PutCoords of fromPoint1 and toPoint1.
- Create an instance of MultiPoint object multipoint.
- Call ConstructIntersectionEx on line0 and line1.
- Query interface (QI) multipoint to IPointCollection and print each point in the pointcollection.
Intersecting a beziér curve and circular curve
Do the following steps to intersect a beziér curve and a circular arc:
- Create a point array of four points.
- Use the point array to define a new beziér curve (called bezierCurve).
- Create three points, named fromPoint, toPoint, and centerPoint.
- Create a CircularArc using IConstructCircularArc.
- Call IConstructCircularArc.ConstructThreePoints using the three points to define the CicularArc.
- Create an instance of MultiPoint object multipoint.
- Call ConstructIntersectionEx on the beziér curve and circular arc.
- QI multipoint to IPointCollection and print each point in the pointcollection.
See the following code example:
[C#] public void ConstructIntersectionExTest()
{
//Case 0 - No intersection (extension needed for line0) line0 meet at line1 in middle.
String title0="**** Case 0 - Line 0 needs extension ****";
IPoint fromPoint0=new PointClass();
fromPoint0.PutCoords(0, 0);
IPoint toPoint0=new PointClass();
toPoint0.PutCoords(10, 10);
ILine line0=new LineClass();
line0.PutCoords(fromPoint0, toPoint0);
IPoint fromPoint1=new PointClass();
fromPoint1.PutCoords(0, 0);
IPoint toPoint1=new PointClass();
toPoint1.PutCoords(10, 10);
ILine line1=new LineClass();
line1.PutCoords(fromPoint1, toPoint1);
ConstructIntersectionEx1(line0, line1, title0);
//Case 1 - Lines intersect in middle.
String title1="**** Case 1 - Intersecting Lines ****";
IPoint fromPoint2=new PointClass();
fromPoint2.PutCoords(0, 0);
IPoint toPoint2=new PointClass();
toPoint2.PutCoords(10, 10);
ILine line2=new LineClass();
line2.PutCoords(fromPoint2, toPoint2);
IPoint fromPoint3=new PointClass();
fromPoint3.PutCoords(10, 0);
IPoint toPoint3=new PointClass();
toPoint3.PutCoords(0, 10);
ILine line3=new LineClass();
line3.PutCoords(fromPoint3, toPoint3);
ConstructIntersectionEx1(line2, line3, title1);
//Case 2 - No Intersection (lines both need extensions).
String title2="**** Case 2 - Extensions needed for both lines ****";
IPoint fromPoint4=new PointClass();
fromPoint4.PutCoords(0, 0);
IPoint toPoint4=new PointClass();
toPoint4.PutCoords(10, 10);
ILine line4=new LineClass();
line4.PutCoords(fromPoint4, toPoint4);
IPoint fromPoint5=new PointClass();
fromPoint5.PutCoords(15, 10);
IPoint toPoint5=new PointClass();
toPoint5.PutCoords(25, 0);
ILine line5=new LineClass();
line5.PutCoords(fromPoint5, toPoint5);
ConstructIntersectionEx1(line4, line5, title2);
//Example 2.
ConstructIntersectionEx2();
}
//These examples demonstrate how to use the ConstructIntersectionEx method.
//Example 1: With line segments only.
private void ConstructIntersectionEx1(ILine line0, ILine line1, String title)
{
//Create a multipoint.
IConstructMultipoint constructMultipoint=new MultipointClass();
//Construct the intersections.
//Params optional.
double param0;
double param1;
int bits;
constructMultipoint.ConstructIntersectionEx(line0 as ISegment,
esriSegmentExtension.esriExtendEmbedded, line1 as ISegment,
esriSegmentExtension.esriExtendEmbedded, out param0, out param1, out bits);
//Prints results.
IPointCollection pointCollcetion=constructMultipoint as IPointCollection;
if (pointCollcetion.PointCount == 0)
{
System.Windows.Forms.MessageBox.Show("No intersecting points");
}
for (int i=0; i < pointCollcetion.PointCount; i++)
{
System.Windows.Forms.MessageBox.Show(title + "\n" +
"Intersection Point i, X, Y : " + i + " , " + pointCollcetion.get_Point
(i).X + " , " + pointCollcetion.get_Point(i).Y);
}
}
//Example 2 - With curves.
private void ConstructIntersectionEx2()
{
IPoint[] points=new IPoint[4];
for (int i=0; i < 4; i++)
{
points[i]=new PointClass();
}
points[0].PutCoords(150, 100);
points[1].PutCoords(200, 600);
points[2].PutCoords(400, 600);
points[3].PutCoords(450, 100);
IBezierCurveGEN bezierCurve=new BezierCurveClass();
bezierCurve.PutCoords(ref points);
IPoint centerPoint=new PointClass();
centerPoint.PutCoords(300, 300);
IPoint fromPoint=new PointClass();
fromPoint.PutCoords(100, 100);
IPoint toPoint=new PointClass();
toPoint.PutCoords(500, 100);
IConstructCircularArc circularArcConstruction=new CircularArcClass();
circularArcConstruction.ConstructThreePoints(fromPoint, centerPoint, toPoint,
false);
//Params optional.
double param0;
double param1;
int bits;
IConstructMultipoint constructMultipoint=new MultipointClass();
constructMultipoint.ConstructIntersectionEx(circularArcConstruction as ISegment,
esriSegmentExtension.esriNoExtension, bezierCurve as ISegment,
esriSegmentExtension.esriNoExtension, out param0, out param1, out bits);
IMultipoint multipoint=constructMultipoint as IMultipoint;
IPointCollection pointCollection=multipoint as IPointCollection;
for (int i=0; i < pointCollection.PointCount; i++)
{
System.Windows.Forms.MessageBox.Show("Example2: Point : " +
pointCollection.get_Point(i).X + " , " + pointCollection.get_Point(i).Y);
}
}
[VB.NET] 'Example 1: With line segments only.
Sub example_ConstructIntersectionEx()
Dim pLine0 As ILine, pLine1 As ILine
Dim pt0fr As IPoint, pt0to As IPoint
Dim pt1fr As IPoint, pt1to As IPoint
Dim pConstructMpt As IConstructMultipoint
Dim pSegment0 As ISegment, pSegment1 As ISegment
'Lines will never have more than one intersection.
Dim dParam0(0) As Double, dParam1(0) As Double, lbits(0) As Long
Dim i As Long, ptc As IPointCollection
'Create lines objects.
pLine0=New Line
pLine1=New Line
'Create from/to point object to build lines.
pt0fr=New Point
pt0to=New Point
pt1fr=New Point
pt1to=New Point
'Case 0 - No intersection (extension needed for line0) line0 meet at line1 in middle.
Debug.Print("**** Case 0 - Line 0 needs extension ****")
'Construct the lines.
pt0fr.PutCoords(0, 0)
pt0to.PutCoords(10, 10)
pLine0.PutCoords(pt0fr, pt0to)
pt1fr.PutCoords(7, 30)
pt1to.PutCoords(30, 0)
pLine1.PutCoords(pt1fr, pt1to)
'Create a multipoint.
pConstructMpt=New Multipoint
pSegment0=pLine0 'QI.
pSegment1=pLine1 'QI.
'Construct the intersections.
pConstructMpt.ConstructIntersectionEx(pSegment0, esriSegmentExtension.esriExtendEmbedded, pSegment1, esriSegmentExtension.esriExtendEmbedded, dParam0(0), dParam1(0), lbits(0))
'Prints results.
ptc=pConstructMpt
For i=0 To ptc.PointCount - 1
Debug.Print("Intersection Point i, X, Y : " & i & " , " & ptc.Point(i).X & " , " & ptc.Point(i).Y)
Next
For i=0 To UBound(dParam0)
Debug.Print("Parametric distances segment 0 : " & i & " , " & dParam0(i))
Next
For i=0 To UBound(dParam1)
Debug.Print("Parametric distances segment 1 : " & i & " , " & dParam1(i))
Next
For i=0 To UBound(lbits)
Debug.Print("Tangent bits : " & i & " , " & lbits(i))
Next
'Case 1 - Lines intersect in middle.
Debug.Print("**** Case 1 - Intersecting Lines ****")
'Construct lines segments.
pt0fr.PutCoords(0, 0)
pt0to.PutCoords(10, 10)
pLine0.PutCoords(pt0fr, pt0to)
pt1fr.PutCoords(10, 0)
pt1to.PutCoords(0, 10)
pLine1.PutCoords(pt1fr, pt1to)
'Create a multipoint.
pConstructMpt=New Multipoint
pSegment0=pLine0 'QI.
pSegment1=pLine1 'QI.
'Construct the intersections.
pConstructMpt.ConstructIntersectionEx(pSegment0, esriSegmentExtension.esriExtendEmbedded, pSegment1, esriSegmentExtension.esriExtendEmbedded, dParam0(0), dParam1(0), lbits(0))
'Prints results.
ptc=pConstructMpt
For i=0 To ptc.PointCount - 1
Debug.Print("Intersection Point i, X, Y : " & i & " , " & ptc.Point(i).X & " , " & ptc.Point(i).Y)
Next
For i=0 To UBound(dParam0)
Debug.Print("Parametric distances segment 0 : " & i & " , " & dParam0(i))
Next
For i=0 To UBound(dParam1)
Debug.Print("Parametric distances segment 1 : " & i & " , " & dParam1(i))
Next
For i=0 To UBound(lbits)
Debug.Print("Tangent bits : " & i & " , " & lbits(i))
Next
'Case 2 - No intersection (lines both need extensions).
Debug.Print("**** Case 2 - Extensions needed for both lines ****")
pt0fr.PutCoords(0, 0)
pt0to.PutCoords(10, 10)
pLine0.PutCoords(pt0fr, pt0to)
pt1fr.PutCoords(15, 10)
pt1to.PutCoords(25, 0)
pLine1.PutCoords(pt1fr, pt1to)
'Create a multipoint.
pConstructMpt=New Multipoint
pSegment0=pLine0 'QI.
pSegment1=pLine1 'QI.
'Construct the intersections.
pConstructMpt.ConstructIntersectionEx(pSegment0, esriSegmentExtension.esriExtendEmbedded, pSegment1, esriSegmentExtension.esriExtendEmbedded, dParam0(0), dParam1(0), lbits(0))
'Prints results.
ptc=pConstructMpt
For i=0 To ptc.PointCount - 1
Debug.Print("Intersection Point i, X, Y : " & i & " , " & ptc.Point(i).X & " , " & ptc.Point(i).Y)
Next
For i=0 To UBound(dParam0)
Debug.Print("Parametric distances segment 0 : " & i & " , " & dParam0(i))
Next
For i=0 To UBound(dParam1)
Debug.Print("Parametric distances segment 1 : " & i & " , " & dParam1(i))
Next
For i=0 To UBound(lbits)
Debug.Print("Tangent bits : " & i & " , " & lbits(i))
Next
End Sub
'Example 2 - With curves.
Private Sub ConstructIntersectionEx()
Dim pConstructCircularArc As IConstructCircularArc
Dim pCArc As ICircularArc
Dim pPoint1 As IPoint
Dim pPoint2 As IPoint
Dim pPoint3 As IPoint
Dim pTcoll As IPointCollection
Dim pConstructMultipoint As IConstructMultipoint
Dim pMultipoint As IMultipoint
Dim i As Long
Dim pBezier As IBezierCurve
Dim pPtCon(0 To 3) As IPoint
Dim pa1(13) As Double
Dim pa2(13) As Double
Dim pa3 As Long
For i=0 To 3
pPtCon(i)=New Point
Next
pPtCon(0).PutCoords(150, 100)
pPtCon(1).PutCoords(200, 600)
pPtCon(2).PutCoords(400, 600)
pPtCon(3).PutCoords(450, 100)
pBezier=New BezierCurve
pBezier.PutCoords(4, pPtCon(0))
pConstructMultipoint=New Multipoint
pConstructCircularArc=New CircularArc
pCArc=pConstructCircularArc
pPoint1=New Point
pPoint2=New Point
pPoint3=New Point
pPoint1.PutCoords(100, 100)
pPoint2.PutCoords(300, 300)
pPoint3.PutCoords(500, 100)
pConstructCircularArc.ConstructThreePoints(pPoint1, pPoint2, pPoint3, False)
pConstructMultipoint.ConstructIntersectionEx(pCArc, esriSegmentExtension.esriNoExtension, pBezier, esriSegmentExtension.esriNoExtension, pa1(0), pa2(0), pa3)
'The parametric distance along the segment1.
Debug.Print("******************************************")
Debug.Print("Parametric distance along the segment 1")
Debug.Print("******************************************")
For i=0 To UBound(pa1)
Debug.Print(pa1(i))
Next
'The parametric distance along the segment2.
Debug.Print("******************************************")
Debug.Print("Parametric distance along the segment 2")
Debug.Print("******************************************")
For i=0 To UBound(pa2)
Debug.Print(pa2(i))
Next
pMultipoint=pConstructMultipoint
pTcoll=pMultipoint
Debug.Print("*********************************************")
Debug.Print(" Report the points")
Debug.Print("*********************************************")
For i=0 To pTcoll.PointCount - 1
Debug.Print("Point : " & pTcoll.Point(i).X & " , " & pTcoll.Point(i).Y)
Next
End Sub
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Advanced | ArcGIS for Desktop Basic |
Engine Developer Kit | ArcGIS for Desktop Standard |
ArcGIS for Desktop Basic | ArcGIS for Desktop Advanced |
ArcGIS for Desktop Standard | Engine |