Search in sources :

Example 1 with WKBWriter

use of com.revolsys.geometry.wkb.WKBWriter in project com.revolsys.open by revolsys.

the class WKBTest method runGeometry.

void runGeometry(final Geometry g, final int dimension, final int byteOrder, final boolean toHex, final int srid) throws IOException, ParseException {
    boolean includeSRID = false;
    if (srid >= 0) {
        includeSRID = true;
    // g.setSRID(srid);
    }
    final 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);
    }
    final Geometry g2 = this.wkbReader.read(wkb);
    final boolean isEqual = g.equals(2, g2);
    assertTrue(isEqual);
    if (includeSRID) {
        final boolean isSRIDEqual = g.getCoordinateSystemId() == g2.getCoordinateSystemId();
        assertTrue(isSRIDEqual);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) WKBWriter(com.revolsys.geometry.wkb.WKBWriter)

Example 2 with WKBWriter

use of com.revolsys.geometry.wkb.WKBWriter in project com.revolsys.open by revolsys.

the class WKBWriterTest method testSRID.

public void testSRID() throws Exception {
    final GeometryFactory gf = GeometryFactory.DEFAULT_3D;
    final Point p1 = gf.point(1.0, 2.0);
    // p1.setSRID(1234);
    // first write out without srid set
    WKBWriter w = new WKBWriter();
    byte[] wkb = w.write(p1);
    // check the 3rd bit of the second byte, should be unset
    byte b = (byte) (wkb[1] & 0x20);
    assertEquals(0, b);
    // read geometry back in
    WKBReader r = new WKBReader(gf);
    Point p2 = (Point) r.read(wkb);
    assertTrue(p1.equals(2, p2));
    assertEquals(0, p2.getCoordinateSystemId());
    // not write out with srid set
    w = new WKBWriter(2, true);
    wkb = w.write(p1);
    // check the 3rd bit of the second byte, should be set
    b = (byte) (wkb[1] & 0x20);
    assertEquals(0x20, b);
    final int srid = (wkb[5] & 0xff) << 24 | (wkb[6] & 0xff) << 16 | (wkb[7] & 0xff) << 8 | wkb[8] & 0xff;
    assertEquals(1234, srid);
    r = new WKBReader(gf);
    p2 = (Point) r.read(wkb);
    // read the geometry back in
    assertTrue(p1.equals(2, p2));
    assertEquals(1234, p2.getCoordinateSystemId());
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) WKBWriter(com.revolsys.geometry.wkb.WKBWriter) Point(com.revolsys.geometry.model.Point) WKBReader(com.revolsys.geometry.wkb.WKBReader) Point(com.revolsys.geometry.model.Point)

Aggregations

WKBWriter (com.revolsys.geometry.wkb.WKBWriter)2 Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 WKBReader (com.revolsys.geometry.wkb.WKBReader)1