Search in sources :

Example 1 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class FloatArrayGriddedElevationModel method getNullBoundaryPoints.

@Override
public LineStringEditor getNullBoundaryPoints() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final LineStringEditor points = new LineStringEditor(geometryFactory);
    final double minX = getGridMinX();
    final double minY = getGridMinY();
    final double gridCellSize = getGridCellSize();
    final int gridHeight = getGridHeight();
    final int gridWidth = getGridWidth();
    final float[] elevations = this.elevations;
    int index = 0;
    final int[] offsets = { -1, 0, 1 };
    for (int gridY = 0; gridY < gridHeight; gridY++) {
        for (int gridX = 0; gridX < gridWidth; gridX++) {
            final float elevation = elevations[index];
            if (elevation == NULL_VALUE) {
                int countZ = 0;
                double sumZ = 0;
                for (final int offsetY : offsets) {
                    if (!(gridY == 0 && offsetY == -1 || gridY == gridHeight - 1 && offsetY == 1)) {
                        final int offsetIndex = index + offsetY * gridWidth;
                        for (final int offsetX : offsets) {
                            if (!(gridX == 0 && offsetX == -1 || gridX == gridWidth - 1 && offsetX == 1)) {
                                final float elevationNeighbour = elevations[offsetIndex + offsetX];
                                if (elevationNeighbour != NULL_VALUE) {
                                    sumZ += elevationNeighbour;
                                    countZ++;
                                }
                            }
                        }
                    }
                }
                if (countZ > 0) {
                    final double x = minX + gridCellSize * gridX;
                    final double y = minY + gridCellSize * gridY;
                    final double z = sumZ / countZ;
                    points.appendVertex(x, y, z);
                }
            }
            index++;
        }
    }
    return points;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 2 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class GriddedElevationModel method getBoundaryXY.

default Polygon getBoundaryXY() {
    final GeometryFactory geometryFactory = getGeometryFactory().convertAxisCount(2);
    final LineStringEditor points = new LineStringEditor(geometryFactory);
    final double minX = getGridMinX();
    final double minY = getGridMinY();
    final double gridCellSize = getGridCellSize();
    final int gridHeight = getGridHeight();
    final int gridWidth = getGridWidth();
    final int maxGridXIndex = gridWidth - 1;
    final int maxGridYIndex = gridHeight - 1;
    int firstGridY = -1;
    int minGridX = -1;
    int maxGridX = 0;
    int minGridY = Integer.MAX_VALUE;
    int maxGridY = 0;
    int lastGridX = 0;
    int lastGridY = 0;
    int gridX = 0;
    int gridY = 0;
    // Process South edge
    while (gridX != gridWidth) {
        final double z = getElevation(gridX, gridY);
        if (Double.isFinite(z)) {
            if (minGridX == -1) {
                minGridX = gridX;
            }
            maxGridX = gridX;
            if (firstGridY == -1) {
                firstGridY = gridY;
            }
            if (gridY < minGridY) {
                minGridY = gridY;
            }
            if (gridY > maxGridY) {
                maxGridY = gridY;
            }
            double x = minX + gridX * gridCellSize;
            if (gridX == maxGridXIndex) {
                x += gridCellSize;
            }
            final double y = minY + gridY * gridCellSize;
            final int vertexCount = points.getVertexCount();
            if (vertexCount < 2) {
                points.appendVertex(x, y);
            } else {
                final double lastY = points.getY(vertexCount - 1);
                if (lastY == y) {
                    if (points.getY(vertexCount - 2) == y) {
                        points.setX(vertexCount - 1, x);
                    } else {
                        points.appendVertex(x, y);
                    }
                } else {
                    if (points.getY(vertexCount - 2) == lastY) {
                        points.setX(vertexCount - 1, x);
                    } else {
                        points.appendVertex(x, lastY);
                    }
                    points.appendVertex(x, y);
                }
            }
            lastGridX = gridX;
            lastGridY = gridY;
            gridX++;
            gridY = 0;
        } else {
            gridY++;
            if (gridY == gridHeight) {
                gridX++;
                gridY = 0;
            }
        }
    }
    // Process East edge
    gridX = maxGridX;
    gridY = lastGridY + 1;
    while (gridY != gridHeight) {
        final double z = getElevation(gridX, gridY);
        if (Double.isFinite(z)) {
            maxGridY = gridY;
            double x = minX + gridX * gridCellSize;
            if (gridX == maxGridXIndex) {
                x += gridCellSize;
            }
            double y = minY + gridY * gridCellSize;
            if (gridY == maxGridYIndex) {
                y += gridCellSize;
            }
            final int vertexCount = points.getVertexCount();
            if (vertexCount < 2) {
                points.appendVertex(x, y);
            } else {
                final double lastX = points.getX(vertexCount - 1);
                if (lastX == x) {
                    if (points.getX(vertexCount - 2) == x) {
                        points.setY(vertexCount - 1, y);
                    } else {
                        points.appendVertex(x, y);
                    }
                } else {
                    if (points.getX(vertexCount - 2) == lastX) {
                        points.setY(vertexCount - 1, y);
                    } else {
                        points.appendVertex(lastX, y);
                    }
                    points.appendVertex(x, y);
                }
            }
            lastGridX = gridX;
            lastGridY = gridY;
            gridX = maxGridX;
            gridY++;
        } else {
            gridX--;
            if (gridX < minGridX) {
                gridY++;
                gridX = maxGridX;
            }
        }
    }
    // Process North edge
    gridX = lastGridX - 1;
    gridY = maxGridY;
    while (gridX >= minGridX) {
        final double z = getElevation(gridX, gridY);
        if (Double.isFinite(z)) {
            double x = minX + gridX * gridCellSize;
            if (gridX == maxGridXIndex) {
                x += gridCellSize;
            }
            double y = minY + gridY * gridCellSize;
            if (gridY == maxGridYIndex) {
                y += gridCellSize;
            }
            final int vertexCount = points.getVertexCount();
            if (vertexCount < 2) {
                points.appendVertex(x, y);
            } else {
                final double lastY = points.getY(vertexCount - 1);
                if (lastY == y) {
                    if (points.getY(vertexCount - 2) == y) {
                        points.setX(vertexCount - 1, x);
                    } else {
                        points.appendVertex(x, y);
                    }
                } else {
                    if (points.getY(vertexCount - 2) == lastY) {
                        points.setX(vertexCount - 1, x);
                    } else {
                        points.appendVertex(x, lastY);
                    }
                    points.appendVertex(x, y);
                }
            }
            lastGridX = gridX;
            lastGridY = gridY;
            gridX--;
            gridY = maxGridY;
        } else {
            gridY--;
            if (gridY < minGridY) {
                gridX--;
                gridY = maxGridY;
            }
        }
    }
    // Process West edge
    gridX = minGridX;
    gridY = lastGridY - 1;
    while (gridY > firstGridY) {
        final double z = getElevation(gridX, gridY);
        if (Double.isFinite(z)) {
            final double x = minX + gridX * gridCellSize;
            final double y = minY + gridY * gridCellSize;
            final int vertexCount = points.getVertexCount();
            if (vertexCount < 2) {
                points.appendVertex(x, y);
            } else {
                final double lastX = points.getX(vertexCount - 1);
                if (lastX == x) {
                    if (points.getX(vertexCount - 2) == x) {
                        points.setY(vertexCount - 1, y);
                    } else {
                        points.appendVertex(x, y);
                    }
                } else {
                    if (points.getX(vertexCount - 2) == lastX) {
                        points.setY(vertexCount - 1, y);
                    } else {
                        points.appendVertex(lastX, y);
                    }
                    points.appendVertex(x, y);
                }
            }
            lastGridX = gridX;
            lastGridY = gridY;
            gridX = minGridX;
            gridY--;
        } else {
            gridX++;
            if (gridX > maxGridX) {
                gridY--;
                gridX = minGridX;
            }
        }
    }
    final int vertexCount = points.getVertexCount();
    if (vertexCount > 2) {
        final double x = points.getX(0);
        final double y = points.getY(0);
        final double lastX = points.getX(vertexCount - 1);
        if (lastX == x) {
            if (points.getX(vertexCount - 2) == x) {
                points.setY(vertexCount - 1, y);
            } else {
                points.appendVertex(x, y);
            }
        } else {
            if (points.getX(vertexCount - 2) == lastX) {
                points.setY(vertexCount - 1, y);
            } else {
                points.appendVertex(lastX, y);
            }
        }
        points.appendVertex(x, y);
    }
    if (points.isEmpty()) {
        return getBoundingBox().toPolygon();
    } else {
        return points.newPolygon();
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Point(com.revolsys.geometry.model.Point)

Example 3 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class GriddedElevationModel method getNullBoundaryPoints.

default LineStringEditor getNullBoundaryPoints() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final LineStringEditor points = new LineStringEditor(geometryFactory);
    final double minX = getGridMinX();
    final double minY = getGridMinY();
    final double gridCellSize = getGridCellSize();
    final int gridHeight = getGridHeight();
    final int gridWidth = getGridWidth();
    final int[] offsets = { -1, 0, 1 };
    for (int gridY = 0; gridY < gridHeight; gridY++) {
        for (int gridX = 0; gridX < gridWidth; gridX++) {
            final double elevation = getElevation(gridX, gridY);
            if (Double.isFinite(elevation)) {
                int countZ = 0;
                long sumZ = 0;
                for (final int offsetY : offsets) {
                    if (!(gridY == 0 && offsetY == -1) && gridY == gridHeight - 1 && offsetY == 1) {
                        for (final int offsetX : offsets) {
                            if (!(gridX == 0 && offsetX == -1) && gridX == gridWidth - 1 && offsetX == 1) {
                                final double elevationNeighbour = getElevation(gridX + offsetX, gridY + offsetY);
                                if (Double.isFinite(elevationNeighbour)) {
                                    sumZ += elevationNeighbour;
                                    countZ++;
                                }
                            }
                        }
                    }
                }
                if (countZ > 0) {
                    final double x = minX + gridCellSize * gridX;
                    final double y = minY + gridCellSize * gridY;
                    final double z = toDoubleZ((int) (sumZ / countZ));
                    points.appendVertex(x, y, z);
                }
            }
        }
    }
    return points;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Point(com.revolsys.geometry.model.Point)

Example 4 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class QuadEdgeSubdivision method getBoundary.

public Geometry getBoundary() {
    final LineStringEditor lineBuilder = new LineStringEditor(this.geometryFactory);
    for (final QuadEdge startingEdge : Arrays.asList(this.edge1, this.edge3, this.edge2)) {
        QuadEdge edge = startingEdge;
        do {
            final Point toPoint = edge.getToPoint();
            final double toX = toPoint.getX();
            final double toY = toPoint.getY();
            if (isFrameCoordinate(toX, toY)) {
            } else {
                lineBuilder.appendVertex(toPoint, false);
            }
            edge = edge.getFromNextEdge();
        } while (edge != startingEdge);
    }
    return lineBuilder.newBestGeometry();
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 5 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class ConvexHull method cleanRing.

/**
 *@param  vertices  the vertices of a linear ring, which may or may not be
 *      flattened (i.e. vertices collinear)
 *@return           the coordinates with unnecessary (collinear) vertices
 *      removed
 */
private static LineStringEditor cleanRing(final GeometryFactory geometryFactory, final List<Point> points) {
    final int count = points.size();
    final LineStringEditor cleanedRing = new LineStringEditor(geometryFactory, count);
    Point previousDistinctPoint = null;
    for (int i = 0; i <= count - 2; i++) {
        final Point currentPoint = points.get(i);
        final Point nextPoint = points.get(i + 1);
        if (currentPoint.equals(nextPoint)) {
        } else if (previousDistinctPoint != null && isBetween(previousDistinctPoint, currentPoint, nextPoint)) {
        } else {
            cleanedRing.appendVertex(currentPoint);
            previousDistinctPoint = currentPoint;
        }
    }
    cleanedRing.appendVertex(points.get(count - 1));
    return cleanedRing;
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Point(com.revolsys.geometry.model.Point)

Aggregations

LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)35 LineString (com.revolsys.geometry.model.LineString)13 Test (org.junit.Test)13 Point (com.revolsys.geometry.model.Point)11 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 ArrayList (java.util.ArrayList)3 TopologyException (com.revolsys.geometry.model.TopologyException)1 AbstractPoint (com.revolsys.geometry.model.impl.AbstractPoint)1 PreparedLineString (com.revolsys.geometry.model.prep.PreparedLineString)1 ArcLineString (com.revolsys.record.io.format.saif.geometry.ArcLineString)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1