package com.revolsys.geometry.test.old.io;
import com.revolsys.geometry.model.Geometry;
import com.revolsys.geometry.model.GeometryFactory;
import com.revolsys.geometry.wkb.ParseException;
import com.revolsys.geometry.wkb.WKBReader;
import junit.framework.TestCase;
import junit.textui.TestRunner;
/**
* Tests for reading WKB.
*
* @author Martin Davis
*
*/
public class WKBReaderTest extends TestCase {
public static void main(final String args[]) {
TestRunner.run(WKBReaderTest.class);
}
private final GeometryFactory geometryFactory = GeometryFactory.DEFAULT_3D;
public WKBReaderTest(final String name) {
super(name);
}
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);
}
public void testShortPolygons() throws ParseException {
// one point
checkWKBGeometry("0000000003000000010000000140590000000000004069000000000000",
"POLYGON ((100 200, 100 200, 100 200, 100 200))");
// two point
checkWKBGeometry(
"000000000300000001000000024059000000000000406900000000000040590000000000004069000000000000",
"POLYGON ((100 200, 100 200, 100 200, 100 200))");
}
public void testSinglePointLineString() throws ParseException {
checkWKBGeometry("00000000020000000140590000000000004069000000000000",
"LINESTRING (100 200, 100 200)");
}
/**
* After removing the 39 bytes of MBR info at the front, and the
* end-of-geometry byte, * Spatialite native BLOB is very similar
* to WKB, except instead of a endian marker at the start of each
* geometry in a multi-geometry, it has a start marker of 0x69.
* Endianness is determined by the endian value of the multigeometry.
*
* @throws ParseException
*/
public void testSpatialiteMultiGeometry() throws ParseException {
// multipolygon
checkWKBGeometry(
"01060000000200000069030000000100000004000000000000000000444000000000000044400000000000003440000000000080464000000000008046400000000000003E4000000000000044400000000000004440690300000001000000040000000000000000003E40000000000000344000000000000034400000000000002E40000000000000344000000000000039400000000000003E400000000000003440",
"MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((30 20, 20 15, 20 25, 30 20)))'");
// multipoint
checkWKBGeometry(
"0104000000020000006901000000000000000000F03F000000000000F03F690100000000000000000000400000000000000040",
"MULTIPOINT(1 1,2 2)'");
// multiline
checkWKBGeometry(
"010500000002000000690200000003000000000000000000244000000000000024400000000000003440000000000000344000000000000024400000000000004440690200000004000000000000000000444000000000000044400000000000003E400000000000003E40000000000000444000000000000034400000000000003E400000000000002440",
"MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))");
// geometrycollection
checkWKBGeometry(
"010700000002000000690100000000000000000010400000000000001840690200000002000000000000000000104000000000000018400000000000001C400000000000002440",
"GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))");
}
/**
* Not yet implemented satisfactorily.
*
* @throws ParseException
*/
public void XXtestIllFormedWKB() throws ParseException {
// WKB is missing LinearRing entry
checkWKBGeometry("00000000030000000140590000000000004069000000000000",
"POLYGON ((100 200, 100 200, 100 200, 100 200)");
}
}