Search in sources :

Example 1 with LineSegment

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

the class NonEncroachingSplitPointFinder method projectedSplitPoint.

/**
 * Computes a split point which is the projection of the encroaching point on the segment
 *
 * @param seg
 * @param encroachPt
 * @return a split point on the segment
 */
public static Point projectedSplitPoint(final LineSegmentDoubleData seg, final Point encroachPt) {
    final LineSegment lineSeg = seg;
    final Point projPt = lineSeg.project(encroachPt);
    return projPt;
}
Also used : Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 2 with LineSegment

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

the class GeometryGraph method addEdges.

private void addEdges(final LineString points, final Map<String, Object> attributes) {
    this.startPoints.add(points.getPoint(0).newPoint2D());
    int index = 0;
    for (LineSegment lineSegment : points.segments()) {
        lineSegment = (LineSegment) lineSegment.clone();
        final double fromX = lineSegment.getX(0);
        final double fromY = lineSegment.getY(0);
        final double toX = lineSegment.getX(1);
        final double toY = lineSegment.getY(1);
        final Edge<LineSegment> edge = addEdge(lineSegment, fromX, fromY, toX, toY);
        attributes.put("segmentIndex", index++);
        edge.setProperties(attributes);
    }
}
Also used : Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 3 with LineSegment

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

the class LineStringGraph method setLineString.

private void setLineString(final LineString lineString) {
    this.points = lineString;
    int index = 0;
    for (final LineSegment lineSegment : lineString.segments()) {
        final double fromX = lineSegment.getX(0);
        final double fromY = lineSegment.getY(0);
        final double toX = lineSegment.getX(1);
        final double toY = lineSegment.getY(1);
        final Edge<LineSegment> edge = addEdge((LineSegment) lineSegment.clone(), fromX, fromY, toX, toY);
        edge.setProperty(INDEX, Arrays.asList(index++));
    }
    this.fromPoint = lineString.getPoint(0).newPoint2D();
    this.envelope = lineString.getBoundingBox();
}
Also used : Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 4 with LineSegment

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

the class LineStringGraph method splitEdge.

@Override
public <V extends Point> List<Edge<LineSegment>> splitEdge(final Edge<LineSegment> edge, final Collection<V> nodes) {
    final List<Edge<LineSegment>> newEdges = new ArrayList<>();
    if (!edge.isRemoved()) {
        final Node<LineSegment> fromNode = edge.getFromNode();
        final Node<LineSegment> toNode = edge.getToNode();
        final CoordinatesDistanceComparator comparator = new CoordinatesDistanceComparator(fromNode.getX(), toNode.getY());
        final Set<Point> newPoints = new TreeSet<>(comparator);
        for (final Point point : nodes) {
            newPoints.add(point);
        }
        newPoints.add(toNode);
        final List<Integer> index = edge.getProperty(INDEX);
        int i = 0;
        Point previousPoint = fromNode;
        for (final Point point : newPoints) {
            final LineSegment lineSegment = new LineSegmentDoubleGF(previousPoint, point);
            final Edge<LineSegment> newEdge = addEdge(lineSegment, previousPoint, point);
            final List<Integer> newIndecies = new ArrayList<>(index);
            newIndecies.add(i++);
            newEdge.setProperty(INDEX, newIndecies);
            newEdges.add(newEdge);
            previousPoint = point;
        }
        remove(edge);
    }
    return newEdges;
}
Also used : CoordinatesDistanceComparator(com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) TreeSet(java.util.TreeSet) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 5 with LineSegment

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

the class LineStringGraph method getLines.

public List<LineString> getLines() {
    removeDuplicateEdges();
    final EdgeAttributeValueComparator<LineSegment> comparator = new EdgeAttributeValueComparator<>("INDEX");
    final List<LineString> lines = new ArrayList<>();
    final List<Point> points = new ArrayList<>();
    final Consumer<Edge<LineSegment>> action = new Consumer<Edge<LineSegment>>() {

        private Node<LineSegment> previousNode = null;

        @Override
        public void accept(final Edge<LineSegment> edge) {
            final LineSegment lineSegment = edge.getObject();
            if (lineSegment.getLength() > 0) {
                final Node<LineSegment> fromNode = edge.getFromNode();
                final Node<LineSegment> toNode = edge.getToNode();
                if (this.previousNode == null) {
                    points.add(lineSegment.getPoint(0));
                    points.add(lineSegment.getPoint(1));
                } else if (fromNode == this.previousNode) {
                    if (edge.getLength() > 0) {
                        points.add(toNode);
                    }
                } else {
                    if (points.size() > 1) {
                        final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
                        lines.add(line);
                    }
                    points.clear();
                    ;
                    points.add(lineSegment.getPoint(0));
                    points.add(lineSegment.getPoint(1));
                }
                if (points.size() > 1) {
                    final int toDegree = toNode.getDegree();
                    if (toDegree != 2) {
                        final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
                        lines.add(line);
                        points.clear();
                        ;
                        points.add(toNode);
                    }
                }
                this.previousNode = toNode;
            }
        }
    };
    forEachEdge(comparator, action);
    if (points.size() > 1) {
        final LineString line = this.geometryFactory.lineString(points);
        lines.add(line);
    }
    return lines;
}
Also used : EdgeAttributeValueComparator(com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Consumer(java.util.function.Consumer) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Aggregations

LineSegment (com.revolsys.geometry.model.segment.LineSegment)61 Point (com.revolsys.geometry.model.Point)34 Edge (com.revolsys.geometry.graph.Edge)19 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)14 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)13 Geometry (com.revolsys.geometry.model.Geometry)12 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)11 ArrayList (java.util.ArrayList)10 LineString (com.revolsys.geometry.model.LineString)9 Node (com.revolsys.geometry.graph.Node)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 EdgeAttributeValueComparator (com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)4 List (java.util.List)4 EdgeObjectFilter (com.revolsys.geometry.graph.filter.EdgeObjectFilter)2 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)2 Polygon (com.revolsys.geometry.model.Polygon)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 Shape (java.awt.Shape)2