Search in sources :

Example 21 with Segment

use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.

the class DistanceWithLocation method computeLineLine.

private boolean computeLineLine(final LineString line1, final LineString line2) {
    if (this.minDistance == Double.MAX_VALUE || line1.getBoundingBox().distance(line2.getBoundingBox()) <= this.minDistance) {
        for (final Segment segment1 : line1.segments()) {
            for (final Segment segment2 : line2.segments()) {
                final double dist = segment1.distance(segment2);
                if (dist < this.minDistance) {
                    this.minDistance = dist;
                    final Point[] closestPt = segment1.closestPoints(segment2);
                    final int segmentIndex1 = segment1.getSegmentIndex();
                    this.minDistanceLocation1 = new GeometryLocation(line1, segmentIndex1, closestPt[0]);
                    final int segmentIndex2 = segment2.getSegmentIndex();
                    this.minDistanceLocation2 = new GeometryLocation(line2, segmentIndex2, closestPt[1]);
                    if (this.minDistance <= this.terminateDistance) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment) Point(com.revolsys.geometry.model.Point)

Example 22 with Segment

use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.

the class AbstractRecordLayerRenderer method getPointWithOrientationCentre.

private static PointDoubleXYOrientation getPointWithOrientationCentre(final GeometryFactory geometryFactory2dFloating, final Geometry geometry) {
    double orientation = 0;
    Point point = null;
    if (geometry instanceof LineString) {
        final LineString line = geometry.convertGeometry(geometryFactory2dFloating, 2);
        final double totalLength = line.getLength();
        final double centreLength = totalLength / 2;
        double currentLength = 0;
        for (final Segment segment : line.segments()) {
            final double segmentLength = segment.getLength();
            currentLength += segmentLength;
            if (currentLength >= centreLength) {
                final double segmentFraction = 1 - (currentLength - centreLength) / segmentLength;
                point = segment.pointAlong(segmentFraction);
                orientation = segment.getOrientaton();
                break;
            }
        }
    } else {
        point = geometry.getPointWithin();
        point = point.convertPoint2d(geometryFactory2dFloating);
    }
    return new PointDoubleXYOrientation(point, orientation);
}
Also used : PointDoubleXYOrientation(com.revolsys.geometry.model.impl.PointDoubleXYOrientation) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment) Segment(com.revolsys.geometry.model.segment.Segment)

Aggregations

Segment (com.revolsys.geometry.model.segment.Segment)22 Point (com.revolsys.geometry.model.Point)16 Vertex (com.revolsys.geometry.model.vertex.Vertex)6 LineSegment (com.revolsys.geometry.model.segment.LineSegment)4 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)2 LineString (com.revolsys.geometry.model.LineString)2 LineStringSegment (com.revolsys.geometry.model.segment.LineStringSegment)2 AbstractVertex (com.revolsys.geometry.model.vertex.AbstractVertex)2 LineStringVertex (com.revolsys.geometry.model.vertex.LineStringVertex)2 GeometryLocation (com.revolsys.geometry.operation.distance.GeometryLocation)2 Pair (com.revolsys.util.Pair)2 PointPairDistance (com.revolsys.geometry.algorithm.distance.PointPairDistance)1 LineSegmentIndex (com.revolsys.geometry.index.LineSegmentIndex)1 GeometryComponent (com.revolsys.geometry.model.GeometryComponent)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 PointDoubleXYOrientation (com.revolsys.geometry.model.impl.PointDoubleXYOrientation)1 PreparedLineString (com.revolsys.geometry.model.prep.PreparedLineString)1 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)1 DuplicateVertexError (com.revolsys.geometry.operation.simple.DuplicateVertexError)1