Search in sources :

Example 11 with GeometryFactory

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

the class EsriAsciiGriddedElevationModelReader method getBufferedReader.

protected BufferedReader getBufferedReader() {
    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);
                    setGeometryFactory(geometryFactory);
                } else if (name.equals(fileName)) {
                    this.reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
                    return this.reader;
                }
            }
            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);
            this.reader = new BufferedReader(new InputStreamReader(gzIn, StandardCharsets.UTF_8));
            return this.reader;
        } else {
            setGeometryFactory(this.resource);
            this.reader = this.resource.newBufferedReader();
            return this.reader;
        }
    } 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) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 12 with GeometryFactory

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

the class EsriAsciiGriddedElevationModelWriter method open.

protected void open(final GriddedElevationModel model) {
    final GeometryFactory geometryFactory = model.getGeometryFactory();
    if (this.writer == null) {
        final String fileNameExtension = this.resource.getFileNameExtension();
        final OutputStream bufferedOut = this.resource.newBufferedOutputStream();
        if ("zip".equals(fileNameExtension) || ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION_ZIP.equals(fileNameExtension)) {
            try {
                final String fileName = this.resource.getBaseName();
                final ZipOutputStream zipOut = new ZipOutputStream(bufferedOut);
                final String prjString = geometryFactory.toWktCs();
                if (prjString.length() > 0) {
                    final ZipEntry prjEntry = new ZipEntry(FileUtil.getBaseName(fileName) + ".prj");
                    zipOut.putNextEntry(prjEntry);
                    zipOut.write(prjString.getBytes(StandardCharsets.UTF_8));
                }
                final ZipEntry fileEntry = new ZipEntry(fileName);
                zipOut.putNextEntry(fileEntry);
                this.writer = new OutputStreamWriter(zipOut, StandardCharsets.UTF_8);
            } catch (final IOException e) {
                throw Exceptions.wrap("Error creating: " + this.resource, e);
            }
        } else if ("gz".equals(fileNameExtension)) {
            try {
                String fileName = this.resource.getBaseName();
                if (!fileName.endsWith("." + ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION)) {
                    fileName += "." + ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION;
                }
                final GZIPOutputStream zipOut = new GZIPOutputStream(bufferedOut);
                this.writer = new OutputStreamWriter(zipOut, StandardCharsets.UTF_8);
            } catch (final IOException e) {
                throw Exceptions.wrap("Error creating: " + this.resource, e);
            }
        } else {
            geometryFactory.writePrjFile(this.resource);
            this.writer = this.resource.newWriter();
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipEntry(java.util.zip.ZipEntry) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException)

Example 13 with GeometryFactory

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

the class ScaledIntegerGriddedDigitalElevationModelFile method createNewFile.

protected void createNewFile() throws IOException {
    Paths.createParentDirectories(this.path);
    this.channel = FileChannel.open(this.path, Paths.OPEN_OPTIONS_READ_WRITE_SET, this.fileAttributes);
    try (final ChannelWriter writer = new ChannelWriter(this.channel)) {
        final int gridWidth = getGridWidth();
        final int gridHeight = getGridHeight();
        final double gridCellSize = getGridCellSize();
        final BoundingBox boundingBox = getBoundingBox();
        final GeometryFactory geometryFactory = getGeometryFactory();
        ScaledIntegerGriddedDigitalElevationModelWriter.writeHeader(writer, boundingBox, geometryFactory, gridWidth, gridHeight, (int) gridCellSize);
        final int count = gridWidth * gridHeight;
        for (int i = 0; i < count; i++) {
            writer.putInt(Integer.MIN_VALUE);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 14 with GeometryFactory

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

the class ScaledIntegerTriangulatedIrregularNetworkReader method forEachTriangle.

public void forEachTriangle(final TriangleConsumer action) {
    open();
    final GeometryFactory geometryFactory = this.geometryFactory;
    final ChannelReader in = this.in;
    try {
        boolean hasMore = true;
        while (hasMore) {
            int triangleVertexCount = 0;
            try {
                final double x1 = geometryFactory.toDoubleX(in.getInt());
                final double y1 = geometryFactory.toDoubleY(in.getInt());
                final double z1 = geometryFactory.toDoubleZ(in.getInt());
                final double x2 = geometryFactory.toDoubleX(in.getInt());
                final double y2 = geometryFactory.toDoubleY(in.getInt());
                final double z2 = geometryFactory.toDoubleZ(in.getInt());
                final double x3 = geometryFactory.toDoubleX(in.getInt());
                final double y3 = geometryFactory.toDoubleY(in.getInt());
                final double z3 = geometryFactory.toDoubleZ(in.getInt());
                action.accept(x1, y1, z1, x2, y2, z2, x3, y3, z3);
                triangleVertexCount = 9;
            } catch (final WrappedException e) {
                if (Exceptions.isException(e, EOFException.class) && triangleVertexCount == 0) {
                    hasMore = false;
                } else {
                    throw e;
                }
            }
        }
    } finally {
        close();
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ChannelReader(com.revolsys.io.channels.ChannelReader)

Example 15 with GeometryFactory

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

the class Graph method moveToMidpoint.

public void moveToMidpoint(final Map<Point, Point> movedNodes, final Graph<T> graph1, final Node<T> node1, final Node<T> node2) {
    final GeometryFactory precisionModel = graph1.getPrecisionModel();
    final Point midPoint = LineSegmentUtil.midPoint(precisionModel, node1, node2);
    if (!node1.equals(2, midPoint)) {
        if (movedNodes != null) {
            movedNodes.put(node1.newPoint2D(), midPoint);
        }
        node1.moveNode(midPoint);
    }
    if (!node2.equals(2, midPoint)) {
        if (movedNodes != null) {
            movedNodes.put(node2.newPoint2D(), midPoint);
        }
        node2.moveNode(midPoint);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) 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