How to find the Intersecting edges of a Polygon and a Line String in Java?

3.5k views Asked by At

I am using JTS in java I have a Polygon and a LineString , I can easy find the Coordinate where the LineString intersects the Polygon .

  Geometry  intersections = polygon.intersection(line);
  for(Coordinate coor : intersections.getCoordinates()){
        System.out.println("Intersects at "+coor);
}

But what i need is , the edges of the Polygon where the LineString Intersects the Polygon . Is there any way or any method which will return me the intersecting edges of a polygon with a Line ?

1

There are 1 answers

0
krause On

I guess you could get the boundaries of the polygon and then perform that intersection. Something like this :

Geometry  intersections = polygon.getBoundary().intersection(line);
for(Coordinate coor : intersections.getCoordinates()){
      System.out.println("Intersects at "+coor);
}