@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; }
private void checkWKBGeometry(String wkbHex, String expectedWKT) throws ParseException { WKBReader wkbReader = new WKBReader(geomFactory); byte[] wkb = WKBReader.hexToBytes(wkbHex); Geometry g2 = wkbReader.read(wkb); WKTReader useRdr = rdr; if (expectedWKT.contains("ZM")) useRdr = rdrM; else if (expectedWKT.contains("M(") || expectedWKT.contains("M (")) useRdr = rdrM; Geometry expected = useRdr.read(expectedWKT); boolean isEqual = (expected.compareTo(g2, comp2) == 0); if (!isEqual) {System.out.println(g2);System.out.println(expected);} assertTrue(isEqual); } }
public WKBAttributeIO() { wkbr = new WKBReader(); }
public Geometry read(String geomStr) throws ParseException { String trimStr = geomStr.trim(); if (isHex(trimStr, MAX_CHARS_TO_CHECK)) return wkbReader.read(WKBReader.hexToBytes(trimStr)); return wktReader.read(trimStr); } }
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); } }
public WKBAttributeIO(GeometryFactory gf) { wkbr = new WKBReader(gf); }
private List read(BufferedReader bufferedReader) throws IOException, ParseException { List geoms = new ArrayList(); while (! isAtEndOfFile(bufferedReader) && ! isAtLimit(geoms)) { String line = bufferedReader.readLine().trim(); if (line.length() == 0) continue; Geometry g = wkbReader.read(WKBReader.hexToBytes(line)); if (count >= offset) geoms.add(g); count++; } return geoms; }
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); } }
/** * 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); } }
static final WKBReader wkbreader() { return new WKBReader(gfactory); }
void runGeometry(Geometry g, int dimension, int byteOrder, boolean toHex, int srid) throws IOException, ParseException { boolean includeSRID = false; if (srid >= 0) { includeSRID = true; g.setSRID(srid); } WKBWriter wkbWriter = new WKBWriter(dimension, byteOrder, includeSRID); byte[] wkb = wkbWriter.write(g); String wkbHex = null; if (toHex) wkbHex = WKBWriter.toHex(wkb); if (toHex) wkb = WKBReader.hexToBytes(wkbHex); Geometry g2 = wkbReader.read(wkb); CoordinateSequenceComparator comp = (dimension == 2) ? comp2 : comp3; boolean isEqual = (g.compareTo(g2, comp) == 0); assertTrue(isEqual); if (includeSRID) { boolean isSRIDEqual = g.getSRID() == g2.getSRID(); assertTrue(isSRIDEqual); } } }
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 static Geometry gFromWKB( byte[] wkb, WKBReader wkbreader ) { try { return wkbreader.read( wkb ); } catch (ParseException e) { throw new RuntimeException( e ); } }
static final WKBReader wkbreader() { return new WKBReader(gfactory); }
@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 static Geometry gFromWKB( byte[] wkb, WKBReader wkbreader ) { try { return wkbreader.read( wkb ); } catch (ParseException e) { throw new RuntimeException( e ); } }
public MultiFormatReader(GeometryFactory geomFactory) { this.geomFactory = geomFactory; wktReader = new WKTReader(geomFactory); wkbReader = new WKBReader(geomFactory); }
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); } }
/** * Reads a single {@link Geometry} in WKB format from a byte array. * * @param bytes the byte array to read from * @return the geometry read * @throws ParseException if the WKB is ill-formed */ public Geometry read(byte[] bytes) throws ParseException { // possibly reuse the ByteArrayInStream? // don't throw IOExceptions, since we are not doing any I/O try { return read(new ByteArrayInStream(bytes)); } catch (IOException ex) { throw new RuntimeException("Unexpected IOException caught: " + ex.getMessage()); } }