Search in sources :

Example 1 with WKBReader

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

the class WKBReaderTest method checkWKBGeometry.

private void checkWKBGeometry(final String wkbHex, final String expectedWKT) throws ParseException {
    final WKBReader wkbReader = new WKBReader(this.geometryFactory);
    final byte[] wkb = WKBReader.hexToBytes(wkbHex);
    final Geometry g2 = wkbReader.read(wkb);
    final Geometry expected = this.geometryFactory.geometry(expectedWKT);
    final boolean isEqual = expected.equals(2, g2);
    assertTrue(isEqual);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) WKBReader(com.revolsys.geometry.wkb.WKBReader)

Example 2 with WKBReader

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

the class IOUtil method readGeometriesFromWKBHexString.

public static Geometry readGeometriesFromWKBHexString(final String wkb, final GeometryFactory geomFact) throws ParseException, IOException {
    final WKBReader reader = new WKBReader(geomFact);
    final WKBHexFileReader fileReader = new WKBHexFileReader(new StringReader(wkb), reader);
    final List geomList = fileReader.read();
    if (geomList.size() == 1) {
        return (Geometry) geomList.get(0);
    }
    return geomFact.geometryCollection(geomList);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) StringReader(java.io.StringReader) List(java.util.List) WKBHexFileReader(com.revolsys.geometry.wkb.WKBHexFileReader) WKBReader(com.revolsys.geometry.wkb.WKBReader)

Example 3 with WKBReader

use of com.revolsys.geometry.wkb.WKBReader 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

WKBReader (com.revolsys.geometry.wkb.WKBReader)3 Geometry (com.revolsys.geometry.model.Geometry)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 WKBHexFileReader (com.revolsys.geometry.wkb.WKBHexFileReader)1 WKBWriter (com.revolsys.geometry.wkb.WKBWriter)1 StringReader (java.io.StringReader)1 List (java.util.List)1