Search in sources :

Example 1 with NamedCoordinateReferenceSystemConverter

use of org.mongodb.morphia.geo.NamedCoordinateReferenceSystemConverter in project morphia by mongodb.

the class StandardGeoFieldCriteria method addTo.

@Override
public void addTo(final DBObject obj) {
    BasicDBObjectBuilder query;
    FilterOperator operator = getOperator();
    switch(operator) {
        case NEAR:
            if (maxDistanceMeters != null) {
                geometryAsDBObject.put("$maxDistance", maxDistanceMeters);
            }
            query = BasicDBObjectBuilder.start(NEAR.val(), geometryAsDBObject);
            break;
        case GEO_WITHIN:
        case INTERSECTS:
            query = BasicDBObjectBuilder.start(operator.val(), geometryAsDBObject);
            if (crs != null) {
                ((DBObject) geometryAsDBObject.get("$geometry")).put("crs", new NamedCoordinateReferenceSystemConverter().encode(crs));
            }
            break;
        default:
            throw new UnsupportedOperationException(String.format("Operator %s not supported for geo-query", operator.val()));
    }
    obj.put(getField(), query.get());
}
Also used : NamedCoordinateReferenceSystemConverter(org.mongodb.morphia.geo.NamedCoordinateReferenceSystemConverter) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject)

Aggregations

BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 DBObject (com.mongodb.DBObject)1 NamedCoordinateReferenceSystemConverter (org.mongodb.morphia.geo.NamedCoordinateReferenceSystemConverter)1