Search in sources :

Example 16 with Geometry

use of com.microsoft.sqlserver.jdbc.Geometry in project mssql-jdbc by Microsoft.

the class SQLServerSpatialDatatypeTest method testSTAsText.

@Test
public void testSTAsText() throws SQLException {
    beforeEachSetup();
    String geoWKT = "GEOMETRYCOLLECTION(POINT(300 20 1), GEOMETRYCOLLECTION EMPTY, GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)), POLYGON((0 0 2, 1 10 3, 1 0 4, 0 0 2)))";
    String geoWKTSS = "GEOMETRYCOLLECTION(POINT(300 20), GEOMETRYCOLLECTION EMPTY, GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)), POLYGON((0 0, 1 10, 1 0, 0 0)))";
    Geometry geomWKT = Geometry.STGeomFromText(geoWKT, 0);
    Geography geogWKT = Geography.STGeomFromText(geoWKT, 4326);
    pstmt = (SQLServerPreparedStatement) con.prepareStatement("insert into " + geomTableName + " values (?)");
    pstmt.setGeometry(1, geomWKT);
    pstmt.execute();
    rs = (SQLServerResultSet) stmt.executeQuery("select c1 from " + geomTableName);
    rs.next();
    assertEquals(rs.getGeometry(1).STAsText(), geoWKTSS);
    pstmt = (SQLServerPreparedStatement) con.prepareStatement("insert into " + geogTableName + " values (?)");
    pstmt.setGeography(1, geogWKT);
    pstmt.execute();
    rs = (SQLServerResultSet) stmt.executeQuery("select c1 from " + geogTableName);
    rs.next();
    assertEquals(rs.getGeography(1).STAsText(), geoWKTSS);
}
Also used : Geometry(com.microsoft.sqlserver.jdbc.Geometry) Geography(com.microsoft.sqlserver.jdbc.Geography) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 17 with Geometry

use of com.microsoft.sqlserver.jdbc.Geometry in project mssql-jdbc by Microsoft.

the class SQLServerSpatialDatatypeTest method testMultiPolygonWkb.

@Test
public void testMultiPolygonWkb() throws DecoderException {
    String geoWKT = "MULTIPOLYGON(((1 1, 1 2, 2 1, 1 1), (0 0, 0 3, 3 3, 3 0, 0 0 7)), ((9 9, 9 10, 10 9, 9 9)))";
    byte[] geomWKB = Hex.decodeHex("0000000001010D000000000000000000F03F000000000000F03F000000000000F03F00000000000000400000000000000040000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000000000000000022400000000000002240000000000000224000000000000024400000000000002440000000000000224000000000000022400000000000002240000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0000000000001C40000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0300000002000000000004000000020900000003000000FFFFFFFF0000000006000000000000000003000000000200000003".toCharArray());
    byte[] geogWKB = Hex.decodeHex("E610000002010D000000000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F000000000000000000000000000000000000000000000840000000000000000000000000000008400000000000000840000000000000000000000000000008400000000000000000000000000000000000000000000022400000000000002240000000000000244000000000000022400000000000002240000000000000244000000000000022400000000000002240000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0000000000001C40000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0300000001000000000104000000010900000003000000FFFFFFFF0000000006000000000000000003000000000200000003".toCharArray());
    Geometry geomWKT = Geometry.deserialize(geomWKB);
    Geography geogWKT = Geography.deserialize(geogWKB);
    assertEquals(geomWKT.asTextZM(), geoWKT);
    assertEquals(geogWKT.asTextZM(), geoWKT);
}
Also used : Geometry(com.microsoft.sqlserver.jdbc.Geometry) Geography(com.microsoft.sqlserver.jdbc.Geography) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 18 with Geometry

use of com.microsoft.sqlserver.jdbc.Geometry in project mssql-jdbc by Microsoft.

the class SQLServerSpatialDatatypeTest method testLineStringWkb.

@Test
public void testLineStringWkb() throws DecoderException {
    String geoWKT = "LINESTRING(1 0, 0 1, -1 0)";
    byte[] geomWKB = Hex.decodeHex("00000000010403000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F0BF000000000000000001000000010000000001000000FFFFFFFF0000000002".toCharArray());
    byte[] geogWKB = Hex.decodeHex("E61000000104030000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F0BF01000000010000000001000000FFFFFFFF0000000002".toCharArray());
    Geometry geomWKT = Geometry.deserialize(geomWKB);
    Geography geogWKT = Geography.deserialize(geogWKB);
    assertEquals(geomWKT.asTextZM(), geoWKT);
    assertEquals(geogWKT.asTextZM(), geoWKT);
}
Also used : Geometry(com.microsoft.sqlserver.jdbc.Geometry) Geography(com.microsoft.sqlserver.jdbc.Geography) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

Geometry (com.microsoft.sqlserver.jdbc.Geometry)18 Geography (com.microsoft.sqlserver.jdbc.Geography)17 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)16 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)2 SQLServerResultSet (com.microsoft.sqlserver.jdbc.SQLServerResultSet)1 ParameterMetaData (java.sql.ParameterMetaData)1 ResultSetMetaData (java.sql.ResultSetMetaData)1