From: Markus Schaber Date: Thu, 24 Feb 2005 11:20:17 +0000 (+0000) Subject: Additional regression tests for EWKT and EWKB on PostGIS 1.X X-Git-Tag: pgis_1_0_0RC4~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad2dd1474c10d0a30d4f63ec16ef8743cc65ee54;p=postgis Additional regression tests for EWKT and EWKB on PostGIS 1.X git-svn-id: http://svn.osgeo.org/postgis/trunk@1440 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/jdbc2/src/examples/TestParser.java b/jdbc2/src/examples/TestParser.java index a55f94f00..bd3707080 100644 --- a/jdbc2/src/examples/TestParser.java +++ b/jdbc2/src/examples/TestParser.java @@ -28,6 +28,7 @@ package examples; import org.postgis.Geometry; import org.postgis.PGgeometry; +import org.postgis.binary.BinaryParser; import org.postgresql.util.PGtokenizer; import java.sql.Connection; @@ -256,6 +257,30 @@ public class TestParser { 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. + 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("asEWKT in: yes"); + } + } + // asEWKB() function is not present on PostGIS 0.X. + 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("asEWKB in: yes"); + } + } } statement.close(); } @@ -269,6 +294,24 @@ public class TestParser { return ((PGgeometry) rs.getObject(1)).getGeometry(); } + /** Pass a geometry representation through the SQL server via EWKT */ + private static Geometry ewktViaSQL(String rep, Statement stat) throws SQLException { + ResultSet rs = stat.executeQuery("SELECT asEWKT(geometry_in('" + rep + "'))"); + rs.next(); + String resrep = rs.getString(1); + return PGgeometry.geomFromString(resrep); + } + + private static BinaryParser bp = new BinaryParser(); + + /** Pass a geometry representation through the SQL server via EWKB */ + private static Geometry ewkbViaSQL(String rep, Statement stat) throws SQLException { + ResultSet rs = stat.executeQuery("SELECT asEWKB(geometry_in('" + rep + "'))"); + rs.next(); + byte[] resrep = rs.getBytes(1); + return bp.parse(resrep); + } + /** * Connect to the databases *