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);
}
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();
}
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();
}
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;
}
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);
}
Aggregations