Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL queries with spatial disjoint filter #227

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@
import org.citydb.core.query.builder.QueryBuildException;
import org.citydb.core.query.filter.selection.expression.ExpressionName;
import org.citydb.core.query.filter.selection.expression.ValueReference;
import org.citydb.core.query.filter.selection.operator.spatial.AbstractSpatialOperator;
import org.citydb.core.query.filter.selection.operator.spatial.BinarySpatialOperator;
import org.citydb.core.query.filter.selection.operator.spatial.Distance;
import org.citydb.core.query.filter.selection.operator.spatial.DistanceOperator;
import org.citydb.core.query.filter.selection.operator.spatial.DistanceUnit;
import org.citydb.core.query.filter.selection.operator.spatial.SpatialOperatorName;
import org.citydb.core.query.filter.selection.operator.spatial.*;
import org.citydb.sqlbuilder.schema.Column;
import org.citydb.sqlbuilder.schema.Table;
import org.citydb.sqlbuilder.select.PredicateToken;
Expand Down Expand Up @@ -139,19 +134,25 @@ private void buildBinaryOperator(BinarySpatialOperator operator, SQLQueryContext
PredicateToken predicate = databaseAdapter.getSQLAdapter().getBinarySpatialPredicate(operator.getOperatorName(), queryContext.getTargetColumn(), spatialDescription, negate);
queryContext.addPredicate(predicate);
} else {
if (operator.getOperatorName() == SpatialOperatorName.CONTAINS || operator.getOperatorName() == SpatialOperatorName.EQUALS)
throw new QueryBuildException("The spatial " + operator.getOperatorName() + " operator is not supported for the geometry property '" + valueReference.getSchemaPath().getLastNode() + "'.");
SpatialOperatorName operatorName = operator.getOperatorName();
if (operatorName == SpatialOperatorName.CONTAINS || operatorName == SpatialOperatorName.EQUALS)
throw new QueryBuildException("The spatial " + operatorName + " operator is not supported for the geometry property '" + valueReference.getSchemaPath().getLastNode() + "'.");

if (operatorName == SpatialOperatorName.DISJOINT) {
operatorName = SpatialOperatorName.INTERSECTS;
negate = !negate;
}

GeometryObject bbox = spatialDescription.toEnvelope();
boolean all = operator.getOperatorName() == SpatialOperatorName.DISJOINT || operator.getOperatorName() == SpatialOperatorName.WITHIN;
boolean all = operatorName == SpatialOperatorName.WITHIN;
Table surfaceGeometry = new Table(MappingConstants.SURFACE_GEOMETRY, schemaName, schemaPathBuilder.getAliasGenerator());
Table cityObject = getCityObjectTable(query, queryContext, useLeftJoins);

Select inner = new Select()
.addProjection(surfaceGeometry.getColumn(MappingConstants.ID))
.addSelection(ComparisonFactory.equalTo(surfaceGeometry.getColumn(MappingConstants.ROOT_ID), targetColumn))
.addSelection(ComparisonFactory.isNotNull(surfaceGeometry.getColumn(MappingConstants.GEOMETRY)))
.addSelection(databaseAdapter.getSQLAdapter().getBinarySpatialPredicate(operator.getOperatorName(), surfaceGeometry.getColumn(MappingConstants.GEOMETRY), spatialDescription, all));
.addSelection(databaseAdapter.getSQLAdapter().getBinarySpatialPredicate(operatorName, surfaceGeometry.getColumn(MappingConstants.GEOMETRY), spatialDescription, all));

PredicateToken spatialPredicate = LogicalOperationFactory.AND(
databaseAdapter.getSQLAdapter().getBinarySpatialPredicate(SpatialOperatorName.BBOX, cityObject.getColumn(MappingConstants.ENVELOPE), bbox, false),
Expand Down
Loading