private LinearRing readLinearRing() throws IOException { int size = dis.readInt(); CoordinateSequence pts = readCoordinateSequenceRing(size); return factory.createLinearRing(pts); }
ByteOrderDataInStream din = new ByteOrderDataInStream(input); din.setOrder(h.getFlags().getEndianess()); h.setSrid(din.readInt()); double x1 = din.readDouble(); double x2 = din.readDouble(); double y1 = din.readDouble(); double y2 = din.readDouble(); din.readDouble(); din.readDouble(); din.readDouble(); din.readDouble();
private void readShapes() throws IOException { int numberOfShapes; Shape[] shapesMetadata; numberOfShapes = dis.readInt(); shapesMetadata = new Shape[numberOfShapes]; for (int i = 0; i < numberOfShapes; i++) { int parentOffset = dis.readInt(); int figureOffset = dis.readInt(); int shapeType = dis.readByte(); shapesMetadata[i] = new Shape(parentOffset, figureOffset, shapeType); } binary.setShapes(shapesMetadata); }
rs.next(); byte[] bytes = rs.getBytes(1); ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); byte byteOrder = dis.readByte(); if (byteOrder == WKBConstants.wkbNDR) dis.setOrder(ByteOrderValues.LITTLE_ENDIAN); int geometryType = dis.readInt(); if (geometryType == 1001) di.setHasOGCWkbZTyps(true); rs.close();
/** * 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; }
private void parse(InStream is) throws IOException { dis.setInStream(is); dis.setOrder(ByteOrderValues.LITTLE_ENDIAN); binary.setSrid(dis.readInt()); byte version = dis.readByte(); if (version != 1) { throw new SqlServerBinaryParseException( "Unsupported version (only supports version 1): " + version); } binary.setSerializationProperties(dis.readByte()); readNumberOfPoints(); readCoordinates(); readZValues(); readMValues(); if (binary.isSinglePoint()) { binary.setFigures(new Figure[] {new Figure(1, 0)}); binary.setShapes(new Shape[] {new Shape(-1, 0, 2)}); } else if (binary.hasSingleLineSegment()) { binary.setFigures(new Figure[] {new Figure(1, 0)}); binary.setShapes(new Shape[] {new Shape(-1, 0, 1)}); } else { readFigures(); readShapes(); } }
private void readFigures() throws IOException { int numberOfFigures; Figure[] figuresMetadata; numberOfFigures = dis.readInt(); figuresMetadata = new Figure[numberOfFigures]; for (int i = 0; i < numberOfFigures; i++) { byte figureAttribute = dis.readByte(); int figurePointOffset = dis.readInt(); figuresMetadata[i] = new Figure(figureAttribute, figurePointOffset); } binary.setFigures(figuresMetadata); }
private Coordinate readCoordinate() throws IOException { return new Coordinate(dis.readDouble(), dis.readDouble()); } }
/** * Reads a {@link Geometry} from an {@link InStream). * * @param is the stream to read from * @return the Geometry read * @throws IOException * @throws ParseException */ public Geometry read(InStream is) throws IOException, ParseException { dis.setInStream(is); Geometry g = readGeometry(); setSRID(g); 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 Geometry readCircularString() throws IOException { int size = dis.readInt(); CoordinateSequence pts = readCoordinateSequenceCircularString(size); return factory.createCurvedGeometry(pts); }
ByteOrderDataInStream din = new ByteOrderDataInStream(input); din.setOrder(h.getFlags().getEndianess()); h.setSrid(din.readInt()); double x1 = din.readDouble(); double x2 = din.readDouble(); double y1 = din.readDouble(); double y2 = din.readDouble(); din.readDouble(); din.readDouble(); din.readDouble(); din.readDouble();
/** * 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; }
private Geometry readCompoundCurve() throws IOException, ParseException { int numGeom = dis.readInt(); List<LineString> geoms = new ArrayList<>(); for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (!(g instanceof LineString)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "CompoundCurve"); geoms.add((LineString) g); } return factory.createCurvedGeometry(geoms); }
private void readMValues() throws IOException { // measure values are currently discarded, as they cannot be represented in a JTS Geometry if (binary.hasM()) { for (int i = 0; i < binary.getNumberOfPoints(); i++) { dis.readDouble(); } } }