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);
}
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);
}
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());
}
Aggregations