Search in sources :

Example 11 with Geometry

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

the class SQLServerSpatialDatatypeTest method testPolygonWkb.

@Test
public void testPolygonWkb() throws DecoderException {
    String geoWKT = "POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))";
    byte[] geomWKB = Hex.decodeHex("000000000104090000000000000000000000000000000000000000000000000000000000000000000840000000000000084000000000000008400000000000000840000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000400000000000000040000000000000F03F000000000000F03F000000000000F03F020000000200000000000500000001000000FFFFFFFF0000000003".toCharArray());
    byte[] geogWKB = Hex.decodeHex("E61000000200090000000000000000000000000000000000000000000000000008400000000000000000000000000000084000000000000008400000000000000000000000000000084000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F020000000100000000010500000001000000FFFFFFFF0000000003".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 12 with Geometry

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

the class SQLServerSpatialDatatypeTest method testAllTypes.

@Test
public void testAllTypes() throws SQLException {
    if (isDenaliOrLater) {
        beforeEachSetup();
        String geoWKTPoint = "POINT(30 12.12312312 5 6)";
        String geoWKTLineString = "LINESTRING(1 1, 2 4 3, 3 9 123 332)";
        String geoWKTCircularString = "CIRCULARSTRING(1 1, 2 4, 3 9)";
        String geoWKTCompoundCurve = "COMPOUNDCURVE((1 1, 1 3), (1 3, 3 3), (3 3, 3 1), (3 1, 1 1))";
        String geoWKTCurvePolygon = "CURVEPOLYGON(CIRCULARSTRING(2 4, 4 2, 6 4, 4 6, 2 4))";
        String geoWKTPolygon = "POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))";
        String geoWKTMultiPoint = "MULTIPOINT((2 3), (7 8 9.5))";
        String geoWKTMultiLineString = "MULTILINESTRING((0 2, 1 1), (1 0, 1 1))";
        String geoWKTMultiPolygon = "MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1)), ((9 9, 9 10, 10 9, 9 9)))";
        String geoWKTGeometryCollection = "GEOMETRYCOLLECTION(POLYGON((0 0 2, 1 10 3, 1 0 4, 0 0 2)), POINT(3 3 1 2.5), LINESTRING(1 0, 0 1, -1 0), GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(1 2 3 4))), GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY), CURVEPOLYGON((0 0, 0 0, 0 0, 0 0), CIRCULARSTRING(1 3, 3 5, 4 7, 7 3, 1 3), COMPOUNDCURVE((0 -23.43778, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 -23.43778, 0 -23.43778)), COMPOUNDCURVE((0 -23.43778, 7 7, 0 23.43778), CIRCULARSTRING(0 23.43778, 8 8, 8 8, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778))))";
        List<String> geoWKTList = new ArrayList<String>();
        geoWKTList.add(geoWKTPoint);
        geoWKTList.add(geoWKTLineString);
        geoWKTList.add(geoWKTCircularString);
        geoWKTList.add(geoWKTCompoundCurve);
        geoWKTList.add(geoWKTCurvePolygon);
        geoWKTList.add(geoWKTPolygon);
        geoWKTList.add(geoWKTMultiPoint);
        geoWKTList.add(geoWKTMultiLineString);
        geoWKTList.add(geoWKTMultiPolygon);
        geoWKTList.add(geoWKTGeometryCollection);
        Geometry geomWKT;
        Geography geogWKT;
        // Geometry
        pstmt = (SQLServerPreparedStatement) con.prepareStatement("insert into " + geomTableName + " values (?)");
        geomWKT = Geometry.STGeomFromText(geoWKTPoint, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTLineString, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTCircularString, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTCompoundCurve, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTCurvePolygon, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTPolygon, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTMultiPoint, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTMultiLineString, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTMultiPolygon, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTGeometryCollection, 0);
        pstmt.setGeometry(1, geomWKT);
        pstmt.executeUpdate();
        rs = (SQLServerResultSet) stmt.executeQuery("select c1 from " + geomTableName);
        for (int i = 0; i < geoWKTList.size(); i++) {
            rs.next();
            assertEquals(rs.getGeometry(1).asTextZM(), geoWKTList.get(i));
        }
        // Geography
        pstmt = (SQLServerPreparedStatement) con.prepareStatement("insert into " + geogTableName + " values (?)");
        geogWKT = Geography.STGeomFromText(geoWKTPoint, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTLineString, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTCircularString, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTCompoundCurve, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTCurvePolygon, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTPolygon, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTMultiPoint, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTMultiLineString, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTMultiPolygon, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        geogWKT = Geography.STGeomFromText(geoWKTGeometryCollection, 4326);
        pstmt.setGeography(1, geogWKT);
        pstmt.executeUpdate();
        rs = (SQLServerResultSet) stmt.executeQuery("select c1 from " + geogTableName);
        for (int i = 0; i < geoWKTList.size(); i++) {
            rs.next();
            assertEquals(rs.getGeography(1).asTextZM(), geoWKTList.get(i));
        }
    }
}
Also used : Geometry(com.microsoft.sqlserver.jdbc.Geometry) Geography(com.microsoft.sqlserver.jdbc.Geography) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 13 with Geometry

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

the class SQLServerSpatialDatatypeTest method testPointWkb.

@Test
public void testPointWkb() throws DecoderException {
    String geoWKT = "POINT(3 40 5 6)";
    byte[] geomWKB = Hex.decodeHex("00000000010F0000000000000840000000000000444000000000000014400000000000001840".toCharArray());
    byte[] geogWKB = Hex.decodeHex("E6100000010F0000000000004440000000000000084000000000000014400000000000001840".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 14 with Geometry

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

the class SQLServerSpatialDatatypeTest method testCurvePolygonWkb.

@Test
public void testCurvePolygonWkb() throws DecoderException {
    String geoWKT = "CURVEPOLYGON((0 0, 0 0, 0 0, 0 0), CIRCULARSTRING(1 3, 3 5, 4 7, 7 3, 1 3), COMPOUNDCURVE((0 -23.43778, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 -23.43778, 0 -23.43778)), COMPOUNDCURVE((0 -23.43778, 7 7, 0 23.43778), CIRCULARSTRING(0 23.43778, 8 8, 8 8, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778)))";
    byte[] geomWKB = Hex.decodeHex("0A00000002001700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000008400000000000000840000000000000144000000000000010400000000000001C400000000000001C400000000000000840000000000000F03F00000000000008400000000000000000C7D79E59127037C00000000000000000C7D79E591270374000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C00000000000000000C7D79E59127037C00000000000001C400000000000001C400000000000000000C7D79E5912703740000000000000204000000000000020400000000000002040000000000000204000000000008046C0C7D79E591270374000000000008056C0C7D79E591270374000000000008056C0C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C004000000010000000002040000000309000000030D00000001000000FFFFFFFF000000000A080000000203020003010203".toCharArray());
    byte[] geogWKB = Hex.decodeHex("E6100000020017000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000F03F000000000000144000000000000008400000000000001C40000000000000104000000000000008400000000000001C400000000000000840000000000000F03FC7D79E59127037C00000000000000000C7D79E59127037400000000000000000C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C000000000000000000000000000001C400000000000001C40C7D79E591270374000000000000000000000000000002040000000000000204000000000000020400000000000002040C7D79E591270374000000000008046C0C7D79E591270374000000000008056C0C7D79E59127037C000000000008056C0C7D79E59127037C000000000008046C0C7D79E59127037C0000000000000000004000000010000000002040000000309000000030D00000001000000FFFFFFFF000000000A080000000203020003010203".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 15 with Geometry

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

the class SQLServerSpatialDatatypeTest method testSTAsBinary.

@Test
public void testSTAsBinary() throws SQLException {
    beforeEachSetup();
    String geoWKT = "POINT(3 40 5 6)";
    String geoWKT2 = "POINT(3 40)";
    Geometry geomWKT = Geometry.STGeomFromText(geoWKT, 0);
    Geography geogWKT = Geography.STGeomFromText(geoWKT, 4326);
    byte[] geomWKB = geomWKT.STAsBinary();
    byte[] geogWKB = geogWKT.STAsBinary();
    Geometry geomWKT2 = Geometry.STGeomFromText(geoWKT2, 0);
    Geography geogWKT2 = Geography.STGeomFromText(geoWKT2, 4326);
    byte[] geomWKB2 = geomWKT2.STAsBinary();
    byte[] geogWKB2 = geogWKT2.STAsBinary();
    assertEquals(geomWKB, geomWKB2);
    assertEquals(geogWKB, geogWKB2);
}
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