Search in sources :

Example 6 with GeometryFactory

use of com.revolsys.geometry.model.GeometryFactory 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 7 with GeometryFactory

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

the class GriddedElevationModel method resample.

default GriddedElevationModel resample(final int newGridCellSize) {
    final int tileX = (int) getGridMinX();
    final int tileY = (int) getGridMinY();
    final double gridCellSize = getGridCellSize();
    final double cellRatio = gridCellSize / newGridCellSize;
    final int step = (int) Math.round(1 / cellRatio);
    final int gridWidth = getGridWidth();
    final int gridHeight = getGridHeight();
    final int newGridWidth = (int) Math.round(gridWidth * cellRatio);
    final int newGridHeight = (int) Math.round(gridHeight * cellRatio);
    final GeometryFactory geometryFactory = getGeometryFactory();
    final GriddedElevationModel newDem = new IntArrayScaleGriddedElevationModel(geometryFactory, tileX, tileY, newGridWidth, newGridHeight, newGridCellSize);
    int newGridY = 0;
    for (int gridYMin = 0; gridYMin < gridHeight; gridYMin += step) {
        final int gridYMax = gridYMin + step;
        int newGridX = 0;
        for (int gridXMin = 0; gridXMin < gridWidth; gridXMin += step) {
            final int gridXMax = gridXMin + step;
            int count = 0;
            double sum = 0;
            for (int gridY = gridYMin; gridY < gridYMax; gridY++) {
                for (int gridX = gridXMin; gridX < gridXMax; gridX++) {
                    final double elevation = getElevation(gridX, gridY);
                    if (Double.isFinite(elevation)) {
                        count++;
                        sum += elevation;
                    }
                }
            }
            if (count > 0) {
                final double elevation = geometryFactory.makeZPrecise(sum / count);
                newDem.setElevation(newGridX, newGridY, elevation);
            }
            newGridX++;
        }
        newGridY++;
    }
    return newDem;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 8 with GeometryFactory

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

the class GriddedElevationModel method forEachPointFinite.

default void forEachPointFinite(final BoundingBox boundingBox, final Consumer<Point> action) {
    final GeometryFactory targetGeometryFactory = boundingBox.getGeometryFactory();
    final GeometryFactory geometryFactory = getGeometryFactory();
    final CoordinatesOperation projection = geometryFactory.getCoordinatesOperation(targetGeometryFactory);
    final BoundingBox convertexBoundingBox = boundingBox.convert(geometryFactory);
    final double gridCellSize = getGridCellSize();
    final double minY = getGridMinY();
    final double minX = getGridMinX();
    final int gridWidth = getGridWidth();
    final int gridHeight = getGridHeight();
    int startGridX = (int) Math.floor((convertexBoundingBox.getMinX() - minX) / gridCellSize);
    if (startGridX < 0) {
        startGridX = 0;
    }
    int endGridX = (int) Math.ceil((convertexBoundingBox.getMaxX() - minX) / gridCellSize);
    if (endGridX > gridWidth) {
        endGridX = gridWidth;
    }
    int startGridY = (int) Math.floor((convertexBoundingBox.getMinY() - minY) / gridCellSize);
    if (startGridY < 0) {
        startGridY = 0;
    }
    int endGridY = (int) Math.ceil((convertexBoundingBox.getMaxY() - minY) / gridCellSize);
    if (endGridY > gridHeight) {
        endGridY = gridHeight;
    }
    if (projection == null) {
        for (int gridY = startGridY; gridY < endGridY; gridY++) {
            final double y = minY + gridY * gridCellSize;
            for (int gridX = startGridX; gridX < endGridX; gridX++) {
                final double x = minX + gridX * gridCellSize;
                final double z = getElevationFast(gridX, gridY);
                if (Double.isFinite(z)) {
                    if (boundingBox.covers(x, y)) {
                        final Point point = targetGeometryFactory.point(x, y, z);
                        action.accept(point);
                    }
                }
            }
        }
    } else {
        final double[] coordinates = new double[2];
        for (int gridY = startGridY; gridY < endGridY; gridY++) {
            final double y = minY + gridY * gridCellSize;
            for (int gridX = startGridX; gridX < endGridX; gridX++) {
                final double x = minX + gridX * gridCellSize;
                final double z = getElevationFast(gridX, gridY);
                if (Double.isFinite(z)) {
                    coordinates[0] = x;
                    coordinates[1] = y;
                    projection.perform(2, coordinates, 2, coordinates);
                    final double targetX = coordinates[0];
                    final double targetY = coordinates[1];
                    if (boundingBox.covers(targetX, targetY)) {
                        final Point point = targetGeometryFactory.point(targetX, targetY, z);
                        action.accept(point);
                    }
                }
            }
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation) Point(com.revolsys.geometry.model.Point)

Example 9 with GeometryFactory

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

the class IntArrayScaleGriddedElevationModel method setElevation.

@Override
public void setElevation(final int gridX, final int gridY, final double elevation) {
    final int width = getGridWidth();
    final int height = getGridHeight();
    final GeometryFactory geometryFactory = getGeometryFactory();
    if (gridX >= 0 && gridX < width && gridY >= 0 && gridY < height) {
        final int index = gridY * width + gridX;
        final int elevationInt = geometryFactory.toIntZ(elevation);
        this.elevations[index] = elevationInt;
        clearCachedObjects();
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 10 with GeometryFactory

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

the class IntArrayScaleGriddedElevationModel method resample.

@Override
public GriddedElevationModel resample(final int newGridCellSize) {
    final double gridCellSize = getGridCellSize();
    final double cellRatio = gridCellSize / newGridCellSize;
    final int step = (int) Math.round(1 / cellRatio);
    final int gridWidth = getGridWidth();
    final int gridHeight = getGridHeight();
    final int newGridWidth = (int) Math.round(gridWidth * cellRatio);
    final int newGridHeight = (int) Math.round(gridHeight * cellRatio);
    final GeometryFactory geometryFactory = getGeometryFactory();
    final int[] oldElevations = this.elevations;
    final int[] newElevations = new int[newGridWidth * newGridHeight];
    int newIndex = 0;
    for (int gridYMin = 0; gridYMin < gridHeight; gridYMin += step) {
        final int gridYMax = gridYMin + step;
        for (int gridXMin = 0; gridXMin < gridWidth; gridXMin += step) {
            final int gridXMax = gridXMin + step;
            int count = 0;
            long sum = 0;
            for (int gridY = gridYMin; gridY < gridYMax; gridY++) {
                for (int gridX = gridXMin; gridX < gridXMax; gridX++) {
                    final int elevation = oldElevations[gridY * gridWidth + gridX];
                    if (elevation != NULL_VALUE) {
                        count++;
                        sum += elevation;
                    }
                }
            }
            if (count > 0) {
                newElevations[newIndex] = (int) (sum / count);
            } else {
                newElevations[newIndex] = NULL_VALUE;
            }
            newIndex++;
        }
    }
    final BoundingBox boundingBox = getBoundingBox();
    final GriddedElevationModel newDem = new IntArrayScaleGriddedElevationModel(geometryFactory, boundingBox, newGridWidth, newGridHeight, newGridCellSize, newElevations);
    return newDem;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Aggregations

GeometryFactory (com.revolsys.geometry.model.GeometryFactory)360 Point (com.revolsys.geometry.model.Point)142 Geometry (com.revolsys.geometry.model.Geometry)72 BoundingBox (com.revolsys.geometry.model.BoundingBox)70 LineString (com.revolsys.geometry.model.LineString)61 ArrayList (java.util.ArrayList)45 DataType (com.revolsys.datatype.DataType)25 FieldDefinition (com.revolsys.record.schema.FieldDefinition)24 Polygon (com.revolsys.geometry.model.Polygon)22 List (java.util.List)18 RecordDefinition (com.revolsys.record.schema.RecordDefinition)17 Test (org.junit.Test)16 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)14 Record (com.revolsys.record.Record)14 IOException (java.io.IOException)13 PathName (com.revolsys.io.PathName)12 LinearRing (com.revolsys.geometry.model.LinearRing)10 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)10 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)8