Search in sources :

Example 11 with GeometryType

use of org.teiid.core.types.GeometryType in project teiid by teiid.

the class TestMySQLTranslator method testMysqlGeometryRead.

@Test
public void testMysqlGeometryRead() throws Exception {
    MySQLExecutionFactory msef = new MySQLExecutionFactory();
    msef.start();
    GeometryType gt = msef.toGeometryType(BlobType.createBlob(new byte[] { 01, 02, 00, 00, 01, 01, 00, 00, 00, 00, 00, 00, 00, 00, 00, (byte) 0xf0, (byte) 0x3f, 00, 00, 00, 00, 00, 00, (byte) 0xf0, 0x3f }));
    assertEquals(513, gt.getSrid());
    GeometryUtils.getGeometry(gt);
}
Also used : GeometryType(org.teiid.core.types.GeometryType) Test(org.junit.Test)

Example 12 with GeometryType

use of org.teiid.core.types.GeometryType in project teiid by teiid.

the class MongoDBSelectVisitor method buildGeoNearFunction.

private DBObject buildGeoNearFunction(Function function) throws TranslatorException {
    List<Expression> args = function.getParameters();
    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    append(args.get(paramIndex++));
    Object object = this.onGoingExpression.pop();
    if (object instanceof GeometryType) {
        convertGeometryToJson(builder, (GeometryType) object);
    } else {
        // $NON-NLS-1$
        builder.push("$geometry");
        // $NON-NLS-1$
        builder.add("type", SpatialType.Point.name());
        // walk the co-ordinates
        BasicDBList coordinates = new BasicDBList();
        coordinates.add(object);
        // $NON-NLS-1$
        builder.add("coordinates", coordinates);
    }
    // maxdistance
    append(args.get(paramIndex++));
    BasicDBObjectBuilder b = builder.pop();
    // $NON-NLS-1$
    b.add("$maxDistance", this.onGoingExpression.pop());
    if (this.executionFactory.getVersion().compareTo(MongoDBExecutionFactory.TWO_6) >= 0) {
        // mindistance
        append(args.get(paramIndex++));
        // $NON-NLS-1$
        b.add("$minDistance", this.onGoingExpression.pop());
    }
    return builder.get();
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BasicDBList(com.mongodb.BasicDBList) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 13 with GeometryType

use of org.teiid.core.types.GeometryType in project teiid by teiid.

the class MongoDBSelectVisitor method buildGeoFunction.

private DBObject buildGeoFunction(Function function) throws TranslatorException {
    List<Expression> args = function.getParameters();
    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    append(args.get(paramIndex++));
    Object object = this.onGoingExpression.pop();
    if (object instanceof GeometryType) {
        convertGeometryToJson(builder, (GeometryType) object);
    } else {
        // Type: Point, LineString, Polygon..
        SpatialType type = SpatialType.valueOf((String) object);
        append(args.get(paramIndex++));
        // $NON-NLS-1$
        builder.push("$geometry");
        // $NON-NLS-1$
        builder.add("type", type.name());
        // walk the co-ordinates
        BasicDBList coordinates = new BasicDBList();
        coordinates.add(this.onGoingExpression.pop());
        // $NON-NLS-1$
        builder.add("coordinates", coordinates);
    }
    return builder.get();
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BasicDBList(com.mongodb.BasicDBList) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 14 with GeometryType

use of org.teiid.core.types.GeometryType in project teiid by teiid.

the class GeometryUtils method geometryFromBlob.

// TODO: should allow an option to assume well formed
public static GeometryType geometryFromBlob(BlobType wkb, int srid) throws FunctionExecutionException {
    // return as geometry
    GeometryType gt = new GeometryType(wkb.getReference(), srid);
    // validate
    getGeometry(gt);
    return gt;
}
Also used : GeometryType(org.teiid.core.types.GeometryType)

Example 15 with GeometryType

use of org.teiid.core.types.GeometryType in project teiid by teiid.

the class TestGeometry method testRoundTrip.

@Test
public void testRoundTrip() throws Exception {
    Expression ex = TestFunctionResolving.getExpression("ST_GeomFromText('POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))')");
    GeometryType geom = (GeometryType) Evaluator.evaluate(ex);
    assertEquals(0, geom.getSrid());
    byte[] bytes = geom.getBytes(1, (int) geom.length());
    Expression ex1 = TestFunctionResolving.getExpression("ST_GeomFromBinary(X'" + new BinaryType(bytes) + "', 8307)");
    GeometryType geom1 = (GeometryType) Evaluator.evaluate(ex1);
    assertEquals(8307, geom1.getSrid());
    assertEquals(geom, geom1);
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BinaryType(org.teiid.core.types.BinaryType) Expression(org.teiid.query.sql.symbol.Expression) Test(org.junit.Test)

Aggregations

GeometryType (org.teiid.core.types.GeometryType)17 Test (org.junit.Test)8 Blob (java.sql.Blob)4 BinaryType (org.teiid.core.types.BinaryType)4 BasicDBList (com.mongodb.BasicDBList)3 BasicDBObject (com.mongodb.BasicDBObject)3 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 SQLException (java.sql.SQLException)3 BlobImpl (org.teiid.core.types.BlobImpl)3 ClobImpl (org.teiid.core.types.ClobImpl)3 ClobType (org.teiid.core.types.ClobType)3 InputStreamFactory (org.teiid.core.types.InputStreamFactory)3 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)2 DBObject (com.mongodb.DBObject)2 InputStream (java.io.InputStream)2 BigDecimal (java.math.BigDecimal)2 PreparedStatement (java.sql.PreparedStatement)2 GridFS (com.mongodb.gridfs.GridFS)1 GridFSInputFile (com.mongodb.gridfs.GridFSInputFile)1