Hi Edgar,
Thanks for your help but I have one case where there is a problem.
If I cut the polygon on the one single side,
I have this result
The result is 2 equals polygons.
So I did some modifications in the class splitter
public static MultipolygonShape Split(PolygonShape processedPolygon, LineShape lineShape)
{
MultipolygonShape resultShape = new MultipolygonShape();
MultipointShape intersectionMultiPoint = lineShape.GetCrossing(processedPolygon.OuterRing);
if (intersectionMultiPoint.Points.Count == 2)
{
PolygonShape polygonShape1 = GetPolygonForSplit(processedPolygon, lineShape, false);
PolygonShape polygonShape2 = GetPolygonForSplit(processedPolygon, lineShape, true);
if (polygonShape1.IsWithin(polygonShape2))
{
polygonShape2 = processedPolygon.OuterRing.GetDifference(polygonShape1).Polygons[0];
foreach (RingShape ii in processedPolygon.InnerRings)
{
polygonShape2.InnerRings.Add(ii);
}
}
.....
}
So I changed too the SplitRing Method because I believed that the problem came because we did not use the intersection point in the creation of the new polygon (intersectionPointShape2)
public static RingShape SplitRing(RingShape processedRing, Collection<PointShape> intersectionPointShapes)
{
RingShape resultRingShape = new RingShape();
PointShape intersectionPointShape1 = intersectionPointShapes[0];
PointShape intersectionPointShape2 = intersectionPointShapes[intersectionPointShapes.Count - 1];
int i = 0;
int totalPointNumber = processedRing.Vertices.Count;
while (i < totalPointNumber - 1)
{
int indexA = i + 1;
if (DoesPointShapeBelongToLineSegment(intersectionPointShape1, new PointShape(processedRing.Vertices), new PointShape(processedRing.Vertices[indexA])))
{
resultRingShape.Vertices.Add(new Vertex(intersectionPointShape1));
if (DoesPointShapeBelongToLineSegment(intersectionPointShape2, new PointShape(processedRing.Vertices), new PointShape(processedRing.Vertices[indexA])))
{
resultRingShape.Vertices.Add(new Vertex(intersectionPointShape2));
for (int shapeIndex = intersectionPointShapes.Count - 2; shapeIndex > 0; shapeIndex--)
{ resultRingShape.Vertices.Add(new Vertex(intersectionPointShapes[shapeIndex])); }
resultRingShape.Vertices.Add(new Vertex(intersectionPointShape1));
...
}
But I still have the problem ;-( and sometimes the new polygon is not correct (form butterfly .....)
But the other polygon is correct
So I don't understand why the GetDifference function gives this result .. ?
May be it's not necessary to use the GetDifference function to solve the problem of cutting of a polygon on a single side ?
Thanks a lots for your help.
Regards.
Stéphanie.