use of com.revolsys.record.query.Value in project com.revolsys.open by revolsys.
the class F method dWithin.
public static WithinDistance dWithin(final String name, final Geometry geometry, double distance) {
if (distance < 0) {
distance = 0;
}
final Column column = new Column(name);
final Value geometryValue = new Value(geometry);
final Value distanceValue = new Value(distance);
return new WithinDistance(column, geometryValue, distanceValue);
}
use of com.revolsys.record.query.Value in project com.revolsys.open by revolsys.
the class F method dWithin.
public static WithinDistance dWithin(final FieldDefinition fieldDefinition, final Geometry geometry, final double distance) {
final Column column = new Column(fieldDefinition);
final Value geometryValue = new Value(fieldDefinition, geometry);
final Value distanceValue = new Value(distance);
return new WithinDistance(column, geometryValue, distanceValue);
}
use of com.revolsys.record.query.Value in project com.revolsys.open by revolsys.
the class OracleRecordStore method appendWithinDistance.
private void appendWithinDistance(final Query query, final StringBuilder sql, final WithinDistance withinDistance) {
final FieldDefinition geometryField = query.getGeometryField();
if (geometryField instanceof OracleSdoGeometryJdbcFieldDefinition) {
sql.append("MDSYS.SDO_WITHIN_DISTANCE(");
final QueryValue geometry1Value = withinDistance.getGeometry1Value();
if (geometry1Value == null) {
sql.append("NULL");
} else {
geometry1Value.appendSql(query, this, sql);
}
sql.append(", ");
final QueryValue geometry2Value = withinDistance.getGeometry2Value();
if (geometry2Value == null) {
sql.append("NULL");
} else {
geometry2Value.appendSql(query, this, sql);
}
sql.append(",'distance = ' || ");
final QueryValue distanceValue = withinDistance.getDistanceValue();
if (distanceValue == null) {
sql.append("0");
} else {
distanceValue.appendSql(query, this, sql);
}
sql.append(") = 'TRUE'");
} else if (geometryField instanceof ArcSdeStGeometryFieldDefinition) {
final Column column = (Column) withinDistance.getGeometry1Value();
final GeometryFactory geometryFactory = column.getFieldDefinition().getRecordDefinition().getGeometryFactory();
final Value geometry2Value = (Value) withinDistance.getGeometry2Value();
final Value distanceValue = (Value) withinDistance.getDistanceValue();
final Number distance = (Number) distanceValue.getValue();
final Object geometryObject = geometry2Value.getValue();
BoundingBox boundingBox;
if (geometryObject instanceof BoundingBox) {
boundingBox = (BoundingBox) geometryObject;
} else if (geometryObject instanceof Geometry) {
final Geometry geometry = (Geometry) geometryObject;
boundingBox = geometry.getBoundingBox();
} else {
boundingBox = geometryFactory.newBoundingBoxEmpty();
}
boundingBox = boundingBox.expand(distance.doubleValue());
boundingBox = boundingBox.convert(geometryFactory);
sql.append("(SDE.ST_ENVINTERSECTS(");
column.appendSql(query, this, sql);
sql.append(",");
sql.append(boundingBox.getMinX());
sql.append(",");
sql.append(boundingBox.getMinY());
sql.append(",");
sql.append(boundingBox.getMaxX());
sql.append(",");
sql.append(boundingBox.getMaxY());
sql.append(") = 1 AND SDE.ST_DISTANCE(");
column.appendSql(query, this, sql);
sql.append(", ");
geometry2Value.appendSql(query, this, sql);
sql.append(") <= ");
distanceValue.appendSql(query, this, sql);
sql.append(")");
} else {
throw new IllegalArgumentException("Unknown geometry attribute type " + geometryField.getClass());
}
}
Aggregations