Search in sources :

Example 96 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class EdgeIntersectLineVisitor method accept.

@Override
public void accept(final Edge<T> edge) {
    final LineString line = edge.getLineString();
    final IntersectionMatrix relate = this.line.relate(line);
    if (relate.get(0, 0) == Dimension.L) {
        this.matchVisitor.accept(edge);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) IntersectionMatrix(com.revolsys.geometry.model.IntersectionMatrix)

Example 97 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class EqualTypeAndLineEdgeCleanupVisitor method processEqualEdge.

private void processEqualEdge(final Edge<Record> edge1, final Edge<Record> edge2) {
    final Record record1 = edge1.getObject();
    final Record record2 = edge2.getObject();
    final boolean equalAttributes = record1.equalValuesExclude(record2, this.equalExcludeFieldNames);
    final LineString line1 = edge1.getLineString();
    int compare = 0;
    final Comparator<Edge<Record>> comparator = getComparator();
    if (comparator != null) {
        compare = comparator.compare(edge1, edge2);
    }
    if (compare == 0) {
        if (equalAttributes) {
            boolean equalExcludedAttributes = true;
            for (final String name : this.equalExcludeFieldNames) {
                if (!record1.equalValue(record2, name)) {
                    equalExcludedAttributes = false;
                }
            }
            final LineString line2 = edge2.getLineString();
            final boolean equalZ = fixMissingZValues(line1, line2);
            if (equalExcludedAttributes) {
                if (equalZ) {
                    removeDuplicate(edge2, edge1);
                } else {
                    RecordLog.error(getClass(), "Equal geometry with different coordinates or Z-values", record1);
                }
            } else {
                RecordLog.error(getClass(), "Equal geometry with different attributes: ", record1);
            }
        } else {
            RecordLog.error(getClass(), "Equal geometry with different attributes: ", record1);
        }
    } else {
        removeDuplicate(edge2, edge1);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge)

Example 98 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class LineSegmentIndex method insert.

public void insert(final Geometry geometry) {
    for (int i = 0; i < geometry.getGeometryCount(); i++) {
        final Geometry subGeometry = geometry.getGeometry(i);
        if (subGeometry instanceof LineString) {
            final LineString line = (LineString) subGeometry;
            insert(line);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 99 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class CoordinatesListUtil method intersection.

public static List<LineString> intersection(final GeometryFactory geometryFactory, final LineString points1, final LineString points2, final double maxDistance) {
    final LineStringGraph graph1 = new LineStringGraph(points1);
    graph1.setPrecisionModel(geometryFactory);
    final LineStringGraph graph2 = new LineStringGraph(points2);
    graph2.setPrecisionModel(geometryFactory);
    final Map<Point, Point> movedNodes = new HashMap<>();
    graph1.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph2, maxDistance, node));
    graph2.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph1, maxDistance, node));
    final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 = graph1.getPointsOnEdges(graph2, maxDistance);
    final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge2 = graph2.getPointsOnEdges(graph1, maxDistance);
    graph1.splitEdges(pointsOnEdge1);
    graph2.splitEdges(pointsOnEdge2);
    Point startPoint = points1.getPoint(0);
    if (movedNodes.containsKey(startPoint)) {
        startPoint = movedNodes.get(startPoint);
    }
    Point endPoint = points1.getPoint(points1.getVertexCount() - 1);
    if (movedNodes.containsKey(endPoint)) {
        endPoint = movedNodes.get(endPoint);
    }
    final List<LineString> intersections = new ArrayList<>();
    final List<Point> currentCoordinates = new ArrayList<>();
    Node<LineSegment> previousNode = graph1.getNode(startPoint);
    do {
        final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
        if (outEdges.isEmpty()) {
            previousNode = null;
        } else if (outEdges.size() > 1) {
            throw new IllegalArgumentException("Cannot handle overlaps\n" + points1 + "\n " + points2);
        } else {
            final Edge<LineSegment> edge = outEdges.get(0);
            final LineSegment line = edge.getObject();
            final Node<LineSegment> nextNode = edge.getToNode();
            if (graph2.hasEdgeBetween(previousNode, nextNode)) {
                if (currentCoordinates.size() == 0) {
                    currentCoordinates.add(line.getPoint(0));
                }
                currentCoordinates.add(line.getPoint(1));
            } else {
                if (currentCoordinates.size() > 0) {
                    final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
                    intersections.add(points);
                    currentCoordinates.clear();
                }
            }
            previousNode = nextNode;
        }
    } while (previousNode != null && !endPoint.equals(2, startPoint));
    if (currentCoordinates.size() > 0) {
        final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
        intersections.add(points);
    }
    return intersections;
}
Also used : HashMap(java.util.HashMap) LineStringGraph(com.revolsys.geometry.graph.linestring.LineStringGraph) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) List(java.util.List) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 100 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class CoordinatesUtil method getElevation.

static double getElevation(final LineString line, final Point coordinate) {
    final LineString coordinates = line;
    Point previousCoordinate = coordinates.getPoint(0);
    for (int i = 1; i < coordinates.getVertexCount(); i++) {
        final Point currentCoordinate = coordinates.getPoint(i);
        if (LineSegmentUtil.distanceLinePoint(previousCoordinate, currentCoordinate, coordinate) < 1) {
            return LineSegmentUtil.getElevation(previousCoordinate, currentCoordinate, coordinate);
        }
        previousCoordinate = currentCoordinate;
    }
    return Double.NaN;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Aggregations

LineString (com.revolsys.geometry.model.LineString)380 Point (com.revolsys.geometry.model.Point)184 Geometry (com.revolsys.geometry.model.Geometry)65 ArrayList (java.util.ArrayList)62 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)51 Polygon (com.revolsys.geometry.model.Polygon)37 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)24 Edge (com.revolsys.geometry.graph.Edge)22 List (java.util.List)22 BoundingBox (com.revolsys.geometry.model.BoundingBox)20 Lineal (com.revolsys.geometry.model.Lineal)20 Test (org.junit.Test)20 LinearRing (com.revolsys.geometry.model.LinearRing)19 Record (com.revolsys.record.Record)17 Iterator (java.util.Iterator)14 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)13 Punctual (com.revolsys.geometry.model.Punctual)12 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)12 LineSegment (com.revolsys.geometry.model.segment.LineSegment)10 Polygonal (com.revolsys.geometry.model.Polygonal)9