Search in sources :

Example 16 with Geography

use of com.microsoft.sqlserver.jdbc.Geography 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)

Example 17 with Geography

use of com.microsoft.sqlserver.jdbc.Geography 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 18 with Geography

use of com.microsoft.sqlserver.jdbc.Geography 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 19 with Geography

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

the class SQLServerSpatialDatatypeTest method testCheckGeogMetaData.

@Test
public void testCheckGeogMetaData() throws SQLException {
    beforeEachSetup();
    pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + geogTableName + " (c1) VALUES (?)");
    ParameterMetaData paramMetaData = pstmt.getParameterMetaData();
    Geography g = Geography.STGeomFromText("POINT (1 2 3 4)", 4326);
    pstmt.setGeography(1, g);
    pstmt.execute();
    int sqlType = paramMetaData.getParameterType(1);
    String sqlTypeName = paramMetaData.getParameterTypeName(1);
    assertEquals(sqlType, -158);
    assertEquals(sqlTypeName, "geography");
    SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + geogTableName);
    ResultSetMetaData rsmd = rs.getMetaData();
    assertEquals(rsmd.getColumnType(1), -158);
}
Also used : Geography(com.microsoft.sqlserver.jdbc.Geography) ResultSetMetaData(java.sql.ResultSetMetaData) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 20 with Geography

use of com.microsoft.sqlserver.jdbc.Geography 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

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