private static final BinaryWriter bw = new BinaryWriter();
/** The actual test method */
public static void test(String WKT, Connection[] conns, String flags) throws SQLException {
System.out.println("Original: " + WKT);
Geometry geom = PGgeometry.geomFromString(WKT);
String parsed = geom.toString();
System.out.println("Parsed: " + parsed);
Geometry regeom = PGgeometry.geomFromString(parsed);
String reparsed = regeom.toString();
System.out.println("Re-Parsed: " + reparsed);
if (!geom.equals(regeom)) {
System.out.println("--- Geometries are not equal!");
failcount++;
} else if (!reparsed.equals(parsed)) {
System.out.println("--- Text Reps are not equal!");
failcount++;
} else {
System.out.println("Equals: yes");
}
String hexNWKT = bw.writeHexed(regeom, ValueSetter.NDR.NUMBER);
System.out.println("NDRHex: " + hexNWKT);
regeom = PGgeometry.geomFromString(hexNWKT);
System.out.println("ReNDRHex: " + regeom.toString());
if (!geom.equals(regeom)) {
System.out.println("--- Geometries are not equal!");
failcount++;
} else {
System.out.println("Equals: yes");
}
String hexXWKT = bw.writeHexed(regeom, ValueSetter.XDR.NUMBER);
System.out.println("XDRHex: " + hexXWKT);
regeom = PGgeometry.geomFromString(hexXWKT);
System.out.println("ReXDRHex: " + regeom.toString());
if (!geom.equals(regeom)) {
System.out.println("--- Geometries are not equal!");
failcount++;
} else {
System.out.println("Equals: yes");
}
byte[] NWKT = bw.writeBinary(regeom, ValueSetter.NDR.NUMBER);
regeom = bp.parse(NWKT);
System.out.println("NDR: " + regeom.toString());
if (!geom.equals(regeom)) {
System.out.println("--- Geometries are not equal!");
failcount++;
} else {
System.out.println("Equals: yes");
}
byte[] XWKT = bw.writeBinary(regeom, ValueSetter.XDR.NUMBER);
regeom = bp.parse(XWKT);
System.out.println("XDR: " + regeom.toString());
if (!geom.equals(regeom)) {
System.out.println("--- Geometries are not equal!");
failcount++;
} else {
System.out.println("Equals: yes");
}
for (int i = 0; i < conns.length; i++) {
Connection connection = conns[i];
Statement statement = connection.createStatement();
int serverPostgisMajor = TestAutoregister.getPostgisMajor(statement);
if ((flags == ONLY10) && serverPostgisMajor < 1) {
System.out.println("PostGIS server too old, skipping test on connection " + i
+ ": " + connection.getCatalog());
} else {
System.out.println("Testing on connection " + i + ": " + connection.getCatalog());
try {
Geometry sqlGeom = viaSQL(WKT, statement);
System.out.println("SQLin : " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after SQL are not equal!");
if (flags == EQUAL10 && serverPostgisMajor < 1) {
System.out.println("--- This is expected with PostGIS "
+ serverPostgisMajor + ".X");
} else {
failcount++;
}
} else {
System.out.println("Eq SQL in: yes");
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
try {
Geometry sqlreGeom = viaSQL(parsed, statement);
System.out.println("SQLout : " + sqlreGeom.toString());
if (!geom.equals(sqlreGeom)) {
System.out.println("--- reparsed Geometries after SQL are not equal!");
if (flags == EQUAL10 && serverPostgisMajor < 1) {
System.out.println("--- This is expected with PostGIS "
+ serverPostgisMajor + ".X");
} else {
failcount++;
}
} else {
System.out.println("Eq SQLout: yes");
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
try {
Geometry sqlreGeom = viaPrepSQL(geom, connection);
System.out.println("Prepared: " + sqlreGeom.toString());
if (!geom.equals(sqlreGeom)) {
System.out.println("--- reparsed Geometries after prepared StatementSQL are not equal!");
if (flags == EQUAL10 && serverPostgisMajor < 1) {
System.out.println("--- This is expected with PostGIS "
+ serverPostgisMajor + ".X");
} else {
failcount++;
}
} else {
System.out.println("Eq Prep: yes");
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
// asEWKT() function is not present on PostGIS 0.X, and the test
// is pointless as 0.X uses EWKT as canonical rep so the same
// functionality was already tested above.
try {
if (serverPostgisMajor >= 1) {
Geometry sqlGeom = ewktViaSQL(WKT, statement);
System.out.println("asEWKT : " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after EWKT SQL are not equal!");
failcount++;
} else {
System.out.println("equal : yes");
}
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
// asEWKB() function is not present on PostGIS 0.X.
try {
if (serverPostgisMajor >= 1) {
Geometry sqlGeom = ewkbViaSQL(WKT, statement);
System.out.println("asEWKB : " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after EWKB SQL are not equal!");
failcount++;
} else {
System.out.println("equal : yes");
}
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
// HexEWKB parsing is not present on PostGIS 0.X.
try {
if (serverPostgisMajor >= 1) {
Geometry sqlGeom = viaSQL(hexNWKT, statement);
System.out.println("hexNWKT: " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after EWKB SQL are not equal!");
failcount++;
} else {
System.out.println("equal : yes");
}
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
try {
if (serverPostgisMajor >= 1) {
Geometry sqlGeom = viaSQL(hexXWKT, statement);
System.out.println("hexXWKT: " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after EWKB SQL are not equal!");
failcount++;
} else {
System.out.println("equal : yes");
}
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
// Canonical binary input is not present before 1.0
try {
if (serverPostgisMajor >= 1) {
Geometry sqlGeom = binaryViaSQL(NWKT, connection);
System.out.println("NWKT: " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after EWKB SQL are not equal!");
failcount++;
} else {
System.out.println("equal : yes");
}
}
} catch (SQLException e) {
System.out.println("--- Server side error: " + e.toString());
failcount++;
}
try {
if (serverPostgisMajor >= 1) {
Geometry sqlGeom = binaryViaSQL(XWKT, connection);
System.out.println("XWKT: " + sqlGeom.toString());
if (!geom.equals(sqlGeom)) {
System.out.println("--- Geometries after EWKB SQL are not equal!");
failcount++;
} else {
System.out.println("equal : yes");