Search in sources :

Example 26 with Lineal

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

the class GeometryGraph method getBoundaryIntersection.

/**
 * Get the intersection between the line and the boundary of this geometry.
 *
 * @param line
 * @return
 */
public Geometry getBoundaryIntersection(final LineString line) {
    final List<Point> pointIntersections = new ArrayList<>();
    final List<LineString> lineIntersections = new ArrayList<>();
    final GeometryFactory geometryFactory = getGeometryFactory();
    final BoundingBox boundingBox = getBoundingBox(line);
    if (boundingBox.intersects(this.boundingBox)) {
        final LineString points = line;
        final int vertexCount = points.getVertexCount();
        final Point fromPoint = points.getPoint(0);
        final Point toPoint = points.getPoint(vertexCount - 1);
        Point previousPoint = fromPoint;
        for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
            final Point nextPoint = points.getPoint(vertexIndex);
            final LineSegment line1 = new LineSegmentDoubleGF(getGeometryFactory(), previousPoint, nextPoint);
            final List<Edge<LineSegment>> edges = EdgeLessThanDistance.getEdges(this, line1, this.maxDistance);
            for (final Edge<LineSegment> edge2 : edges) {
                final LineSegment line2 = edge2.getObject();
                final Geometry segmentIntersection = line1.getIntersection(line2);
                if (segmentIntersection instanceof Point) {
                    final Point intersection = (Point) segmentIntersection;
                    if (intersection.equals(fromPoint) || intersection.equals(toPoint)) {
                        // Point intersection, make sure it's not at the start
                        final Node<LineSegment> node = findNode(intersection);
                        if (node == null) {
                            pointIntersections.add(geometryFactory.point(intersection));
                        } else {
                            final int degree = node.getDegree();
                            if (isStartPoint(node)) {
                                if (degree > 2) {
                                    // Intersection not at the start/end of the other line,
                                    // taking
                                    // into account loops
                                    pointIntersections.add(geometryFactory.point(intersection));
                                }
                            } else if (degree > 1) {
                                // Intersection not at the start/end of the other line
                                pointIntersections.add(geometryFactory.point(intersection));
                            }
                        }
                    } else {
                        // Intersection not at the start/end of the line
                        pointIntersections.add(geometryFactory.point(intersection));
                    }
                } else if (segmentIntersection instanceof LineSegment) {
                    lineIntersections.add((LineSegment) segmentIntersection);
                }
                for (final Point point : line1.vertices()) {
                    if (line2.distancePoint(point) < this.maxDistance) {
                        if (point.equals(fromPoint) || point.equals(toPoint)) {
                            // Point intersection, make sure it's not at the start
                            final double maxDistance1 = this.maxDistance;
                            for (final Node<LineSegment> node : this.getNodes(point, maxDistance1)) {
                                final int degree = node.getDegree();
                                if (isStartPoint(node)) {
                                    if (degree > 2) {
                                        // Intersection not at the start/end of the other line,
                                        // taking
                                        // into account loops
                                        pointIntersections.add(geometryFactory.point(point));
                                    }
                                } else if (degree > 1) {
                                    // Intersection not at the start/end of the other line
                                    pointIntersections.add(geometryFactory.point(point));
                                }
                            }
                        } else {
                            // Intersection not at the start/end of the line
                            pointIntersections.add(geometryFactory.point(point));
                        }
                    }
                }
            }
            previousPoint = nextPoint;
        }
    }
    if (lineIntersections.isEmpty()) {
        return geometryFactory.punctual(pointIntersections);
    } else {
        final List<LineString> mergedLines = LineMerger.merge(lineIntersections);
        final Lineal multiLine = geometryFactory.lineal(mergedLines);
        if (pointIntersections.isEmpty()) {
            return multiLine;
        } else {
            final Punctual multiPoint = geometryFactory.punctual(pointIntersections);
            return multiPoint.union(multiLine);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 27 with Lineal

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

the class LineStringRelate method isEndOverlaps.

public boolean isEndOverlaps(final double maxDistance) {
    if (isOverlaps()) {
        boolean overlaps = false;
        final boolean from1Within = isWithin2(this.fromPoint1, maxDistance);
        final boolean to1Within = isWithin2(this.toPoint1, 1);
        if (from1Within != to1Within) {
            final boolean from2Within = isWithin1(this.fromPoint2, 1);
            final boolean to2Within = isWithin1(this.toPoint2, 1);
            if (from2Within != to2Within) {
                overlaps = true;
            }
        }
        if (overlaps) {
            final Lineal intersection = getOverlap();
            if (intersection.getGeometryCount() == 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : Lineal(com.revolsys.geometry.model.Lineal)

Example 28 with Lineal

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

the class GmlGeometryFieldType method geometry.

private void geometry(final XmlWriter out, final Object value, final boolean writeSrsName) {
    if (value instanceof Geometry) {
        final Geometry geometry = (Geometry) value;
        if (geometry instanceof Point) {
            final Point point = (Point) geometry;
            point(out, point, writeSrsName);
        } else if (geometry instanceof LineString) {
            final LineString line = (LineString) geometry;
            lineString(out, line, writeSrsName);
        } else if (geometry instanceof Polygon) {
            final Polygon polygon = (Polygon) geometry;
            polygon(out, polygon, writeSrsName);
        } else if (geometry instanceof Punctual) {
            final Punctual punctual = (Punctual) geometry;
            multiPoint(out, punctual, writeSrsName);
        } else if (geometry instanceof Lineal) {
            final Lineal lineal = (Lineal) geometry;
            multiLineString(out, lineal, writeSrsName);
        } else if (geometry instanceof Polygonal) {
            final Polygonal polygonal = (Polygonal) geometry;
            multiPolygon(out, polygonal, writeSrsName);
        } else if (geometry.isGeometryCollection()) {
            geometryCollection(out, geometry, writeSrsName);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Polygonal(com.revolsys.geometry.model.Polygonal) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Example 29 with Lineal

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

the class MultiLineStringVertex method next.

@Override
public Vertex next() {
    final Lineal lineal = getLineal();
    this.vertexIndex++;
    while (this.partIndex < lineal.getGeometryCount()) {
        final LineString lineString = lineal.getLineString(this.partIndex);
        if (this.vertexIndex < lineString.getVertexCount()) {
            return this;
        } else {
            this.partIndex++;
            this.vertexIndex = 0;
        }
    }
    throw new NoSuchElementException();
}
Also used : Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) NoSuchElementException(java.util.NoSuchElementException)

Example 30 with Lineal

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

the class EWktWriter method write.

public static void write(final Writer out, final Geometry geometry) {
    if (geometry != null) {
        if (geometry instanceof Point) {
            final Point point = (Point) geometry;
            write(out, point);
        } else if (geometry instanceof Punctual) {
            final Punctual punctual = (Punctual) geometry;
            write(out, punctual);
        } else if (geometry instanceof LinearRing) {
            final LinearRing line = (LinearRing) geometry;
            write(out, line);
        } else if (geometry instanceof LineString) {
            final LineString line = (LineString) geometry;
            write(out, line);
        } else if (geometry instanceof Lineal) {
            final Lineal lineal = (Lineal) geometry;
            write(out, lineal);
        } else if (geometry instanceof Polygon) {
            final Polygon polygon = (Polygon) geometry;
            write(out, polygon);
        } else if (geometry instanceof Polygonal) {
            final Polygonal polygonal = (Polygonal) geometry;
            write(out, polygonal);
        } else if (geometry.isGeometryCollection()) {
            writeGeometryCollection(out, geometry);
        } else {
            throw new IllegalArgumentException("Unknown geometry type" + geometry.getClass());
        }
    }
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Polygonal(com.revolsys.geometry.model.Polygonal) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Aggregations

Lineal (com.revolsys.geometry.model.Lineal)38 LineString (com.revolsys.geometry.model.LineString)20 Point (com.revolsys.geometry.model.Point)19 Polygon (com.revolsys.geometry.model.Polygon)11 Punctual (com.revolsys.geometry.model.Punctual)11 Polygonal (com.revolsys.geometry.model.Polygonal)9 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)8 LinearRing (com.revolsys.geometry.model.LinearRing)7 Test (org.junit.Test)7 LinealEditor (com.revolsys.geometry.model.editor.LinealEditor)6 BoundingBox (com.revolsys.geometry.model.BoundingBox)5 Geometry (com.revolsys.geometry.model.Geometry)5 ArrayList (java.util.ArrayList)4 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)2 Edge (com.revolsys.geometry.graph.Edge)2 AbstractLineString (com.revolsys.geometry.model.impl.AbstractLineString)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 NoSuchElementException (java.util.NoSuchElementException)2 DataType (com.revolsys.datatype.DataType)1