/** * Reads a coordinate value with the specified dimensionality. * Makes the X and Y ordinates precise according to the precision model * in use. */ private void readCoordinate() throws IOException { for (int i = 0; i < inputDimension; i++) { if (i <= 1) { ordValues[i] = precisionModel.makePrecise(dis.readDouble()); } else { ordValues[i] = dis.readDouble(); } } }
/** * Reads a {@link Geometry} in binary WKB format from an {@link InStream}. * * @param is the stream to read from * @return the Geometry read * @throws IOException if the underlying stream creates an error * @throws ParseException if the WKB is ill-formed */ public Geometry read(InStream is) throws IOException, ParseException { dis.setInStream(is); Geometry g = readGeometry(); return g; }
/** * Read the first bytes of Geometry WKB. * @param bytes WKB Bytes * @return Geometry MetaData * @throws IOException If WKB meta is invalid (do not check the Geometry) */ public static GeometryMetaData getMetaDataFromWKB(byte[] bytes) throws IOException { ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); // determine byte order byte byteOrderWKB = dis.readByte(); // always set byte order, since it may change from geometry to geometry int byteOrder = byteOrderWKB == WKBConstants.wkbNDR ? ByteOrderValues.LITTLE_ENDIAN : ByteOrderValues.BIG_ENDIAN; dis.setOrder(byteOrder); int typeInt = dis.readInt(); int geometryType = typeInt & 0xff; // determine if Z values are present boolean hasZ = (typeInt & 0x80000000) != 0; int inputDimension = hasZ ? 3 : 2; // determine if SRIDs are present boolean hasSRID = (typeInt & 0x20000000) != 0; int SRID = 0; if (hasSRID) { SRID = dis.readInt(); } return new GeometryMetaData(inputDimension, hasSRID, hasZ, geometryType, SRID); } }
private LineString readLineString() throws IOException { int size = dis.readInt(); CoordinateSequence pts = readCoordinateSequenceLineString(size); return factory.createLineString(pts); }
private Shape[] readShapes(ByteOrderDataInStream is, int num) throws IOException { Shape[] shapes = new Shape[num]; for (int i = 0; i < num; i++) { Shape shape = new Shape(); shape.parentOffset = is.readInt(); shape.figureOffset = is.readInt(); shape.type = TYPES[is.readByte() - 1]; shapes[i] = shape; } return shapes; }
/** * Read the first bytes of Geometry WKB. * @param bytes WKB Bytes * @return Geometry MetaData * @throws IOException If WKB meta is invalid (do not check the Geometry) */ public static GeometryMetaData getMetaDataFromWKB(byte[] bytes) throws IOException { ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); // determine byte order byte byteOrderWKB = dis.readByte(); // always set byte order, since it may change from geometry to geometry int byteOrder = byteOrderWKB == WKBConstants.wkbNDR ? ByteOrderValues.LITTLE_ENDIAN : ByteOrderValues.BIG_ENDIAN; dis.setOrder(byteOrder); int typeInt = dis.readInt(); int geometryType = typeInt & 0xff; // determine if Z values are present boolean hasZ = (typeInt & 0x80000000) != 0; int inputDimension = hasZ ? 3 : 2; // determine if SRIDs are present boolean hasSRID = (typeInt & 0x20000000) != 0; int SRID = 0; if (hasSRID) { SRID = dis.readInt(); } return new GeometryMetaData(inputDimension, hasSRID, hasZ, geometryType, SRID); } }
private LinearRing readLinearRing() throws IOException { int size = dis.readInt(); CoordinateSequence pts = readCoordinateSequenceRing(size); return factory.createLinearRing(pts); }
private Shape[] readShapes(ByteOrderDataInStream is, int num) throws IOException { Shape[] shapes = new Shape[num]; for (int i = 0; i < num; i++) { Shape shape = new Shape(); shape.parentOffset = is.readInt(); shape.figureOffset = is.readInt(); shape.type = TYPES[is.readByte() - 1]; shapes[i] = shape; } return shapes; }
public Geometry read(InStream is) throws IOException { ByteOrderDataInStream dis = new ByteOrderDataInStream(is); dis.setOrder(ByteOrderValues.LITTLE_ENDIAN); srid = dis.readInt(); version = dis.readByte(); serializationProps = dis.readByte(); hasZ = (serializationProps & 1) == 1; hasM = (serializationProps & 2) == 2; numberOfPoints = 2; } else if (!singlePoint) { numberOfPoints = dis.readInt(); int numberOfFigures = dis.readInt(); figures = readFigures(dis, numberOfFigures); int numberOfShapes = dis.readInt(); shapes = readShapes(dis, numberOfShapes); return decode(0);
private GeometryCollection readGeometryCollection() throws IOException, ParseException { int numGeom = dis.readInt(); Geometry[] geoms = new Geometry[numGeom]; for (int i = 0; i < numGeom; i++) { geoms[i] = readGeometry(); } return factory.createGeometryCollection(geoms); }
private double[] readDoubles(ByteOrderDataInStream is, int num) throws IOException { double[] doubles = new double[num]; for (int i = 0; i < num; i++) { doubles[i] = is.readDouble(); } return doubles; }
/** * Reads a {@link Geometry} in binary WKB format from an {@link InStream}. * * @param is the stream to read from * @return the Geometry read * @throws IOException if the underlying stream creates an error * @throws ParseException if the WKB is ill-formed */ public Geometry read(InStream is) throws IOException, ParseException { dis.setInStream(is); Geometry g = readGeometry(); return g; }
public Geometry read(InStream is) throws IOException { ByteOrderDataInStream dis = new ByteOrderDataInStream(is); dis.setOrder(ByteOrderValues.LITTLE_ENDIAN); srid = dis.readInt(); version = dis.readByte(); serializationProps = dis.readByte(); hasZ = (serializationProps & 1) == 1; hasM = (serializationProps & 2) == 2; numberOfPoints = 2; } else if (!singlePoint) { numberOfPoints = dis.readInt(); int numberOfFigures = dis.readInt(); figures = readFigures(dis, numberOfFigures); int numberOfShapes = dis.readInt(); shapes = readShapes(dis, numberOfShapes); return decode(0);
private MultiPoint readMultiPoint() throws IOException, ParseException { int numGeom = dis.readInt(); Point[] geoms = new Point[numGeom]; for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (! (g instanceof Point)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPoint"); geoms[i] = (Point) g; } return factory.createMultiPoint(geoms); }
private double[][] readPoints(ByteOrderDataInStream is, int num) throws IOException { double[][] points = new double[num][]; for (int i = 0; i < num; i++) { points[i] = new double[]{is.readDouble(), is.readDouble()}; } return points; }