Search in sources :

Example 1 with GeometryFactory

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

the class ScaledIntegerGriddedDigitalElevationModelReader method readHeader.

private void readHeader() {
    final byte[] fileTypeBytes = new byte[6];
    this.reader.getBytes(fileTypeBytes);
    @SuppressWarnings("unused") final String fileType = new String(fileTypeBytes, StandardCharsets.UTF_8);
    @SuppressWarnings("unused") final short version = this.reader.getShort();
    final GeometryFactory geometryFactory = GeometryFactory.readOffsetScaled3d(this.reader);
    this.geometryFactory = geometryFactory;
    final double minX = this.reader.getDouble();
    final double minY = this.reader.getDouble();
    final double minZ = this.reader.getDouble();
    final double maxX = this.reader.getDouble();
    final double maxY = this.reader.getDouble();
    final double maxZ = this.reader.getDouble();
    this.gridCellSize = this.reader.getInt();
    this.gridWidth = this.reader.getInt();
    this.gridHeight = this.reader.getInt();
    this.boundingBox = geometryFactory.newBoundingBox(3, minX, minY, minZ, maxX, maxY, maxZ);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 2 with GeometryFactory

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

the class UsgsGriddedElevationReader method getChannel.

protected ReadableByteChannel getChannel() {
    final String fileExtension = this.resource.getFileNameExtension();
    try {
        if (fileExtension.equals("zip")) {
            final ZipInputStream in = this.resource.newBufferedInputStream(ZipInputStream::new);
            final String fileName = this.resource.getBaseName();
            final String baseName = FileUtil.getBaseName(fileName);
            final String projName = baseName + ".prj";
            for (ZipEntry zipEntry = in.getNextEntry(); zipEntry != null; zipEntry = in.getNextEntry()) {
                final String name = zipEntry.getName();
                if (name.equals(projName)) {
                    final String wkt = FileUtil.getString(new InputStreamReader(in, StandardCharsets.UTF_8), false);
                    final GeometryFactory geometryFactory = GeometryFactory.floating3d(wkt);
                    if (geometryFactory.isHasCoordinateSystem()) {
                        this.geometryFactory = geometryFactory;
                    }
                } else if (name.equals(fileName)) {
                    return new InputStreamResource(in).newReadableByteChannel();
                }
            }
            throw new IllegalArgumentException("Cannot find " + fileName + " in " + this.resource);
        } else if (fileExtension.equals("gz")) {
            final String baseName = this.resource.getBaseName();
            setGeometryFactory(this.resource.getParent().newChildResource(baseName));
            final InputStream in = this.resource.newBufferedInputStream();
            final GZIPInputStream gzIn = new GZIPInputStream(in);
            return new InputStreamResource(gzIn).newReadableByteChannel();
        } else {
            setGeometryFactory(this.resource);
            return this.resource.newReadableByteChannel();
        }
    } catch (final IOException e) {
        throw Exceptions.wrap("Unable to open: " + this.resource, e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) InputStreamResource(com.revolsys.spring.resource.InputStreamResource)

Example 3 with GeometryFactory

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

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

the class GriddedElevationModel method getScaleXY.

default double getScaleXY() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final double scaleXy = geometryFactory.getScaleXY();
    return scaleXy;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 5 with GeometryFactory

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

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