Search in sources :

Example 96 with Geometry

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

the class PackedCoordinateUtil method writeMultiCoordinates.

private static void writeMultiCoordinates(final PackedIntegerOutputStream out, final List<List<Geometry>> partsList, final int axisIndex, final double offset, final double scale) {
    long previous = Math.round(offset * scale);
    boolean firstPart = true;
    for (final List<Geometry> part : partsList) {
        if (firstPart) {
            firstPart = false;
        } else {
            out.writeLong(-previous);
            previous = 0;
        }
        for (final Geometry component : part) {
            if (component.getAxisCount() > axisIndex) {
                previous = writeCoordinates(out, component, previous, scale, axisIndex);
            } else {
                previous = writeZeroCoordinates(out, component.getVertexCount(), scale, previous);
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry)

Example 97 with Geometry

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

the class PackedCoordinateUtil method getPackedBytes.

public static byte[] getPackedBytes(final Double xOffset, final Double yOffset, final Double xyScale, final boolean hasZ, final Double zOffset, final Double zScale, final boolean hasM, final Double mScale, final Double mOffset, final List<List<Geometry>> parts) {
    final int packedByteLength = 0;
    byte dimensionFlag = 0;
    final byte annotationDimension = 0;
    final byte shapeFlags = 0;
    if (hasZ) {
        dimensionFlag |= 1;
    }
    if (hasM) {
        dimensionFlag |= 2;
    }
    final PackedIntegerOutputStream out = new PackedIntegerOutputStream();
    out.writeLong5(packedByteLength);
    out.writeLong(dimensionFlag);
    out.writeLong(annotationDimension);
    out.writeLong(shapeFlags);
    // Write x,y for all parts
    long previousX = Math.round(xOffset * xyScale);
    long previousY = Math.round(yOffset * xyScale);
    boolean first = true;
    for (final List<Geometry> part : parts) {
        if (first) {
            first = false;
        } else {
            out.writeLong(-1 - previousX);
            out.writeLong(-previousY);
            previousX = -1;
            previousY = 0;
        }
        for (final Geometry component : part) {
            for (final Vertex vertex : component.vertices()) {
                previousX = writeCoordinate(out, vertex, previousX, xyScale, 0);
                previousY = writeCoordinate(out, vertex, previousY, xyScale, 1);
            }
        }
    }
    // Write z for all parts
    if (hasZ) {
        writeMultiCoordinates(out, parts, 2, zOffset, zScale);
    }
    // Write m for all parts
    if (hasM) {
        writeMultiCoordinates(out, parts, 3, mOffset, mScale);
    }
    return out.toByteArray();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) Point(com.revolsys.geometry.model.Point)

Example 98 with Geometry

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

the class PackedGeometry method checkGeometry.

public static void checkGeometry(final Geometry geometry) {
    final GeometryFactory geometryFactory = geometry.getGeometryFactory();
    final Double xOffset = 0.0;
    final Double yOffset = 0.0;
    final Double xyScale = geometryFactory.getScaleXY();
    final Double zOffset = 0.0;
    final Double zScale = geometryFactory.getScaleZ();
    final boolean hasZ = zScale > 0;
    final boolean hasM = false;
    final Double mScale = null;
    final Double mOffset = null;
    final List<List<Geometry>> parts = ArcSdeStGeometryFieldDefinition.getParts(geometry);
    final int numPoints = PackedCoordinateUtil.getNumPoints(parts);
    final byte[] data = PackedCoordinateUtil.getPackedBytes(xOffset, yOffset, xyScale, hasZ, zOffset, zScale, hasM, mScale, mOffset, parts);
    final int geometryType = ArcSdeConstants.getStGeometryType(geometry);
    try {
        final Geometry geometry2 = PackedCoordinateUtil.getGeometry(data, geometryFactory, geometryType, numPoints, xOffset, yOffset, xyScale, zOffset, zScale, mOffset, mScale);
        System.out.println(WktWriter.toString(geometry));
        if (!DataTypes.GEOMETRY.equals(geometry, geometry2, Collections.<String>emptyList())) {
            System.err.println(WktWriter.toString(geometry2));
            throw new RuntimeException("Geometry not equal");
        }
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) List(java.util.List) IOException(java.io.IOException)

Example 99 with Geometry

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

the class OgrRecordWriter method addParts.

private void addParts(final org.gdal.ogr.Geometry ogrGeometry, final Geometry geometry, final int geometryType, final int axisCount) {
    for (final Geometry part : geometry.geometries()) {
        final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(part, geometryType, axisCount);
        ogrGeometry.AddGeometry(ogrRing);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry)

Example 100 with Geometry

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

the class OgrRecordWriter method toOgrGeometry.

protected org.gdal.ogr.Geometry toOgrGeometry(final Geometry geometry, final int geometryType, final int axisCount) {
    final org.gdal.ogr.Geometry ogrGeometry = new org.gdal.ogr.Geometry(geometryType);
    if (!geometry.isEmpty()) {
        switch(geometryType) {
            case 1:
            case 0x80000000 + 1:
                {
                    final Point point = (Point) geometry;
                    final double x = point.getX();
                    final double y = point.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = point.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 2:
            case 0x80000000 + 2:
                final LineString line = (LineString) geometry;
                final int vertexCount = line.getVertexCount();
                for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
                    final double x = line.getX(vertexIndex);
                    final double y = line.getY(vertexIndex);
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = line.getZ(vertexIndex);
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 3:
            case 0x80000000 + 3:
                for (final LinearRing ring : ((Polygon) geometry).rings()) {
                    final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(ring, 101, axisCount);
                    ogrGeometry.AddGeometry(ogrRing);
                }
                break;
            case 4:
                addParts(ogrGeometry, geometry, 1, axisCount);
                break;
            case 0x80000000 + 4:
                addParts(ogrGeometry, geometry, 0x80000000 + 1, axisCount);
                break;
            case 5:
                addParts(ogrGeometry, geometry, 2, axisCount);
                break;
            case 0x80000000 + 5:
                addParts(ogrGeometry, geometry, 0x80000000 + 2, axisCount);
                break;
            case 6:
                addParts(ogrGeometry, geometry, 3, axisCount);
                break;
            case 0x80000000 + 6:
                addParts(ogrGeometry, geometry, 0x80000000 + 3, axisCount);
                break;
            // return this.geometryFactory.geometry(parts);
            case 101:
                for (final Vertex vertex : geometry.vertices()) {
                    final double x = vertex.getX();
                    final double y = vertex.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = vertex.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            default:
                return null;
        }
    }
    if (axisCount == 2) {
        ogrGeometry.FlattenTo2D();
    }
    return ogrGeometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)488 Point (com.revolsys.geometry.model.Point)140 LineString (com.revolsys.geometry.model.LineString)87 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)75 ArrayList (java.util.ArrayList)70 BoundingBox (com.revolsys.geometry.model.BoundingBox)39 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)39 Polygon (com.revolsys.geometry.model.Polygon)34 List (java.util.List)33 Record (com.revolsys.record.Record)32 Iterator (java.util.Iterator)20 RecordDefinition (com.revolsys.record.schema.RecordDefinition)18 LinearRing (com.revolsys.geometry.model.LinearRing)16 Vertex (com.revolsys.geometry.model.vertex.Vertex)16 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)14 LineSegment (com.revolsys.geometry.model.segment.LineSegment)13 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)13 FieldDefinition (com.revolsys.record.schema.FieldDefinition)12 DataType (com.revolsys.datatype.DataType)10 IOException (java.io.IOException)10