Search in sources :

Example 6 with Geography

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

the class SQLServerSpatialDatatypeTest method testMixedAllTypes.

@Test
public void testMixedAllTypes() throws SQLException {
    if (isDenaliOrLater) {
        beforeEachSetupSpatialDatatype();
        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))))";
        String s = "some string";
        Double d = 31.34;
        int i2 = 5;
        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;
        pstmt = (SQLServerPreparedStatement) con.prepareStatement("insert into " + spatialDatatypeTableName + " values (?, ?, ?, ?, ?)");
        geomWKT = Geometry.STGeomFromText(geoWKTPoint, 0);
        geogWKT = Geography.STGeomFromText(geoWKTPoint, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTLineString, 0);
        geogWKT = Geography.STGeomFromText(geoWKTLineString, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTCircularString, 0);
        geogWKT = Geography.STGeomFromText(geoWKTCircularString, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTCompoundCurve, 0);
        geogWKT = Geography.STGeomFromText(geoWKTCompoundCurve, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTCurvePolygon, 0);
        geogWKT = Geography.STGeomFromText(geoWKTCurvePolygon, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTPolygon, 0);
        geogWKT = Geography.STGeomFromText(geoWKTPolygon, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTMultiPoint, 0);
        geogWKT = Geography.STGeomFromText(geoWKTMultiPoint, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTMultiLineString, 0);
        geogWKT = Geography.STGeomFromText(geoWKTMultiLineString, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTMultiPolygon, 0);
        geogWKT = Geography.STGeomFromText(geoWKTMultiPolygon, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        geomWKT = Geometry.STGeomFromText(geoWKTGeometryCollection, 0);
        geogWKT = Geography.STGeomFromText(geoWKTGeometryCollection, 4326);
        pstmt.setGeometry(1, geomWKT);
        pstmt.setGeography(2, geogWKT);
        pstmt.setString(3, s);
        pstmt.setDouble(4, d);
        pstmt.setInt(5, i2);
        pstmt.executeUpdate();
        rs = (SQLServerResultSet) stmt.executeQuery("select * from " + spatialDatatypeTableName);
        for (int i = 0; i < geoWKTList.size(); i++) {
            rs.next();
            assertEquals(rs.getGeometry(1).asTextZM(), geoWKTList.get(i));
            assertEquals(rs.getGeography(2).asTextZM(), geoWKTList.get(i));
            assertEquals(rs.getString(3), s);
            assertEquals((Double) rs.getDouble(4), d);
            assertEquals(rs.getInt(5), i2);
        }
    }
}
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 7 with Geography

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

the class SQLServerSpatialDatatypeTest method testWkt.

private void testWkt(String geoWKT, String geoWKTSS) throws SQLException {
    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).asTextZM(), 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).asTextZM(), geoWKTSS);
}
Also used : Geometry(com.microsoft.sqlserver.jdbc.Geometry) Geography(com.microsoft.sqlserver.jdbc.Geography)

Example 8 with Geography

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

the class SQLServerSpatialDatatypeTest method testMultiPointWkb.

@Test
public void testMultiPointWkb() throws DecoderException {
    String geoWKT = "MULTIPOINT((2 3), (7 8 9.5))";
    byte[] geomWKB = Hex.decodeHex("00000000010502000000000000000000004000000000000008400000000000001C400000000000002040000000000000F8FF0000000000002340020000000100000000010100000003000000FFFFFFFF0000000004000000000000000001000000000100000001".toCharArray());
    byte[] geogWKB = Hex.decodeHex("E61000000105020000000000000000000840000000000000004000000000000020400000000000001C40000000000000F8FF0000000000002340020000000100000000010100000003000000FFFFFFFF0000000004000000000000000001000000000100000001".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 9 with Geography

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

the class SQLServerSpatialDatatypeTest method testPoint.

@Test
public void testPoint() throws SQLException {
    beforeEachSetup();
    String geoWKT = "POINT(1 2)";
    Geometry geomWKT = Geometry.point(1, 2, 0);
    Geography geogWKT = Geography.point(1, 2, 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).asTextZM(), geoWKT);
    assertEquals(rs.getGeometry(1).getSrid(), 0);
    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).asTextZM(), geoWKT);
    assertEquals(rs.getGeography(1).getSrid(), 4326);
}
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 10 with Geography

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

the class SQLServerSpatialDatatypeTest method testFullGlobeWkb.

@Test
public void testFullGlobeWkb() throws DecoderException {
    String geoWKT = "FULLGLOBE";
    byte[] geogWKB = Hex.decodeHex("E61000000224000000000000000001000000FFFFFFFFFFFFFFFF0B".toCharArray());
    Geography geogWKT = Geography.deserialize(geogWKB);
    assertEquals(geogWKT.asTextZM(), geoWKT);
}
Also used : Geography(com.microsoft.sqlserver.jdbc.Geography) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

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