private void copy(Coordinate co, double[] ordinates, DimensionalFlag flag) { ordinates[flag.X] = co.x; ordinates[flag.Y] = co.y; if (flag.is3D()) ordinates[flag.Z] = co.z; if (flag.isMeasured()) { ordinates[flag.M] = (co instanceof DimensionalCoordinate) ? ((DimensionalCoordinate) co).m : Double.NaN; } }
protected void writeTypeCodeAndSrid( Geometry geometry, DimensionalFlag dimension, ByteBuffer output) { int typeCode = getGeometryType(geometry); boolean hasSrid = (geometry.getSRID() > 0); if (hasSrid && !hasWrittenSrid) typeCode |= PostgisWkbTypeMasks.SRID_FLAG; if (dimension.isMeasured()) typeCode |= PostgisWkbTypeMasks.M_FLAG; if (dimension.is3D()) typeCode |= PostgisWkbTypeMasks.Z_FLAG; output.putUInt(typeCode); if (hasSrid && !hasWrittenSrid) { output.putInt(geometry.getSRID()); hasWrittenSrid = true; } }
@Override public void visit(LinearRing geom) { writeByteOrder(output); DimensionalFlag dimension = DimensionalFlag.valueOf(geom.is3D(), geom.isMeasured()); writeTypeCodeAndSrid(geom, dimension, output); writeRing(geom); }
@Override public void visit(GeometryCollection geom) { writeByteOrder(output); DimensionalFlag dimension = DimensionalFlag.valueOf(geom.is3D(), geom.isMeasured()); writeTypeCodeAndSrid(geom, dimension, output); output.putUInt(geom.getNumGeometries()); }
@Override public void visit(Point geom) { writeByteOrder(output); DimensionalFlag dimension = DimensionalFlag.valueOf(geom.is3D(), geom.isMeasured()); writeTypeCodeAndSrid(geom, dimension, output); writePoints(geom.getPoints(), geom.getCoordinateDimension(), output); }
private CoordinateSequence fromCoordinateArray(Coordinate[] coordinates, DimensionalFlag dim) { PointSequenceBuilder builder = PointSequenceBuilders.fixedSized(coordinates.length, dim); double[] ordinates = new double[dim.getCoordinateDimension()]; for (Coordinate co : coordinates) { copy(co, ordinates, dim); builder.add(ordinates); } return (CoordinateSequence) builder.toPointSequence(); }
@Override public void visit(PolyHedralSurface geom) { writeByteOrder(output); DimensionalFlag dimension = DimensionalFlag.valueOf(geom.is3D(), geom.isMeasured()); writeTypeCodeAndSrid(geom, dimension, output); output.putUInt(geom.getNumPatches()); for (Polygon pg : geom) { pg.accept(this); } }
@Override public void visit(Polygon geom) { writeByteOrder(output); DimensionalFlag dimension = DimensionalFlag.valueOf(geom.is3D(), geom.isMeasured()); writeTypeCodeAndSrid(geom, dimension, output); writeNumRings(geom, output); for (LinearRing ring : geom) { writeRing(ring); } }