public Geometry getGeometryNoCopy() { if (geometry == null) { try { geometry = new WKBReader().read(bytes); } catch (ParseException ex) { throw DbException.convert(ex); } } return geometry; }
@Override public Geometry loadFootprint(String pathNoExtension) throws Exception { File file = new File(pathNoExtension + ".wkb"); if (file.exists()) { FileInputStream is = null; try { is = new FileInputStream(file); return reader.read(new InputStreamInStream(is)); } finally { IOUtils.closeQuietly(is); } } return null; }
public Geometry decodeGeometryValue( GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx, Hints hints) throws IOException, SQLException { byte[] bytes = rs.getBytes(column); if (bytes == null) { return null; } try { return new WKBReader(factory).read(bytes); } catch (ParseException e) { throw (IOException) new IOException().initCause(e); } // return JTS.geometryFromBytes( bytes ); }
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx) throws SQLException, IOException { // String wkb = rs.getString( column ); byte[] wkb = rs.getBytes(column); try { // TODO: srid Polygon polygon = (Polygon) new WKBReader().read(wkb); return polygon.getEnvelopeInternal(); } catch (ParseException e) { String msg = "Error decoding wkb for envelope"; throw (IOException) new IOException(msg).initCause(e); } }
@Override public Geometry decodeGeometryValue( GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx, Hints hints) throws IOException, SQLException { byte[] bytes = rs.getBytes(column); if (bytes == null) { return null; } try { return new WKBReader(factory).read(bytes); } catch (ParseException e) { throw (IOException) new IOException().initCause(e); } }
public Geometry decodeGeometryValue( GeometryDescriptor descriptor, ResultSet rs, String name, GeometryFactory factory, Connection cx, Hints hints) throws IOException, SQLException { byte[] bytes = rs.getBytes(name); if (bytes == null) { return null; } try { return new WKBReader(factory).read(bytes); } catch (ParseException e) { String msg = "Error decoding wkb"; throw (IOException) new IOException(msg).initCause(e); } }
@Override public Geometry decodeGeometryValue( GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx, Hints hints) throws IOException, SQLException { byte[] bytes = rs.getBytes(column); if (bytes == null) { return null; } try { return new WKBReader(factory).read(bytes); } catch (ParseException e) { String msg = "Error decoding wkb"; throw (IOException) new IOException(msg).initCause(e); } }
@Override public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx) throws SQLException, IOException { byte[] wkb = rs.getBytes(column); try { /** * As of MySQL 5.7.6, if the argument is a point or a vertical or horizontal line * segment, ST_Envelope() returns the point or the line segment as its MBR rather than * returning an invalid polygon therefore we must override behavior and check for a * geometry and not a polygon */ // TODO: srid Geometry geom = (Geometry) new WKBReader().read(wkb); return geom.getEnvelopeInternal(); } catch (ParseException e) { String msg = "Error decoding wkb for envelope"; throw (IOException) new IOException(msg).initCause(e); } }
@Override protected Envelope getEnvelopeFromResultSet(ResultSet r) throws SQLException { byte[] bytes = r.getBytes(2); WKBReader reader = new WKBReader(); Geometry bbox = null; try { bbox = reader.read(bytes); } catch (ParseException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new SQLException(e.getMessage()); } return bbox.getEnvelopeInternal(); }
protected Geometry read() throws IOException { // header must be read! // read the geometry try { WKBReader wkbReader = new WKBReader(factory); Geometry g = wkbReader.read(input); g.setSRID(header.getSrid()); return g; } catch (ParseException e) { throw new IOException(e); } }
@Override protected Envelope getEnvelopeFromResultSet(ResultSet r) throws SQLException { byte[] bytes = r.getBytes(2); WKBReader reader = new WKBReader(); Geometry bbox = null; try { bbox = reader.read(bytes); } catch (ParseException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new SQLException(e.getMessage()); } return bbox.getEnvelopeInternal(); }
public Geometry wkb2Geometry(InputStream inputStream) throws IOException { if (inputStream == null) // DJB: null value from database --> null // geometry (the same behavior as WKT). NOTE: // sending back a GEOMETRYCOLLECTION(EMPTY) is // also a possibility, but this is not the same // as NULL return null; try { inputStreamInStream.setIn(inputStream); return wkbr.read(inputStreamInStream); } catch (Exception e) { throw new DataSourceException("An exception occurred while parsing WKB data", e); } }
@Override public Geometry decodeGeometryValue( GeometryDescriptor descriptor, ResultSet rs, String column, GeometryFactory factory, Connection cx, Hints hints) throws IOException, SQLException { byte[] bytes = rs.getBytes(column); if (bytes == null) { return null; } if (useNativeSerialization) { try { return new SqlServerBinaryReader(factory).read(bytes); } catch (IOException e) { throw (IOException) new IOException().initCause(e); } } else { try { return new WKBReader(factory).read(bytes); } catch (ParseException e) { throw (IOException) new IOException().initCause(e); } } }
private static Geometry fromWKB(byte[] wkb) { try { ByteArrayInputStream bytes = new ByteArrayInputStream(wkb, 0, wkb.length - 4); // read the geometry Geometry g = new WKBReader().read(new InputStreamInStream(bytes)); // read the srid int srid = 0; srid |= wkb[wkb.length - 4] & 0xFF; srid <<= 8; srid |= wkb[wkb.length - 3] & 0xFF; srid <<= 8; srid |= wkb[wkb.length - 2] & 0xFF; srid <<= 8; srid |= wkb[wkb.length - 1] & 0xFF; g.setSRID(srid); return g; } catch (Exception e) { throw new RuntimeException(e); } }
/** * This method will convert a Well Known Binary representation to a JTS Geometry object. * * @return a JTS Geometry object that is equivalent to the WTB representation passed in by param * wkb * @throws IOException if more than one geometry object was found in the WTB representation, or * if the parser could not parse the WKB representation. */ public Geometry wkb2Geometry(byte[] wkbBytes) throws IOException { if (wkbBytes == null) // DJB: null value from database --> null geometry // (the same behavior as WKT). NOTE: sending back // a GEOMETRYCOLLECTION(EMPTY) is also a // possibility, but this is not the same as NULL return null; try { byteArrayInStream.setBytes(wkbBytes); return wkbr.read(byteArrayInStream); } catch (Exception e) { throw new DataSourceException("An exception occurred while parsing WKB data", e); } }
@Override protected Envelope getExtent(ImageLevelInfo li, Connection con) throws SQLException, IOException { String extentSelect = getExtentSelectStatment(li); String statementString = MessageFormat.format(extentSelect, new Object[] {li.getSpatialTableName()}); Envelope extent = null; PreparedStatement s = con.prepareStatement(statementString); ResultSet r = s.executeQuery(); WKBReader reader = new WKBReader(); while (r.next()) { byte[] bytes = r.getBytes(1); Geometry g; try { g = reader.read(bytes); } catch (ParseException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new IOException(e); } if (extent == null) { extent = g.getEnvelopeInternal(); } else { extent.expandToInclude(g.getEnvelopeInternal()); } } r.close(); s.close(); return extent; }
Geometry geom = new WKBReader().read(wkb); extent = geom.getEnvelopeInternal(); LOGGER.fine("creating Extent");
public Shape readJtsGeom(final DataInput dataInput) throws IOException { JtsSpatialContext ctx = (JtsSpatialContext)super.ctx; WKBReader reader = new WKBReader(ctx.getGeometryFactory()); try { InStream inStream = new InStream() {//a strange JTS abstraction boolean first = true; @Override public void read(byte[] buf) throws IOException { if (first) {//we don't write JTS's leading BOM so synthesize reading it if (buf.length != 1) throw new IllegalStateException("Expected initial read of one byte, not: " + buf.length); buf[0] = WKBConstants.wkbXDR;//0 first = false; } else { //TODO for performance, specialize for common array lengths: 1, 4, 8 dataInput.readFully(buf); } } }; Geometry geom = reader.read(inStream); //false: don't check for dateline-180 cross or multi-polygon overlaps; this won't happen // once it gets written, and we're reading it now return ctx.makeShape(geom, false, false); } catch (ParseException ex) { throw new InvalidShapeException("error reading WKT", ex); } }
+ "ABEuC8DAV+jS2XIy3MAYBQgfRHnAwFfslYpsZkDAFphJ8XbhQMBX6mVp0arUwBOSV/ye1QDAV+HZ\n" + "ntGQa8AQR2N8waYU"; Geometry geometry = new WKBReader().read(Base64.decode(wkb));
+ "4dme0ZBrwBBHY3zBphTAV+GPbx9YxMAQMbM4fB1AwFfivDEmxxzAEIAAI+c6wMBX4dme0ZBrwBBH\n" + "Y3zBphQ="; Geometry geometry = new WKBReader().read(Base64.decode(wkb));