@Override public void write(int adminEntityId, Geometry geometry) throws IOException { if (!geometry.isValid()) { throw new IllegalStateException(adminEntityId + " has invalid geometry"); } dataOut.writeInt(adminEntityId); writer.write(geometry, new OutputStreamOutStream(dataOut)); numFeatures++; }
private Object toWkbBinary(Geometry value) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); WKBWriter writer = new WKBWriter(); try { writer.write(value, new OutputStreamOutStream(baos)); } catch (IOException e) { throw new RuntimeException("Failed to encode geometry as WKB", e); } return baos.toByteArray(); }
private byte[] toBinary(Geometry geometry) { WKBWriter writer = new WKBWriter(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { writer.write(fixUpGeometry(geometry), new OutputStreamOutStream(baos)); } catch (IOException e) { throw new RuntimeException(e); } return baos.toByteArray(); } }
private static byte[] toWKB( Geometry g ) { try { WKBWriter w = new WKBWriter(); //write the geometry ByteArrayOutputStream bytes = new ByteArrayOutputStream(); w.write( g , new OutputStreamOutStream( bytes ) ); //supplement it with the srid int srid = g.getSRID(); bytes.write( (byte)(srid >>> 24) ); bytes.write( (byte)(srid >> 16 & 0xff) ); bytes.write( (byte)(srid >> 8 & 0xff) ); bytes.write( (byte)(srid & 0xff) ); return bytes.toByteArray(); } catch (IOException e) { throw new RuntimeException( e ); } } //
public static void write( Geometry geom, OutputStream os ) throws IOException, ParseException { // com.vividsolutions.jts.io.WKBWriter is not thread safe //TODO: test for dimentionality here aswell? new com.vividsolutions.jts.io.WKBWriter().write( ( (AbstractDefaultGeometry) geom ).getJTSGeometry(), new OutputStreamOutStream( os ) ); } }
@Test(expected=ExpressionEvaluationException.class) public void testEwkbZCooridinate() throws Exception { WKBWriter writer = new WKBWriter(3, true); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint(new Coordinate(0, 0, 0)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(point, new OutputStreamOutStream(baos)); Expression ex1 = TestFunctionResolving.getExpression("ST_GeomFromBinary(X'"+new BinaryType(baos.toByteArray())+"', 8307)"); Evaluator.evaluate(ex1); }
@Test(expected=ExpressionEvaluationException.class) public void testEwkb() throws Exception { WKBWriter writer = new WKBWriter(3, true); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint(new Coordinate(0, 0, 0)); point.setSRID(100); ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(point, new OutputStreamOutStream(baos)); Expression ex1 = TestFunctionResolving.getExpression("ST_GeomFromBinary(X'"+new BinaryType(baos.toByteArray())+"', 8307)"); Evaluator.evaluate(ex1); }