Strabon

changeset 1039:516d8a0ae1db

Fixes bug #35. Changed the implementation of strdf:buffer. I adopted the definition
of geof:buffer(geom: ogc:geomLiteral, radius: xsd:double, units: xsd:anyURI): ogc:geomLiteral.
Now strdf:buffer can be called as follows:
strdf:buffer(geom, radius, <http://www.opengis.net/def/uom/OGC/1.0/metre>) or
strdf:buffer(geom, radius, <http://www.opengis.net/def/uom/OGC/1.0/degree>)
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Wed Apr 17 14:35:06 2013 +0300 (2013-04-17)
parents 6260271ba203
children 61bc2e9bf304
files generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoBuffer.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialConstructTriple.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialMetricTriple.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java
line diff
     1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoBuffer.java	Tue Apr 16 14:12:15 2013 +0300
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoBuffer.java	Wed Apr 17 14:35:06 2013 +0300
     1.3 @@ -9,17 +9,16 @@
     1.4  import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
     1.5  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
     1.6  
     1.7 -public class GeneralDBSqlGeoBuffer extends GeneralDBSqlSpatialConstructBinary{
     1.8 +public class GeneralDBSqlGeoBuffer extends GeneralDBSqlSpatialConstructTriple {
     1.9  
    1.10 -	public GeneralDBSqlGeoBuffer(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    1.11 -		super(left, right);
    1.12 +	public GeneralDBSqlGeoBuffer(GeneralDBSqlExpr left, GeneralDBSqlExpr right, GeneralDBSqlExpr third)
    1.13 +	{
    1.14 +		super(left, right, third);
    1.15  	}
    1.16  
    1.17  	@Override
    1.18 -	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
    1.19 -		throws X
    1.20 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor) throws X
    1.21  	{
    1.22  		visitor.meet(this);
    1.23  	}
    1.24 -
    1.25  }
    1.26 \ No newline at end of file
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Tue Apr 16 14:12:15 2013 +0300
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Wed Apr 17 14:35:06 2013 +0300
     2.3 @@ -8,7 +8,6 @@
     2.4    
     2.5  import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
     2.6  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
     2.7 -import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator;
     2.8  
     2.9  public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricTriple
    2.10  {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialConstructTriple.java	Wed Apr 17 14:35:06 2013 +0300
     3.3 @@ -0,0 +1,23 @@
     3.4 +/*
     3.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
     3.6 + *
     3.7 + * Licensed under the Aduna BSD-style license.
     3.8 + */
     3.9 +package org.openrdf.sail.generaldb.algebra;
    3.10 +
    3.11 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
    3.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
    3.13 +import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator;
    3.14 +
    3.15 +public class GeneralDBSqlSpatialConstructTriple extends TripleGeneralDBOperator {
    3.16 +	public GeneralDBSqlSpatialConstructTriple(GeneralDBSqlExpr left, GeneralDBSqlExpr right, GeneralDBSqlExpr third) 
    3.17 +	{
    3.18 +		super(left, right, third);
    3.19 +	}
    3.20 +
    3.21 +	@Override
    3.22 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor) throws X
    3.23 +	{
    3.24 +		visitor.meet(this);
    3.25 +	}
    3.26 +}
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialMetricTriple.java	Tue Apr 16 14:12:15 2013 +0300
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialMetricTriple.java	Wed Apr 17 14:35:06 2013 +0300
     4.3 @@ -1,3 +1,8 @@
     4.4 +/*
     4.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
     4.6 + *
     4.7 + * Licensed under the Aduna BSD-style license.
     4.8 + */
     4.9  package org.openrdf.sail.generaldb.algebra;
    4.10  
    4.11  import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Tue Apr 16 14:12:15 2013 +0300
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Wed Apr 17 14:35:06 2013 +0300
     5.3 @@ -349,9 +349,9 @@
     5.4  		return new GeneralDBSqlGeoUnion(left, right);
     5.5  	}
     5.6  
     5.7 -	public static GeneralDBSqlExpr geoBuffer(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
     5.8 +	public static GeneralDBSqlExpr geoBuffer(GeneralDBSqlExpr left, GeneralDBSqlExpr right, GeneralDBSqlExpr third) {
     5.9  
    5.10 -		return new GeneralDBSqlGeoBuffer(left, right);
    5.11 +		return new GeneralDBSqlGeoBuffer(left, right, third);
    5.12  	}
    5.13  	
    5.14  	public static GeneralDBSqlExpr geoTransform(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Tue Apr 16 14:12:15 2013 +0300
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Wed Apr 17 14:35:06 2013 +0300
     6.3 @@ -122,6 +122,7 @@
     6.4  import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlConvexHullFunc;
     6.5  import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlEnvelopeFunc;
     6.6  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BoundaryFunc;
     6.7 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc;
     6.8  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.ConvexHullFunc;
     6.9  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc;
    6.10  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc;
    6.11 @@ -615,6 +616,7 @@
    6.12  		{
    6.13  			GeneralDBSqlExpr leftArg = null;
    6.14  			GeneralDBSqlExpr rightArg = null;
    6.15 +			GeneralDBSqlExpr thirdArg = null;
    6.16  
    6.17  			ValueExpr left = functionCall.getArgs().get(0);
    6.18  
    6.19 @@ -660,9 +662,11 @@
    6.20  						rightArg = label(right);
    6.21  					}
    6.22  				}
    6.23 +				if(function instanceof BufferFunc)
    6.24 +					thirdArg = uri(functionCall.getArgs().get(2));
    6.25  			}
    6.26  
    6.27 -			result = spatialConstructPicker(function, leftArg, rightArg);
    6.28 +			result = spatialConstructPicker(function, leftArg, rightArg, thirdArg);
    6.29  
    6.30  		}
    6.31  		else if(function instanceof SpatialRelationshipFunc)
    6.32 @@ -845,10 +849,10 @@
    6.33  	{
    6.34  		GeneralDBSqlExpr leftArg = null;
    6.35  		GeneralDBSqlExpr rightArg = null;
    6.36 +		GeneralDBSqlExpr thirdArg = null;
    6.37  
    6.38  		ValueExpr left = functionCall.getArgs().get(0);
    6.39  
    6.40 -
    6.41  		if(left instanceof FunctionCall)
    6.42  		{
    6.43  			leftArg = spatialFunction((FunctionCall) left);
    6.44 @@ -858,9 +862,6 @@
    6.45  			leftArg = label(left);
    6.46  		}
    6.47  
    6.48 -
    6.49 -
    6.50 -
    6.51  		if(!(function instanceof EnvelopeFunc) 
    6.52  				&& !(function instanceof ConvexHullFunc) 
    6.53  				&& !(function instanceof BoundaryFunc)
    6.54 @@ -893,9 +894,11 @@
    6.55  					rightArg = label(right);
    6.56  				}
    6.57  			}
    6.58 +			if(function instanceof BufferFunc)
    6.59 +				thirdArg = uri(functionCall.getArgs().get(2));
    6.60  		}
    6.61  
    6.62 -		return spatialConstructPicker(function, leftArg, rightArg);
    6.63 +		return spatialConstructPicker(function, leftArg, rightArg, thirdArg);
    6.64  
    6.65  	}
    6.66  
    6.67 @@ -1176,7 +1179,7 @@
    6.68  	}
    6.69  
    6.70  
    6.71 -	GeneralDBSqlExpr spatialConstructPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    6.72 +	GeneralDBSqlExpr spatialConstructPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, GeneralDBSqlExpr thirdArg)
    6.73  	{
    6.74  		if(function.getURI().equals(GeoConstants.stSPARQLunion))
    6.75  		{
    6.76 @@ -1184,7 +1187,7 @@
    6.77  		}
    6.78  		else if(function.getURI().equals(GeoConstants.stSPARQLbuffer))
    6.79  		{
    6.80 -			return geoBuffer(leftArg,rightArg);
    6.81 +			return geoBuffer(leftArg, rightArg, thirdArg);
    6.82  		}
    6.83  		else if(function.getURI().equals(GeoConstants.stSPARQLtransform))
    6.84  		{
     7.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Tue Apr 16 14:12:15 2013 +0300
     7.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Wed Apr 17 14:35:06 2013 +0300
     7.3 @@ -50,6 +50,7 @@
     7.4  import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlConvexHullFunc;
     7.5  import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlEnvelopeFunc;
     7.6  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BoundaryFunc;
     7.7 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc;
     7.8  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.ConvexHullFunc;
     7.9  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc;
    7.10  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc;
    7.11 @@ -297,6 +298,7 @@
    7.12  	{
    7.13  		GeneralDBSqlExpr leftArg = null;
    7.14  		GeneralDBSqlExpr rightArg = null;
    7.15 +		GeneralDBSqlExpr thirdArg = null;
    7.16  
    7.17  		ValueExpr left = functionCall.getArgs().get(0);
    7.18  
    7.19 @@ -310,8 +312,6 @@
    7.20  			leftArg = label(left);
    7.21  		}
    7.22  
    7.23 -
    7.24 -
    7.25  		if(!(function instanceof EnvelopeFunc) 
    7.26  				&& !(function instanceof ConvexHullFunc) 
    7.27  				&& !(function instanceof BoundaryFunc)
    7.28 @@ -342,14 +342,12 @@
    7.29  					//thus the special treatment
    7.30  					rightArg = label(right);
    7.31  				}
    7.32 -
    7.33 -
    7.34 -
    7.35 -
    7.36  			}
    7.37 +			if(function instanceof BufferFunc)
    7.38 +				thirdArg = uri(functionCall.getArgs().get(2));
    7.39  		}
    7.40  
    7.41 -		return spatialConstructPicker(function, leftArg, rightArg);
    7.42 +		return spatialConstructPicker(function, leftArg, rightArg, thirdArg);
    7.43  
    7.44  	}
    7.45  
    7.46 @@ -435,7 +433,7 @@
    7.47  	}
    7.48  
    7.49  
    7.50 -	GeneralDBSqlExpr spatialConstructPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    7.51 +	GeneralDBSqlExpr spatialConstructPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, GeneralDBSqlExpr thirdArg)
    7.52  	{
    7.53  		if(function.getURI().equals(GeoConstants.stSPARQLunion))
    7.54  		{
    7.55 @@ -443,7 +441,7 @@
    7.56  		}
    7.57  		else if(function.getURI().equals(GeoConstants.stSPARQLbuffer))
    7.58  		{
    7.59 -			return geoBuffer(leftArg,rightArg);
    7.60 +			return geoBuffer(leftArg,rightArg, thirdArg);
    7.61  		}
    7.62  		else if(function.getURI().equals(GeoConstants.stSPARQLtransform))
    7.63  		{
     8.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Apr 16 14:12:15 2013 +0300
     8.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Wed Apr 17 14:35:06 2013 +0300
     8.3 @@ -85,6 +85,7 @@
     8.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMathExpr;
     8.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot;
     8.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
     8.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructTriple;
     8.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
     8.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
    8.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricTriple;
    8.11 @@ -816,6 +817,12 @@
    8.12  		{
    8.13  			locateColumnVars(((GeneralDBSqlSpatialConstructUnary)expr).getArg(),allKnown);
    8.14  		}
    8.15 +		else if(expr instanceof GeneralDBSqlSpatialConstructTriple)
    8.16 +		{
    8.17 +			locateColumnVars(((GeneralDBSqlSpatialConstructTriple)expr).getLeftArg(),allKnown);
    8.18 +			locateColumnVars(((GeneralDBSqlSpatialConstructTriple)expr).getRightArg(),allKnown);
    8.19 +			locateColumnVars(((GeneralDBSqlSpatialConstructTriple)expr).getThirdArg(),allKnown);
    8.20 +		}
    8.21  		/** Addition for datetime metric functions
    8.22  		 * 
    8.23  		 * @author George Garbis <ggarbis@di.uoa.gr>
    8.24 @@ -985,8 +992,7 @@
    8.25  			}
    8.26  
    8.27  		}
    8.28 -		else if(expr instanceof GeneralDBSqlSpatialConstructBinary ||
    8.29 -				expr instanceof GeneralDBSqlSpatialConstructUnary)
    8.30 +		else if(expr instanceof GeneralDBSqlSpatialConstructBinary || expr instanceof GeneralDBSqlSpatialConstructUnary || expr instanceof GeneralDBSqlSpatialConstructTriple)
    8.31  		{
    8.32  			return ResultType.WKB;
    8.33  		}
     9.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Tue Apr 16 14:12:15 2013 +0300
     9.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Wed Apr 17 14:35:06 2013 +0300
     9.3 @@ -661,9 +661,6 @@
     9.4  		else if (expr instanceof GeneralDBSqlGeoUnion) {
     9.5  			append((GeneralDBSqlGeoUnion)expr, filter);
     9.6  		}
     9.7 -		else if (expr instanceof GeneralDBSqlGeoBuffer) {
     9.8 -			append((GeneralDBSqlGeoBuffer)expr, filter);
     9.9 -		}
    9.10  		else if (expr instanceof GeneralDBSqlGeoTransform) {
    9.11  			append((GeneralDBSqlGeoTransform)expr, filter);
    9.12  		}
    9.13 @@ -696,6 +693,10 @@
    9.14  		else if (expr instanceof GeneralDBSqlGeoDistance) {
    9.15  			append((GeneralDBSqlGeoDistance)expr, filter);
    9.16  		}
    9.17 +		//Construct
    9.18 +		else if (expr instanceof GeneralDBSqlGeoBuffer) {
    9.19 +			append((GeneralDBSqlGeoBuffer)expr, filter);
    9.20 +		}
    9.21  		else
    9.22  		{
    9.23  			throw unsupported(expr);
    9.24 @@ -1153,9 +1154,8 @@
    9.25  
    9.26  	protected abstract String appendWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter);
    9.27  
    9.28 -	protected void appendConstructFunction(GeneralDBSqlExpr constr, GeneralDBSqlExprBuilder filter) 
    9.29 -			throws UnsupportedRdbmsOperatorException
    9.30 -			{
    9.31 +	protected void appendConstructFunction(GeneralDBSqlExpr constr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
    9.32 +	{
    9.33  		if(constr instanceof GeneralDBSqlGeoUnion)
    9.34  		{
    9.35  			append((GeneralDBSqlGeoUnion)constr, filter);
    9.36 @@ -1192,8 +1192,7 @@
    9.37  		{
    9.38  			append((GeneralDBSqlGeoSymDifference)constr, filter);
    9.39  		}
    9.40 -
    9.41 -			}
    9.42 +	}
    9.43  
    9.44  	protected void appendMetricFunction(GeneralDBSqlExpr constr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
    9.45  	{
    10.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Tue Apr 16 14:12:15 2013 +0300
    10.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Wed Apr 17 14:35:06 2013 +0300
    10.3 @@ -56,8 +56,10 @@
    10.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRelate;
    10.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRight;
    10.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
    10.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructTriple;
    10.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
    10.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
   10.10 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricTriple;
   10.11  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
   10.12  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
   10.13  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouches;
   10.14 @@ -115,6 +117,7 @@
   10.15  	
   10.16  	public static final String ST_TRANSFORM = "ST_Transform";	
   10.17  	public static final String GEOGRAPHY = "Geography";
   10.18 +	public static final String GEOMETRY = "Geometry";
   10.19  	
   10.20  	/**
   10.21  	 * If (spatial) label column met is null, I must not try to retrieve its srid. 
   10.22 @@ -697,11 +700,10 @@
   10.23  			}
   10.24  
   10.25  	@Override
   10.26 -	protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter)
   10.27 -			throws UnsupportedRdbmsOperatorException
   10.28 -			{
   10.29 -		appendMonetDBSpatialFunctionBinary(expr, filter, SpatialFunctionsMonetDB.ST_Buffer);
   10.30 -			}
   10.31 +	protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
   10.32 +	{
   10.33 +		appendMonetDBBuffer(expr, filter, SpatialFunctionsMonetDB.ST_Buffer);
   10.34 +	}
   10.35  
   10.36  	//XXX Different Behavior
   10.37  	@Override
   10.38 @@ -1329,8 +1331,7 @@
   10.39  			case ST_Difference: filter.appendFunction("Difference"); break;
   10.40  			case ST_Intersection: filter.appendFunction("Intersection"); break;
   10.41  			case ST_Union: filter.appendFunction("\"Union\""); break;
   10.42 -			case ST_SymDifference: filter.appendFunction("SymDifference"); break;
   10.43 -			case ST_Buffer: filter.appendFunction("Buffer"); break;			
   10.44 +			case ST_SymDifference: filter.appendFunction("SymDifference"); break;			
   10.45  			case ST_Touches: filter.appendFunction("Touches"); break;
   10.46  			case ST_Disjoint: filter.appendFunction("Disjoint"); break;
   10.47  			case ST_Crosses: filter.appendFunction("Crosses"); break;
   10.48 @@ -1444,37 +1445,262 @@
   10.49  			filter.appendComma();
   10.50  			filter.append(sridExpr);
   10.51  		}
   10.52 -			}
   10.53 +	}
   10.54  	
   10.55 -		protected void appendMonetDBDistance(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsMonetDB func) throws UnsupportedRdbmsOperatorException
   10.56 +	protected void appendMonetDBDistance(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsMonetDB func) throws UnsupportedRdbmsOperatorException
   10.57 +	{
   10.58 +		String units = null;
   10.59 +
   10.60 +		filter.openBracket();
   10.61 +		
   10.62 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
   10.63 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
   10.64 +		boolean check3 = expr.getThirdArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
   10.65 +		
   10.66 +		if(check1)
   10.67  		{
   10.68 -			String units = null;
   10.69 -
   10.70 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   10.71 +		}
   10.72 +		else if(check2)
   10.73 +		{
   10.74 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   10.75 +		}
   10.76 +		else if(check3)
   10.77 +		{
   10.78 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   10.79 +		}
   10.80 +		
   10.81 +		else
   10.82 +		{								
   10.83 +			filter.appendFunction("Distance");
   10.84 +			
   10.85  			filter.openBracket();
   10.86  			
   10.87 -			boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
   10.88 -			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
   10.89 -			boolean check3 = expr.getThirdArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
   10.90 +			if (expr.getThirdArg() instanceof GeneralDBStringValue)
   10.91 +			{			
   10.92 +				units = ((GeneralDBStringValue)expr.getThirdArg()).getValue();
   10.93 +				if(!OGCConstants.supportedUnitsOfMeasure.contains(units))
   10.94 +				{
   10.95 +					throw new UnsupportedRdbmsOperatorException("No such unit of measure exists");
   10.96 +				}	
   10.97 +
   10.98 +				if(units.equals(OGCConstants.OGCmetre))
   10.99 +				{
  10.100 +					filter.appendFunction(GEOGRAPHY);
  10.101 +					filter.openBracket();
  10.102 +					filter.appendFunction(ST_TRANSFORM);
  10.103 +					filter.openBracket();
  10.104 +				}
  10.105 +				else if(units.equals(OGCConstants.OGCdegree))
  10.106 +				{
  10.107 +					filter.appendFunction(ST_TRANSFORM);
  10.108 +					filter.openBracket();
  10.109 +				}	
  10.110 +			}	
  10.111  			
  10.112 -			if(check1)
  10.113 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
  10.114  			{
  10.115 -				this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.116 +				appendWKT(expr.getLeftArg(),filter);
  10.117  			}
  10.118 -			else if(check2)
  10.119 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
  10.120  			{
  10.121 -				this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.122 +				appendConstructFunction(expr.getLeftArg(), filter);
  10.123  			}
  10.124 -			else if(check3)
  10.125 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
  10.126  			{
  10.127 -				this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.128 +				appendConstructFunction(expr.getLeftArg(), filter);
  10.129 +			}
  10.130 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  10.131 +			{
  10.132 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
  10.133 +				appendMBB(onlyLabel,filter); 
  10.134 +			}
  10.135 +			else
  10.136 +			{
  10.137 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
  10.138  			}
  10.139  			
  10.140 +			if(units.equals(OGCConstants.OGCmetre))
  10.141 +			{				
  10.142 +				filter.appendComma();
  10.143 +				filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.144 +				filter.closeBracket(); //close st_transform
  10.145 +				filter.closeBracket(); //close geography
  10.146 +				
  10.147 +				filter.appendComma();
  10.148 +
  10.149 +				filter.appendFunction(GEOGRAPHY);
  10.150 +				filter.openBracket();
  10.151 +				filter.appendFunction(ST_TRANSFORM);
  10.152 +				filter.openBracket();
  10.153 +			}
  10.154 +			else if(units.equals(OGCConstants.OGCdegree))
  10.155 +			{
  10.156 +				filter.appendComma();
  10.157 +				filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.158 +				filter.closeBracket(); //close st_transform
  10.159 +				
  10.160 +				filter.appendComma();
  10.161 +				
  10.162 +				filter.appendFunction(ST_TRANSFORM);
  10.163 +				filter.openBracket();
  10.164 +			}	
  10.165  			else
  10.166 -			{								
  10.167 -				filter.appendFunction("Distance");
  10.168 -				
  10.169 -				filter.openBracket();
  10.170 -				
  10.171 +			{
  10.172 +				filter.appendComma();
  10.173 +			}															
  10.174 +			
  10.175 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
  10.176 +			{
  10.177 +				appendWKT(expr.getRightArg(),filter);
  10.178 +			}
  10.179 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
  10.180 +			{
  10.181 +				appendConstructFunction(expr.getRightArg(), filter);
  10.182 +			}
  10.183 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
  10.184 +			{
  10.185 +				appendConstructFunction(expr.getRightArg(), filter);
  10.186 +			}
  10.187 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructTriple)
  10.188 +			{
  10.189 +				appendConstructFunction(expr.getRightArg(), filter);
  10.190 +			}
  10.191 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
  10.192 +			{
  10.193 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
  10.194 +				appendMBB(onlyLabel,filter);					 
  10.195 +			}
  10.196 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
  10.197 +			{
  10.198 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
  10.199 +			}
  10.200 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
  10.201 +			{
  10.202 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
  10.203 +			}
  10.204 +			else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
  10.205 +			{
  10.206 +				filter.keepSRID_part1();
  10.207 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
  10.208 +				filter.keepSRID_part2();
  10.209 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
  10.210 +				filter.keepSRID_part3();
  10.211 +			}
  10.212 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
  10.213 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
  10.214 +			{
  10.215 +				appendWithCastDouble(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  10.216 +				//					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  10.217 +				//					appendCastToDouble(filter);
  10.218 +			}
  10.219 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
  10.220 +			{
  10.221 +				appendMetricFunction(expr.getRightArg(), filter);
  10.222 +			}
  10.223 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
  10.224 +			{
  10.225 +				appendMetricFunction(expr.getRightArg(), filter);
  10.226 +			}
  10.227 +			else
  10.228 +			{
  10.229 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
  10.230 +			}
  10.231 +
  10.232 +			if(units.equals(OGCConstants.OGCmetre))
  10.233 +			{
  10.234 +				filter.appendComma();
  10.235 +				filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.236 +				filter.closeBracket();
  10.237 +				filter.closeBracket();
  10.238 +			}
  10.239 +			else if(units.equals(OGCConstants.OGCdegree))
  10.240 +			{
  10.241 +				filter.appendComma();
  10.242 +				filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.243 +				filter.closeBracket();
  10.244 +			}
  10.245 +
  10.246 +			filter.closeBracket();
  10.247 +		}
  10.248 +
  10.249 +		filter.closeBracket();
  10.250 +	}
  10.251 +	
  10.252 +	protected void appendMonetDBBuffer(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsMonetDB func) throws UnsupportedRdbmsOperatorException
  10.253 +	{
  10.254 +		boolean sridNeeded = true;
  10.255 +		//XXX Incorporating SRID
  10.256 +		String sridExpr = null;
  10.257 +		String units = null;
  10.258 +
  10.259 +		filter.openBracket();
  10.260 +		
  10.261 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
  10.262 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
  10.263 +		boolean check3 = expr.getThirdArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
  10.264 +		
  10.265 +		if(check1)
  10.266 +		{
  10.267 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.268 +		}
  10.269 +		else if(check2)
  10.270 +		{
  10.271 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.272 +		}
  10.273 +		else if(check3)
  10.274 +		{
  10.275 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.276 +		}
  10.277 +		
  10.278 +		else
  10.279 +		{	
  10.280 +			GeneralDBSqlExpr tmp = expr;
  10.281 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
  10.282 +			{
  10.283 +				while(true)
  10.284 +				{
  10.285 +					GeneralDBSqlExpr child;
  10.286 +
  10.287 +					if(tmp instanceof BinaryGeneralDBOperator)
  10.288 +					{
  10.289 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
  10.290 +					}
  10.291 +					else //(tmp instanceof UnaryGeneralDBOperator)
  10.292 +					{
  10.293 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
  10.294 +					}
  10.295 +
  10.296 +					tmp = child;
  10.297 +					if(tmp instanceof GeneralDBLabelColumn)
  10.298 +					{
  10.299 +						//Reached the innermost left var -> need to capture its SRID
  10.300 +						String alias;
  10.301 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
  10.302 +							//Predicates used in triple patterns non-existent in db
  10.303 +							alias="NULL";
  10.304 +						}
  10.305 +						else
  10.306 +						{
  10.307 +							//Reached the innermost left var -> need to capture its SRID
  10.308 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
  10.309 +							alias=alias+".srid";
  10.310 +						}
  10.311 +						sridExpr = alias;
  10.312 +						break;
  10.313 +					}
  10.314 +					else if (tmp instanceof GeneralDBStringValue) //Constant!!
  10.315 +					{
  10.316 +						sridNeeded  = false;
  10.317 +						break;
  10.318 +					}
  10.319 +				}
  10.320 +				if(sridNeeded)
  10.321 +				{
  10.322 +					filter.appendFunction("Transform");
  10.323 +					filter.openBracket();
  10.324 +				}								
  10.325 +									
  10.326  				if (expr.getThirdArg() instanceof GeneralDBStringValue)
  10.327  				{			
  10.328  					units = ((GeneralDBStringValue)expr.getThirdArg()).getValue();
  10.329 @@ -1482,9 +1708,13 @@
  10.330  					{
  10.331  						throw new UnsupportedRdbmsOperatorException("No such unit of measure exists");
  10.332  					}	
  10.333 -
  10.334 +	
  10.335  					if(units.equals(OGCConstants.OGCmetre))
  10.336  					{
  10.337 +						filter.appendFunction(GEOMETRY);
  10.338 +						filter.openBracket();
  10.339 +						filter.appendFunction("Buffer");			
  10.340 +						filter.openBracket();
  10.341  						filter.appendFunction(GEOGRAPHY);
  10.342  						filter.openBracket();
  10.343  						filter.appendFunction(ST_TRANSFORM);
  10.344 @@ -1492,6 +1722,8 @@
  10.345  					}
  10.346  					else if(units.equals(OGCConstants.OGCdegree))
  10.347  					{
  10.348 +						filter.appendFunction("Buffer");			
  10.349 +						filter.openBracket();
  10.350  						filter.appendFunction(ST_TRANSFORM);
  10.351  						filter.openBracket();
  10.352  					}	
  10.353 @@ -1509,46 +1741,36 @@
  10.354  				{
  10.355  					appendConstructFunction(expr.getLeftArg(), filter);
  10.356  				}
  10.357 +				else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
  10.358 +				{
  10.359 +					appendConstructFunction(expr.getLeftArg(), filter);
  10.360 +				}
  10.361  				else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  10.362  				{
  10.363  					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
  10.364 -					appendMBB(onlyLabel,filter); 
  10.365 +					appendMBB(onlyLabel,filter);
  10.366  				}
  10.367  				else
  10.368  				{
  10.369  					appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
  10.370  				}
  10.371 -				
  10.372 +
  10.373  				if(units.equals(OGCConstants.OGCmetre))
  10.374 -				{				
  10.375 +				{
  10.376  					filter.appendComma();
  10.377  					filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.378  					filter.closeBracket(); //close st_transform
  10.379  					filter.closeBracket(); //close geography
  10.380 -					
  10.381  					filter.appendComma();
  10.382 -
  10.383 -					filter.appendFunction(GEOGRAPHY);
  10.384 -					filter.openBracket();
  10.385 -					filter.appendFunction(ST_TRANSFORM);
  10.386 -					filter.openBracket();
  10.387  				}
  10.388  				else if(units.equals(OGCConstants.OGCdegree))
  10.389  				{
  10.390  					filter.appendComma();
  10.391  					filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.392  					filter.closeBracket(); //close st_transform
  10.393 -					
  10.394  					filter.appendComma();
  10.395 -					
  10.396 -					filter.appendFunction(ST_TRANSFORM);
  10.397 -					filter.openBracket();
  10.398 -				}	
  10.399 -				else
  10.400 -				{
  10.401 -					filter.appendComma();
  10.402 -				}															
  10.403 -				
  10.404 +				}
  10.405 +
  10.406  				if(expr.getRightArg() instanceof GeneralDBStringValue)
  10.407  				{
  10.408  					appendWKT(expr.getRightArg(),filter);
  10.409 @@ -1561,33 +1783,28 @@
  10.410  				{
  10.411  					appendConstructFunction(expr.getRightArg(), filter);
  10.412  				}
  10.413 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricTriple)
  10.414 +				{
  10.415 +					appendMetricFunction(expr.getRightArg(), filter);
  10.416 +				}
  10.417  				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
  10.418  				{
  10.419  					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
  10.420 -					appendMBB(onlyLabel,filter);					 
  10.421 +					appendMBB(onlyLabel,filter);
  10.422  				}
  10.423 -				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
  10.424 +				else if(expr.getRightArg() instanceof GeneralDBDoubleValue)
  10.425  				{
  10.426  					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
  10.427  				}
  10.428 -				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
  10.429 +				else if(expr.getRightArg() instanceof GeneralDBNumericColumn)
  10.430  				{
  10.431  					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
  10.432  				}
  10.433 -				else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
  10.434 -				{
  10.435 -					filter.keepSRID_part1();
  10.436 -					append(((GeneralDBURIColumn)expr.getRightArg()), filter);
  10.437 -					filter.keepSRID_part2();
  10.438 -					append(((GeneralDBURIColumn)expr.getRightArg()), filter);
  10.439 -					filter.keepSRID_part3();
  10.440 -				}
  10.441  				//case met in buffer when in select -> buffer(?spatial,?thematic)
  10.442  				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
  10.443  				{
  10.444 -					appendWithCastDouble(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  10.445 -					//					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  10.446 -					//					appendCastToDouble(filter);
  10.447 +					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  10.448 +					appendCastToDouble(filter);
  10.449  				}
  10.450  				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
  10.451  				{
  10.452 @@ -1597,30 +1814,36 @@
  10.453  				{
  10.454  					appendMetricFunction(expr.getRightArg(), filter);
  10.455  				}
  10.456 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricTriple)
  10.457 +				{
  10.458 +					appendMetricFunction(expr.getRightArg(), filter);
  10.459 +				}
  10.460  				else
  10.461  				{
  10.462  					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
  10.463  				}
  10.464  
  10.465 -				if(units.equals(OGCConstants.OGCmetre))
  10.466 +				filter.closeBracket();
  10.467 +				//SRID Support
  10.468 +				if(expr instanceof GeneralDBSqlSpatialConstructTriple && expr.getParentNode() == null)
  10.469  				{
  10.470  					filter.appendComma();
  10.471 -					filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.472 -					filter.closeBracket();
  10.473 +					filter.append(sridExpr);
  10.474  					filter.closeBracket();
  10.475  				}
  10.476 -				else if(units.equals(OGCConstants.OGCdegree))
  10.477 -				{
  10.478 -					filter.appendComma();
  10.479 -					filter.append(String.valueOf(GeoConstants.defaultSRID));
  10.480 -					filter.closeBracket();
  10.481 -				}
  10.482 -
  10.483 -				filter.closeBracket();
  10.484 +				///
  10.485  			}
  10.486 -
  10.487 +			if(units.equals(OGCConstants.OGCmetre))
  10.488 +				filter.closeBracket(); //close Geometry
  10.489  			filter.closeBracket();
  10.490 -		}
  10.491 +			//Used to explicitly include SRID
  10.492 +			if(expr instanceof GeneralDBSqlSpatialConstructTriple && expr.getParentNode() == null)
  10.493 +			{
  10.494 +				filter.appendComma();
  10.495 +				filter.append(sridExpr);
  10.496 +			}
  10.497 +		}	
  10.498 +	}	
  10.499  
  10.500  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 
  10.501  	protected void appendMonetDBSpatialFunctionUnary(UnaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsMonetDB func)
    11.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Apr 16 14:12:15 2013 +0300
    11.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Wed Apr 17 14:35:06 2013 +0300
    11.3 @@ -57,6 +57,7 @@
    11.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRelate;
    11.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRight;
    11.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
    11.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructTriple;
    11.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
    11.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
   11.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricTriple;
   11.11 @@ -120,6 +121,7 @@
   11.12  	public static final String ST_TRANSFORM = "ST_Transform";
   11.13  	public static final String ST_ASBINARY = "ST_AsBinary";
   11.14  	public static final String GEOGRAPHY = "Geography";
   11.15 +	public static final String GEOMETRY = "Geometry";
   11.16  	/**
   11.17  	 * If (spatial) label column met is null, I must not try to retrieve its srid. 
   11.18  	 * Opting to ask for 'null' instead
   11.19 @@ -368,6 +370,10 @@
   11.20  		{
   11.21  			dispatchTripleSqlOperator((GeneralDBSqlSpatialMetricTriple) expr, query.select);
   11.22  		}
   11.23 +		else if(expr instanceof GeneralDBSqlSpatialConstructTriple)
   11.24 +		{
   11.25 +			dispatchTripleSqlOperator((GeneralDBSqlSpatialConstructTriple) expr, query.select);
   11.26 +		}
   11.27  		//SRID support must be explicitly added!
   11.28  
   11.29  		return this;
   11.30 @@ -696,11 +702,10 @@
   11.31  			}
   11.32  
   11.33  	@Override
   11.34 -	protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter)
   11.35 -			throws UnsupportedRdbmsOperatorException
   11.36 -			{
   11.37 -		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Buffer);
   11.38 -			}
   11.39 +	protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
   11.40 +	{
   11.41 +		appendBuffer(expr, filter, SpatialFunctionsPostGIS.ST_Buffer);
   11.42 +	}
   11.43  
   11.44  	//XXX Different Behavior
   11.45  	@Override
   11.46 @@ -917,6 +922,10 @@
   11.47  				{
   11.48  					appendConstructFunction(expr.getArg(), filter);
   11.49  				}
   11.50 +				else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructTriple)
   11.51 +				{
   11.52 +					appendConstructFunction(expr.getArg(), filter);
   11.53 +				}
   11.54  				else if(expr.getArg() instanceof GeneralDBSqlCase)
   11.55  				{
   11.56  					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult();
   11.57 @@ -1098,6 +1107,10 @@
   11.58  			{
   11.59  				appendConstructFunction(expr.getLeftArg(), filter);
   11.60  			}
   11.61 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
   11.62 +			{
   11.63 +				appendConstructFunction(expr.getLeftArg(), filter);
   11.64 +			}
   11.65  			else
   11.66  			{
   11.67  				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   11.68 @@ -1140,6 +1153,10 @@
   11.69  			{
   11.70  				appendConstructFunction(expr.getRightArg(), filter);
   11.71  			}
   11.72 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
   11.73 +			{
   11.74 +				appendConstructFunction(expr.getLeftArg(), filter);
   11.75 +			}
   11.76  			else
   11.77  			{
   11.78  				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   11.79 @@ -1151,9 +1168,8 @@
   11.80  	}
   11.81  
   11.82  	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
   11.83 -	protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter)
   11.84 -			throws UnsupportedRdbmsOperatorException
   11.85 -			{
   11.86 +	protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
   11.87 +	{
   11.88  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
   11.89  		boolean sridNeeded = true;
   11.90  		//XXX Incorporating SRID
   11.91 @@ -1236,6 +1252,10 @@
   11.92  			{
   11.93  				appendConstructFunction(expr.getLeftArg(), filter);
   11.94  			}
   11.95 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
   11.96 +			{
   11.97 +				appendConstructFunction(expr.getLeftArg(), filter);
   11.98 +			}
   11.99  			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  11.100  			{
  11.101  				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
  11.102 @@ -1405,9 +1425,8 @@
  11.103  
  11.104  	//Used in all the generaldb stsparql (and geosparql) boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
  11.105  	//EXCEPT ST_Transform!!!
  11.106 -	protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
  11.107 -			throws UnsupportedRdbmsOperatorException
  11.108 -			{
  11.109 +	protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) throws UnsupportedRdbmsOperatorException
  11.110 +	{
  11.111  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
  11.112  		boolean sridNeeded = true;
  11.113  		//XXX Incorporating SRID
  11.114 @@ -1441,6 +1460,11 @@
  11.115  					{
  11.116  						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
  11.117  					}
  11.118 +					else if(tmp instanceof TripleGeneralDBOperator)
  11.119 +					{
  11.120 +						child = ((TripleGeneralDBOperator) tmp).getLeftArg();
  11.121 +					}
  11.122 +
  11.123  					else //(tmp instanceof UnaryGeneralDBOperator)
  11.124  					{
  11.125  						child = ((UnaryGeneralDBOperator) tmp).getArg();
  11.126 @@ -1513,6 +1537,10 @@
  11.127  			{
  11.128  				appendConstructFunction(expr.getLeftArg(), filter);
  11.129  			}
  11.130 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
  11.131 +			{
  11.132 +				appendConstructFunction(expr.getLeftArg(), filter);
  11.133 +			}
  11.134  			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  11.135  			{
  11.136  				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
  11.137 @@ -1536,6 +1564,10 @@
  11.138  			{
  11.139  				appendConstructFunction(expr.getRightArg(), filter);
  11.140  			}
  11.141 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructTriple)
  11.142 +			{
  11.143 +				appendConstructFunction(expr.getRightArg(), filter);
  11.144 +			}
  11.145  			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
  11.146  			{
  11.147  				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
  11.148 @@ -1571,6 +1603,10 @@
  11.149  			{
  11.150  				appendMetricFunction(expr.getRightArg(), filter);
  11.151  			}
  11.152 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricTriple)
  11.153 +			{
  11.154 +				appendMetricFunction(expr.getRightArg(), filter);
  11.155 +			}
  11.156  			else
  11.157  			{
  11.158  				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
  11.159 @@ -1619,27 +1655,22 @@
  11.160  		else if(check3)
  11.161  		{
  11.162  			this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
  11.163 -
  11.164  		}
  11.165  		else
  11.166 -		{						
  11.167 +		{
  11.168  			filter.appendFunction("ST_Distance");
  11.169 -
  11.170  			filter.openBracket();
  11.171  	
  11.172  			if (expr.getThirdArg() instanceof GeneralDBStringValue)
  11.173 -			{	
  11.174 -				
  11.175 +			{
  11.176  				units = ((GeneralDBStringValue)expr.getThirdArg()).getValue();
  11.177 -				
  11.178  				if(!OGCConstants.supportedUnitsOfMeasure.contains(units))
  11.179  				{
  11.180  					throw new UnsupportedRdbmsOperatorException("No such unit of measure exists");
  11.181  				}	
  11.182 -				
  11.183 +
  11.184  				if(units.equals(OGCConstants.OGCmetre))
  11.185 -				{							
  11.186 -					//if(!unparsedUnits.equals(OGCConstants.OGCmetre));
  11.187 +				{
  11.188  					filter.appendFunction(GEOGRAPHY);
  11.189  					filter.openBracket();
  11.190  					filter.appendFunction(ST_TRANSFORM);
  11.191 @@ -1664,6 +1695,10 @@
  11.192  			{
  11.193  				appendConstructFunction(expr.getLeftArg(), filter);
  11.194  			}
  11.195 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
  11.196 +			{
  11.197 +				appendConstructFunction(expr.getLeftArg(), filter);
  11.198 +			}			
  11.199  			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  11.200  			{
  11.201  				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
  11.202 @@ -1686,7 +1721,7 @@
  11.203  				filter.appendFunction(GEOGRAPHY);
  11.204  				filter.openBracket();
  11.205  				filter.appendFunction(ST_TRANSFORM);
  11.206 -				filter.openBracket();				
  11.207 +				filter.openBracket();
  11.208  			}
  11.209  			else if(units.equals(OGCConstants.OGCdegree))
  11.210  			{
  11.211 @@ -1716,6 +1751,10 @@
  11.212  			{
  11.213  				appendConstructFunction(expr.getRightArg(), filter);
  11.214  			}
  11.215 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
  11.216 +			{
  11.217 +				appendConstructFunction(expr.getLeftArg(), filter);
  11.218 +			}
  11.219  			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
  11.220  			{
  11.221  				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
  11.222 @@ -1767,10 +1806,229 @@
  11.223  		filter.closeBracket();
  11.224  	}
  11.225  
  11.226 +	//Buffer function
  11.227 +	protected void appendBuffer(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) throws UnsupportedRdbmsOperatorException
  11.228 +	{
  11.229 +		boolean sridNeeded = true;
  11.230 +		//XXX Incorporating SRID
  11.231 +		String sridExpr = null;
  11.232 +		String units = null;
  11.233 +
  11.234 +		filter.openBracket();
  11.235 +
  11.236 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  11.237 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  11.238 +		boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  11.239 +
  11.240 +		if(check1)
  11.241 +		{
  11.242 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  11.243 +
  11.244 +		}
  11.245 +		else if(check2)
  11.246 +		{
  11.247 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
  11.248 +		}
  11.249 +		else if(check3)
  11.250 +		{
  11.251 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
  11.252 +		}
  11.253 +		else
  11.254 +		{
  11.255 +			GeneralDBSqlExpr tmp = expr;
  11.256 +			if(tmp instanceof GeneralDBSqlSpatialConstructTriple && tmp.getParentNode() == null)
  11.257 +			{
  11.258 +				while(true)
  11.259 +				{
  11.260 +					GeneralDBSqlExpr child;
  11.261 +
  11.262 +					if(tmp instanceof TripleGeneralDBOperator)
  11.263 +					{
  11.264 +						child = ((TripleGeneralDBOperator) tmp).getLeftArg();
  11.265 +					}
  11.266 +					else if(tmp instanceof BinaryGeneralDBOperator)
  11.267 +					{
  11.268 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
  11.269 +					}
  11.270 +					else //(tmp instanceof UnaryGeneralDBOperator)
  11.271 +					{
  11.272 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
  11.273 +					}
  11.274 +
  11.275 +					tmp = child;
  11.276 +					if(tmp instanceof GeneralDBLabelColumn)
  11.277 +					{
  11.278 +						//Reached the innermost left var -> need to capture its SRID
  11.279 +						String alias;
  11.280 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
  11.281 +							//Predicates used in triple patterns non-existent in db
  11.282 +							alias="NULL";
  11.283 +						}
  11.284 +						else
  11.285 +						{
  11.286 +							//Reached the innermost left var -> need to capture its SRID
  11.287 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
  11.288 +							alias=alias+".srid";
  11.289 +						}
  11.290 +						sridExpr = alias;
  11.291 +						break;
  11.292 +					}
  11.293 +					else if (tmp instanceof GeneralDBStringValue) //Constant!!
  11.294 +					{
  11.295 +						sridNeeded  = false;
  11.296 +						break;
  11.297 +					}
  11.298 +				}
  11.299 +				if(sridNeeded)
  11.300 +				{
  11.301 +					filter.appendFunction(ST_TRANSFORM);
  11.302 +					filter.openBracket();
  11.303 +				}
  11.304 +			}			
  11.305 +
  11.306 +			if (expr.getThirdArg() instanceof GeneralDBStringValue)
  11.307 +			{
  11.308 +				units = ((GeneralDBStringValue)expr.getThirdArg()).getValue();
  11.309 +
  11.310 +				if(!OGCConstants.supportedUnitsOfMeasure.contains(units))
  11.311 +				{
  11.312 +					throw new UnsupportedRdbmsOperatorException("No such unit of measure exists");
  11.313 +				}
  11.314 +
  11.315 +				if(units.equals(OGCConstants.OGCmetre))
  11.316 +				{
  11.317 +					filter.appendFunction(GEOMETRY);
  11.318 +					filter.openBracket();
  11.319 +					filter.appendFunction("ST_Buffer");
  11.320 +					filter.openBracket();
  11.321 +					filter.appendFunction(GEOGRAPHY);
  11.322 +					filter.openBracket();
  11.323 +					filter.appendFunction(ST_TRANSFORM);
  11.324 +					filter.openBracket();
  11.325 +				}
  11.326 +				else if(units.equals(OGCConstants.OGCdegree))
  11.327 +				{
  11.328 +					filter.appendFunction("ST_Buffer");
  11.329 +					filter.openBracket();
  11.330 +					filter.appendFunction(ST_TRANSFORM);
  11.331 +					filter.openBracket();
  11.332 +				}
  11.333 +			}
  11.334 +
  11.335 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
  11.336 +			{
  11.337 +				appendWKT(expr.getLeftArg(),filter);
  11.338 +			}
  11.339 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
  11.340 +			{
  11.341 +				appendConstructFunction(expr.getLeftArg(), filter);
  11.342 +			}
  11.343 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
  11.344 +			{
  11.345 +				appendConstructFunction(expr.getLeftArg(), filter);
  11.346 +			}
  11.347 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructTriple)
  11.348 +			{
  11.349 +				appendConstructFunction(expr.getLeftArg(), filter);
  11.350 +			}
  11.351 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  11.352 +			{
  11.353 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
  11.354 +				appendMBB(onlyLabel,filter);
  11.355 +			}
  11.356 +			else
  11.357 +			{
  11.358 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
  11.359 +			}
  11.360 +
  11.361 +			if(units.equals(OGCConstants.OGCmetre))
  11.362 +			{
  11.363 +				filter.appendComma();
  11.364 +				filter.append(String.valueOf(GeoConstants.defaultSRID));
  11.365 +				filter.closeBracket(); //close st_transform
  11.366 +				filter.closeBracket(); //close geography
  11.367 +				filter.appendComma();
  11.368 +			}
  11.369 +			else if(units.equals(OGCConstants.OGCdegree))
  11.370 +			{
  11.371 +				filter.appendComma();
  11.372 +				filter.append(String.valueOf(GeoConstants.defaultSRID));
  11.373 +				filter.closeBracket(); //close st_transform
  11.374 +				filter.appendComma();
  11.375 +			}
  11.376 +
  11.377 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
  11.378 +			{
  11.379 +				appendWKT(expr.getRightArg(),filter);
  11.380 +			}
  11.381 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
  11.382 +			{
  11.383 +				appendConstructFunction(expr.getRightArg(), filter);
  11.384 +			}
  11.385 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
  11.386 +			{
  11.387 +				appendConstructFunction(expr.getRightArg(), filter);
  11.388 +			}
  11.389 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
  11.390 +			{
  11.391 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
  11.392 +				appendMBB(onlyLabel,filter);
  11.393 +			}
  11.394 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue)
  11.395 +			{
  11.396 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
  11.397 +			}
  11.398 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn)
  11.399 +			{
  11.400 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
  11.401 +			}
  11.402 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
  11.403 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
  11.404 +			{
  11.405 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  11.406 +				appendCastToDouble(filter);
  11.407 +			}
  11.408 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
  11.409 +			{
  11.410 +				appendMetricFunction(expr.getRightArg(), filter);
  11.411 +			}
  11.412 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
  11.413 +			{
  11.414 +				appendMetricFunction(expr.getRightArg(), filter);
  11.415 +			}
  11.416 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricTriple)
  11.417 +			{
  11.418 +				appendMetricFunction(expr.getRightArg(), filter);
  11.419 +			}
  11.420 +			else
  11.421 +			{
  11.422 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
  11.423 +			}
  11.424 +			
  11.425 +			if(units.equals(OGCConstants.OGCmetre))
  11.426 +				filter.closeBracket(); //close Geometry
  11.427 +			filter.closeBracket();
  11.428 +			//SRID Support
  11.429 +			if(expr instanceof GeneralDBSqlSpatialConstructTriple && expr.getParentNode() == null)
  11.430 +			{
  11.431 +				filter.appendComma();
  11.432 +				filter.append(sridExpr);
  11.433 +				filter.closeBracket();
  11.434 +			}
  11.435 +			///
  11.436 +		}
  11.437 +		filter.closeBracket();
  11.438 +		//Used to explicitly include SRID
  11.439 +		if(expr instanceof GeneralDBSqlSpatialConstructTriple && expr.getParentNode() == null)
  11.440 +		{
  11.441 +			filter.appendComma();
  11.442 +			filter.append(sridExpr);
  11.443 +		}
  11.444 +	}
  11.445 +
  11.446  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 
  11.447 -	protected void appendGeneralDBSpatialFunctionUnary(UnaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
  11.448 -			throws UnsupportedRdbmsOperatorException
  11.449 -			{
  11.450 +	protected void appendGeneralDBSpatialFunctionUnary(UnaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) throws UnsupportedRdbmsOperatorException
  11.451 +	{
  11.452  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
  11.453  		boolean sridNeeded = true;
  11.454  		String sridExpr = null;
  11.455 @@ -2055,9 +2313,8 @@
  11.456  
  11.457  	//GeoSPARQL
  11.458  	//XXX
  11.459 -	protected void appendRelate(BinaryGeneralDBOperator expr, PostGISSqlExprBuilder filter, char[] intersectionPattern)
  11.460 -			throws UnsupportedRdbmsOperatorException
  11.461 -			{
  11.462 +	protected void appendRelate(BinaryGeneralDBOperator expr, PostGISSqlExprBuilder filter, char[] intersectionPattern) throws UnsupportedRdbmsOperatorException
  11.463 +	{
  11.464  		filter.openBracket();
  11.465  
  11.466  		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");