Search in sources :

Example 6 with Segment

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

the class DistanceWithLocation method computeLinePoint.

private boolean computeLinePoint(final LineString line, final Point point) {
    if (this.minDistance == Double.MAX_VALUE || line.getBoundingBox().distance(point) <= this.minDistance) {
        for (final Segment segment : line.segments()) {
            final double distance = segment.distancePoint(point);
            if (distance < this.minDistance) {
                this.minDistance = distance;
                final Point closestPoint = segment.closestPoint(point);
                final int segmentIndex = segment.getSegmentIndex();
                this.minDistanceLocation1 = new GeometryLocation(line, segmentIndex, closestPoint);
                this.minDistanceLocation2 = new GeometryLocation(point, 0, point);
                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 7 with Segment

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

the class DiscreteHausdorffDistance method computeOrientedDistance.

private void computeOrientedDistance(final Geometry discreteGeom, final Geometry geom, final PointPairDistance ptDist) {
    final PointPairDistance maxPtDist = new PointPairDistance();
    final PointPairDistance minPtDist = new PointPairDistance();
    for (final Vertex vertex : discreteGeom.vertices()) {
        minPtDist.initialize();
        DistanceToPoint.computeDistance(geom, vertex, minPtDist);
        maxPtDist.setMaximum(minPtDist);
    }
    ptDist.setMaximum(maxPtDist);
    if (this.densifyFrac > 0) {
        maxPtDist.initialize();
        final int numSubSegs = 0;
        for (final Segment segment : discreteGeom.segments()) {
            final double x1 = segment.getX(0);
            final double y1 = segment.getY(0);
            final double x2 = segment.getX(1);
            final double y2 = segment.getY(1);
            final double delx = (x2 - x1) / numSubSegs;
            final double dely = (y2 - y1) / numSubSegs;
            for (int i = 0; i < numSubSegs; i++) {
                final double x = x1 + i * delx;
                final double y = y1 + i * dely;
                final Point pt = new PointDoubleXY(x, y);
                minPtDist.initialize();
                DistanceToPoint.computeDistance(geom, pt, minPtDist);
                maxPtDist.setMaximum(minPtDist);
            }
        }
        ptDist.setMaximum(maxPtDist);
    }
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment)

Example 8 with Segment

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

the class GeometrySegmentQuadTree method intersectsBounds.

@Override
protected boolean intersectsBounds(final Object id, final double x, final double y) {
    final Segment segment = getItem(id);
    final BoundingBox boundingBox = segment.getBoundingBox();
    return boundingBox.intersects(x, y, x, y);
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Segment(com.revolsys.geometry.model.segment.Segment)

Example 9 with Segment

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

the class SegmentError method getSegment.

public Segment getSegment() {
    final Geometry geometry = getGeometry();
    final Segment segment = geometry.getSegment(this.segmentId);
    return segment;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Segment(com.revolsys.geometry.model.segment.Segment)

Example 10 with Segment

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

the class MapPanel method findCloseLocation.

public CloseLocation findCloseLocation(final GeometryFactory viewportGeometryFactory2d, final AbstractRecordLayer layer, final LayerRecord record, final Geometry geometry, final double x, final double y, final double maxDistance) {
    final Geometry convertedGeometry = geometry.convertGeometry(viewportGeometryFactory2d);
    final Pair<GeometryComponent, Double> closestGeometryComponent = convertedGeometry.findClosestGeometryComponent(x, y, maxDistance);
    if (!closestGeometryComponent.isEmpty()) {
        final GeometryComponent geometryComponent = closestGeometryComponent.getValue1();
        if (geometryComponent instanceof Vertex) {
            final Vertex convertedVertex = (Vertex) geometryComponent;
            final int[] vertexId = convertedVertex.getVertexId();
            // Get the vertex from the original geometry
            final Vertex vertex = geometry.getVertex(vertexId);
            return new CloseLocation(layer, record, vertex);
        } else if (geometryComponent instanceof Segment) {
            final Segment convertedSegment = (Segment) geometryComponent;
            final int[] segmentId = convertedSegment.getSegmentId();
            // Get the segment from the original geometry
            final Segment segment = geometry.getSegment(segmentId);
            final Point closePoint = convertedSegment.project(x, y);
            final Point sourcePoint = geometry.convertGeometry(closePoint);
            return new CloseLocation(layer, record, segment, closePoint, sourcePoint);
        }
    }
    return null;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) GeometryComponent(com.revolsys.geometry.model.GeometryComponent) Vertex(com.revolsys.geometry.model.vertex.Vertex) Point(com.revolsys.geometry.model.Point) 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