Search in sources :

Example 86 with LineString

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

the class OgrRecordWriter method toOgrGeometry.

protected org.gdal.ogr.Geometry toOgrGeometry(final Geometry geometry, final int geometryType, final int axisCount) {
    final org.gdal.ogr.Geometry ogrGeometry = new org.gdal.ogr.Geometry(geometryType);
    if (!geometry.isEmpty()) {
        switch(geometryType) {
            case 1:
            case 0x80000000 + 1:
                {
                    final Point point = (Point) geometry;
                    final double x = point.getX();
                    final double y = point.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = point.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 2:
            case 0x80000000 + 2:
                final LineString line = (LineString) geometry;
                final int vertexCount = line.getVertexCount();
                for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
                    final double x = line.getX(vertexIndex);
                    final double y = line.getY(vertexIndex);
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = line.getZ(vertexIndex);
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 3:
            case 0x80000000 + 3:
                for (final LinearRing ring : ((Polygon) geometry).rings()) {
                    final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(ring, 101, axisCount);
                    ogrGeometry.AddGeometry(ogrRing);
                }
                break;
            case 4:
                addParts(ogrGeometry, geometry, 1, axisCount);
                break;
            case 0x80000000 + 4:
                addParts(ogrGeometry, geometry, 0x80000000 + 1, axisCount);
                break;
            case 5:
                addParts(ogrGeometry, geometry, 2, axisCount);
                break;
            case 0x80000000 + 5:
                addParts(ogrGeometry, geometry, 0x80000000 + 2, axisCount);
                break;
            case 6:
                addParts(ogrGeometry, geometry, 3, axisCount);
                break;
            case 0x80000000 + 6:
                addParts(ogrGeometry, geometry, 0x80000000 + 3, axisCount);
                break;
            // return this.geometryFactory.geometry(parts);
            case 101:
                for (final Vertex vertex : geometry.vertices()) {
                    final double x = vertex.getX();
                    final double y = vertex.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = vertex.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            default:
                return null;
        }
    }
    if (axisCount == 2) {
        ogrGeometry.FlattenTo2D();
    }
    return ogrGeometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 87 with LineString

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

the class DistanceToPoint method computeDistance.

public static void computeDistance(final Geometry geom, final Point point, final PointPairDistance pointDistance) {
    if (geom instanceof LineString) {
        final LineString line = (LineString) geom;
        computeDistance(line, point, pointDistance);
    } else if (geom instanceof Polygon) {
        final Polygon polygon = (Polygon) geom;
        computeDistance(polygon, point, pointDistance);
    } else if (geom.isGeometryCollection()) {
        for (final Geometry part : geom.geometries()) {
            computeDistance(part, point, pointDistance);
        }
    } else {
        // assume geom is Point
        pointDistance.setMinimum(geom.getPoint(), point);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) Polygon(com.revolsys.geometry.model.Polygon)

Example 88 with LineString

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

the class LineMatchGraph method getNonMatchedLines.

public Lineal getNonMatchedLines(final int index1, final int index2) {
    final List<LineString> lines = new ArrayList<>();
    final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
    for (Node<LineSegmentMatch> currentNode : getStartNodes(index1)) {
        final List<Point> coordinates = new ArrayList<>();
        while (currentNode != null) {
            Node<LineSegmentMatch> nextNode = null;
            final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
            for (final Edge<LineSegmentMatch> edge : edges) {
                final LineSegmentMatch lineSegmentMatch = edge.getObject();
                if (lineSegmentMatch.hasSegment(index1) && !processedEdges.contains(edge)) {
                    if (!lineSegmentMatch.hasMatches(index1, index2)) {
                        if (coordinates.isEmpty()) {
                            final Point startCoordinate = currentNode;
                            coordinates.add(startCoordinate);
                        }
                        final Node<LineSegmentMatch> toNode = edge.getToNode();
                        final Point toCoordinate = toNode;
                        coordinates.add(toCoordinate);
                    } else {
                        newLine(lines, coordinates);
                        coordinates.clear();
                    }
                    processedEdges.add(edge);
                    nextNode = edge.getToNode();
                }
            }
            currentNode = nextNode;
        }
        newLine(lines, coordinates);
    }
    return this.geometryFactory.lineal(lines);
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.graph.Edge) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 89 with LineString

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

the class LineMatchGraph method add.

private void add(final LineString line, final int index) {
    if (line.getLength() > 0) {
        final LineString coords = line;
        final Point coordinate0 = coords.getPoint(0);
        final Node<LineSegmentMatch> node = getNode(coordinate0);
        final Set<Node<LineSegmentMatch>> indexStartNodes = getStartNodes(index);
        indexStartNodes.add(node);
        Point previousCoordinate = coordinate0;
        for (int i = 1; i < coords.getVertexCount(); i++) {
            final Point coordinate = coords.getPoint(i);
            final LineSegment segment = new LineSegmentDoubleGF(this.geometryFactory, previousCoordinate, coordinate);
            if (segment.getLength() > 0) {
                add(previousCoordinate, coordinate, segment, index);
            }
            previousCoordinate = coordinate;
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Node(com.revolsys.geometry.graph.Node) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 90 with LineString

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

the class LineMatchGraph method getOverlappingMatches.

public Lineal getOverlappingMatches() {
    final List<LineString> overlappingLines = new ArrayList<>();
    final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
    for (Node<LineSegmentMatch> currentNode : getStartNodes(0)) {
        while (currentNode != null) {
            Node<LineSegmentMatch> nextNode = null;
            final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
            for (final Edge<LineSegmentMatch> edge : edges) {
                final LineSegmentMatch lineSegmentMatch = edge.getObject();
                if (lineSegmentMatch.hasSegment(0) && !processedEdges.contains(edge)) {
                    if (lineSegmentMatch.getMatchCount(0) > 2) {
                        for (int i = 1; i < lineSegmentMatch.getSegmentCount() && lineSegmentMatch.getMatchCount(0) > 2; i++) {
                            if (lineSegmentMatch.hasSegment(i)) {
                                if (!hasMatch(currentNode, false, 0, i)) {
                                    final Node<LineSegmentMatch> toNode = edge.getToNode();
                                    if (!hasMatch(toNode, true, 0, i)) {
                                        lineSegmentMatch.removeSegment(i);
                                    } else {
                                        final double matchLength = getMatchLength(currentNode, false, 0, i);
                                        final double duplicateMatchLength = getDuplicateMatchLength(currentNode, true, 0, i);
                                        if (matchLength + duplicateMatchLength <= 2) {
                                            lineSegmentMatch.removeSegment(i);
                                        }
                                    }
                                }
                            }
                        }
                        if (lineSegmentMatch.getMatchCount(0) > 2) {
                            overlappingLines.add(lineSegmentMatch.getLine());
                        }
                    }
                    processedEdges.add(edge);
                    nextNode = edge.getToNode();
                }
            }
            currentNode = nextNode;
        }
    }
    final Lineal lines = this.geometryFactory.lineal(overlappingLines);
    return lines;
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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