Search in sources :

Example 21 with BoundingBox

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

the class ShapefileGeometryUtil method writeMultipoint.

private void writeMultipoint(final EndianOutput out, final Geometry geometry, final int shapeType, final int wordsPerPoint) throws IOException {
    if (geometry instanceof Punctual) {
        final int vertexCount = geometry.getVertexCount();
        if (this.writeLength) {
            final int recordLength = 20 + wordsPerPoint * vertexCount;
            // (BYTES_IN_INT + 4 * BYTES_IN_DOUBLE + BYTES_IN_INT +
            // (vertexCount * 2 * BYTES_IN_DOUBLE)) / BYTES_IN_SHORT;
            out.writeInt(recordLength);
        }
        out.writeLEInt(shapeType);
        final BoundingBox envelope = geometry.getBoundingBox();
        writeEnvelope(out, envelope);
        out.writeLEInt(vertexCount);
        writeXYCoordinates(out, geometry);
    } else {
        throw new IllegalArgumentException("Expecting Punctual geometry got " + geometry.getGeometryType());
    }
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 22 with BoundingBox

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

the class ShapefileGeometryUtil method writeZCoordinatesRange.

public void writeZCoordinatesRange(final EndianOutput out, final Geometry geometry) throws IOException {
    final BoundingBox boundingBox = geometry.getBoundingBox();
    final double min = boundingBox.getMin(2);
    final double max = boundingBox.getMax(2);
    if (Double.isNaN(min) || Double.isNaN(max)) {
        out.writeLEDouble(0);
        out.writeLEDouble(0);
    } else {
        out.writeLEDouble(min);
        out.writeLEDouble(max);
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 23 with BoundingBox

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

the class ShapefileGeometryUtil method writeMCoordinatesRange.

public void writeMCoordinatesRange(final EndianOutput out, final Geometry geometry) throws IOException {
    final BoundingBox boundingBox = geometry.getBoundingBox();
    final double minM = boundingBox.getMin(3);
    final double maxM = boundingBox.getMax(3);
    if (Double.isNaN(minM) || Double.isNaN(maxM)) {
        out.writeLEDouble(0);
        out.writeLEDouble(0);
    } else {
        out.writeLEDouble(minM);
        out.writeLEDouble(maxM);
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 24 with BoundingBox

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

the class ShapefileGeometryUtil method writePolygon.

private List<LineString> writePolygon(final EndianOutput out, final Geometry geometry, final int shapeType, final int headerOverhead, final int wordsPerPoint) throws IOException {
    int vertexCount = 0;
    final List<LineString> rings = new ArrayList<>();
    for (int i = 0; i < geometry.getGeometryCount(); i++) {
        final Geometry part = geometry.getGeometry(i);
        if (part instanceof Polygon) {
            final Polygon polygon = (Polygon) part;
            LineString shell = polygon.getShell();
            shell = shell.toClockwise();
            rings.add(shell);
            vertexCount += shell.getVertexCount();
            final int numHoles = polygon.getHoleCount();
            for (int j = 0; j < numHoles; j++) {
                LineString hole = polygon.getHole(j);
                hole = hole.toCounterClockwise();
                rings.add(hole);
                vertexCount += hole.getVertexCount();
            }
        } else {
            throw new IllegalArgumentException("Expecting " + Polygon.class + " geometry got " + part.getClass());
        }
    }
    final int numParts = rings.size();
    if (this.writeLength) {
        final int recordLength = 22 + headerOverhead + 2 * numParts + wordsPerPoint * vertexCount;
        out.writeInt(recordLength);
    }
    out.writeLEInt(shapeType);
    final BoundingBox envelope = geometry.getBoundingBox();
    writeEnvelope(out, envelope);
    out.writeLEInt(numParts);
    out.writeLEInt(vertexCount);
    int partIndex = 0;
    for (final LineString ring : rings) {
        out.writeLEInt(partIndex);
        partIndex += ring.getVertexCount();
    }
    for (final LineString ring : rings) {
        writeXYCoordinates(out, ring);
    }
    return rings;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 25 with BoundingBox

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

the class ShapefileGeometryHandler method writePolyline.

private void writePolyline(final EndianOutput out, final Geometry geometry, final int shapeType, final int wordsPerPoint) {
    if (geometry instanceof Lineal) {
        final int numCoordinates = geometry.getVertexCount();
        final int numGeometries = geometry.getGeometryCount();
        final BoundingBox envelope = geometry.getBoundingBox();
        if (this.writeLength) {
            // final int recordLength = ((3 + numGeometries) * BYTES_IN_INT + (4 + 2
            // * numCoordinates)
            // * BYTES_IN_DOUBLE) / 2;
            final int recordLength = 22 + numGeometries * 2 + numCoordinates * wordsPerPoint;
            out.writeInt(recordLength);
        }
        out.writeLEInt(shapeType);
        writeEnvelope(out, envelope);
        out.writeLEInt(numGeometries);
        out.writeLEInt(numCoordinates);
        writePolylinePartIndexes(out, geometry);
        writeXYCoordinates(out, geometry);
    } else {
        throw new IllegalArgumentException("Expecting Lineal geometry got " + geometry.getGeometryType() + "\n" + geometry);
    }
}
Also used : Lineal(com.revolsys.geometry.model.Lineal) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Aggregations

BoundingBox (com.revolsys.geometry.model.BoundingBox)307 Point (com.revolsys.geometry.model.Point)83 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)76 ArrayList (java.util.ArrayList)45 Geometry (com.revolsys.geometry.model.Geometry)41 LineString (com.revolsys.geometry.model.LineString)26 List (java.util.List)26 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)19 Polygon (com.revolsys.geometry.model.Polygon)14 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)14 Project (com.revolsys.swing.map.layer.Project)14 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)12 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)11 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)11 Edge (com.revolsys.geometry.graph.Edge)10 HashMap (java.util.HashMap)10 Record (com.revolsys.record.Record)9 Graphics2D (java.awt.Graphics2D)9 MapEx (com.revolsys.collection.map.MapEx)8 LinearRing (com.revolsys.geometry.model.LinearRing)8