您可以使用JTS。
- 創建使用LinearRing
- 使用intersection方法的多邊形
簡單的代碼示例:
// build polygon p1
LinearRing p1 = new GeometryFactory().createLinearRing(new Coordinate[]{new Coordinate(0,0), new Coordinate(0,10), new Coordinate(10,10), new Coordinate(10,0), new Coordinate(0,0)});
// build polygon p2
LinearRing p2 = new GeometryFactory().createLinearRing(new Coordinate[]{new Coordinate(5,5), new Coordinate(15,5), new Coordinate(15,15), new Coordinate(5,15), new Coordinate(5,5)});
// calculate intersecting points
Geometry intersectingPoints = p1.intersection(p2);
// print result
for(Coordinate c : intersectingPoints.getCoordinates()){
System.out.println(c.toString());
}
輸出是(像預期):
(5.0, 10.0, NaN)
(10.0, 5.0, NaN)
我建議張貼thi s在http://gis.stackexchange.com/ - 你可能會得到更好的反饋。 –