1

我有一个任意的线段列表,我想与视口相交。有什么方法可以从该视口中获取另一个线段列表。

假设视口是正方形。任何给定的线段都可以被丢弃(如果该线段不与视口相交)或如果它与视口相交至少 2 个点则被剪裁。

到目前为止我有这个:

public LineString [] intersectWithViewport
    (Linestring[] input, double centerX, double centerY, double length) {
    GeometryFactory gf = new GeometryFactory();
    double halfLength = length / 2;
    Coordinate upperLeft = new Coordinate(centerX - halfLength, centerY - halfLength);
    Coordinate lowerLeft = new Coordinate(centerX - halfLength, centerY + halfLength);
    Coordinate lowerRight = new Coordinate(centerX + halfLength, centerY + halfLength);
    Coordinate upperRight = new Coordinate(centerX + halfLength, centerY - halfLength);
    Coordinate[] viewPortCoords = 
        new Coordinate[]{upperLeft, lowerLeft, lowerRight, upperRight};
    LinearRing lr = gf.createLinearRing(viewPortCoords);

    Geometry viewPort = gf.createPolygon(lr, null);
    Geometry segments = gf.createMultiLineString(input);
    Geometry intersection = segments.intersection(viewPort);
    ...
}

如何LineStringsintersection几何中获得?

4

0 回答 0