Search in sources :

Example 51 with LineString

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

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

the class ShapefileGeometryHandler method writeZCoordinatesRange.

public void writeZCoordinatesRange(final EndianOutput out, final List<LineString> coordinatesList) {
    double minZ = Double.MAX_VALUE;
    double maxZ = -Double.MAX_VALUE;
    for (final LineString ring : coordinatesList) {
        for (int i = 0; i < ring.getVertexCount(); i++) {
            double z = ring.getCoordinate(i, 2);
            if (Double.isNaN(z)) {
                z = 0;
            }
            minZ = Math.min(z, minZ);
            maxZ = Math.max(z, maxZ);
        }
    }
    if (minZ == Double.MAX_VALUE || maxZ == -Double.MAX_VALUE) {
        out.writeLEDouble(0);
        out.writeLEDouble(0);
    } else {
        out.writeLEDouble(minZ);
        out.writeLEDouble(maxZ);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 53 with LineString

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

the class ShapefileGeometryHandler method writeMCoordinatesRange.

public void writeMCoordinatesRange(final EndianOutput out, final List<LineString> coordinatesList) {
    double minM = Double.MAX_VALUE;
    double maxM = -Double.MAX_VALUE;
    for (final LineString ring : coordinatesList) {
        for (int i = 0; i < ring.getVertexCount(); i++) {
            double m = ring.getCoordinate(i, 2);
            if (Double.isNaN(m)) {
                m = 0;
            }
            minM = Math.min(m, minM);
            maxM = Math.max(m, maxM);
        }
    }
    if (minM == Double.MAX_VALUE && maxM == -Double.MAX_VALUE) {
        out.writeLEDouble(0);
        out.writeLEDouble(0);
    } else {
        out.writeLEDouble(minM);
        out.writeLEDouble(maxM);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 54 with LineString

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

the class ShapefileGeometryHandler method readPolyline.

public Geometry readPolyline(final GeometryFactory geometryFactory, final ByteBuffer buffer, final int recordLength) {
    buffer.getDouble();
    buffer.getDouble();
    buffer.getDouble();
    buffer.getDouble();
    final int numParts = buffer.getInt();
    final int vertexCount = buffer.getInt();
    final int axisCount = 2;
    if (numParts == 1) {
        buffer.getInt();
        final double[] coordinates = readXYCoordinates(buffer, vertexCount, axisCount);
        return geometryFactory.lineString(2, coordinates);
    } else {
        final int[] partIndex = new int[numParts + 1];
        partIndex[numParts] = vertexCount;
        for (int i = 0; i < partIndex.length - 1; i++) {
            partIndex[i] = buffer.getInt();
        }
        final List<LineString> lines = new ArrayList<>();
        for (int i = 0; i < partIndex.length - 1; i++) {
            final int startIndex = partIndex[i];
            final int endIndex = partIndex[i + 1];
            final int numCoords = endIndex - startIndex;
            final double[] coordinates = readXYCoordinates(buffer, numCoords, axisCount);
            lines.add(geometryFactory.lineString(2, coordinates));
        }
        return geometryFactory.lineal(lines);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point)

Example 55 with LineString

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

the class MoepBinaryIterator method readLineString.

private void readLineString(final int extraParams, final Record object) throws IOException {
    int numCoords = 0;
    if (extraParams == 2 || extraParams == 4) {
        numCoords = readLEShort(this.in);
    } else {
        numCoords = read();
    }
    if (extraParams == 3 || extraParams == 4) {
        final int z = readLEShort(this.in);
        final LineString line = readContourLine(numCoords);
        object.setGeometryValue(line);
        object.setValue(MoepConstants.ELEVATION, z);
    } else {
        final LineString line = readSimpleLine(numCoords);
        object.setGeometryValue(line);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Aggregations

LineString (com.revolsys.geometry.model.LineString)380 Point (com.revolsys.geometry.model.Point)184 Geometry (com.revolsys.geometry.model.Geometry)65 ArrayList (java.util.ArrayList)62 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)51 Polygon (com.revolsys.geometry.model.Polygon)37 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)24 Edge (com.revolsys.geometry.graph.Edge)22 List (java.util.List)22 BoundingBox (com.revolsys.geometry.model.BoundingBox)20 Lineal (com.revolsys.geometry.model.Lineal)20 Test (org.junit.Test)20 LinearRing (com.revolsys.geometry.model.LinearRing)19 Record (com.revolsys.record.Record)17 Iterator (java.util.Iterator)14 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)13 Punctual (com.revolsys.geometry.model.Punctual)12 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)12 LineSegment (com.revolsys.geometry.model.segment.LineSegment)10 Polygonal (com.revolsys.geometry.model.Polygonal)9