ThinkGeo.com    |     Documentation    |     Premium Support

How to clip a line that passes through a rectangle to the edge of the rectangle

Please refer to the attached image.


I have street lines that pass through a rectangle. I would like to clip the lines to the edge of the rectangle. For example, line A-B passes through the rectangle, and points A' and B' denote where the line touches the edge of the rectangle. I'd like to "shorten" line A-B so that its terminal points are really A' and B'.


What do you think?



Gregory,


Thanks for your post and question.


Try following code, hope it is what we are trying to achieve.



private static LineShape GetIntersectionLineShape(LineShape lineShape, RectangleShape rectangleShape)
        {
            MultipointShape crossingPoints = lineShape.GetCrossing(rectangleShape);

            if (crossingPoints.Points.Count != 2)
            {
                throw new ArgumentException("The lineshape and rectangle does not contains 2 intersection points.");
            }

            LineShape returnLineShape =(LineShape) lineShape.GetLineOnALine(crossingPoints.Points[0],crossingPoints.Points[1]);
            return returnLineShape;
        }

Any more questions just feel free to let me know.


Thanks.


Yale

 



Thanks, Yale! That approach works perfectly! I appreciate the quick and thorough response. 
  
 Greg

Gregory  
  
 Thanks for letting me know your status. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale