Strabon

changeset 956:4454601946a5

#23 Changed the definition and implementation of strdf:distance. Now it supports meters or degrees as
third argument. It can be called as follows:

strdf:distance(geom1, geom2, <http://www.opengis.net/def/uom/OGC/1.0/metre>) or
strdf:distance(geom1, geom2, <http://www.opengis.net/def/uom/OGC/1.0/degree>)

For both cases i made transformation of geometries in 4326. I did not use ST_Distance_Spheroid, because
i read that it is less accurate and only works for points. I need to check correctness for MonetDB.
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Tue Apr 02 10:24:02 2013 +0300 (2013-04-02)
parents 318ed1e6dd14
children c01f4bcf12bb 8fe210a0e6bd
files generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.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/GeneralDBSqlGeoDistance.java	Tue Apr 02 01:03:35 2013 +0300
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Tue Apr 02 10:24:02 2013 +0300
     1.3 @@ -8,18 +8,18 @@
     1.4    
     1.5  import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
     1.6  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
     1.7 +import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator;
     1.8  
     1.9 -public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricBinary {
    1.10 -
    1.11 -	public GeneralDBSqlGeoDistance(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    1.12 -		super(left, right);
    1.13 +public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricTriple
    1.14 +{
    1.15 +	public GeneralDBSqlGeoDistance(GeneralDBSqlExpr left, GeneralDBSqlExpr right, GeneralDBSqlExpr third)
    1.16 +	{
    1.17 +		super(left, right, third);
    1.18  	}
    1.19  
    1.20  	@Override
    1.21 -	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
    1.22 -		throws X
    1.23 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor) throws X
    1.24  	{
    1.25  		visitor.meet(this);
    1.26  	}
    1.27 -
    1.28  }
    1.29 \ No newline at end of file
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Tue Apr 02 01:03:35 2013 +0300
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Tue Apr 02 10:24:02 2013 +0300
     2.3 @@ -423,12 +423,10 @@
     2.4  		return new GeneralDBSqlGeoArea(expr);
     2.5  	}
     2.6  	
     2.7 -	public static GeneralDBSqlExpr geoDistance(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
     2.8 -
     2.9 -		return new GeneralDBSqlGeoDistance(left, right);
    2.10 +	public static GeneralDBSqlExpr geoDistance(GeneralDBSqlExpr left, GeneralDBSqlExpr right, GeneralDBSqlExpr third) {
    2.11 +		return new GeneralDBSqlGeoDistance(left, right,third);
    2.12  	}
    2.13  	
    2.14 -
    2.15  	//XXX Spatial Property Functions
    2.16  	public static GeneralDBSqlExpr dimension(GeneralDBSqlExpr expr) {
    2.17  
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Tue Apr 02 01:03:35 2013 +0300
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Tue Apr 02 10:24:02 2013 +0300
     3.3 @@ -551,9 +551,8 @@
     3.4  	 * FIXME spatials
     3.5  	 */
     3.6  	@Override
     3.7 -	public void meet(FunctionCall functionCall)
     3.8 -			throws UnsupportedRdbmsOperatorException
     3.9 -			{
    3.10 +	public void meet(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
    3.11 +	{
    3.12  		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
    3.13  
    3.14  		if(function instanceof SpatialConstructFunc)
    3.15 @@ -672,6 +671,7 @@
    3.16  			//TODO
    3.17  			GeneralDBSqlExpr leftArg = null;
    3.18  			GeneralDBSqlExpr rightArg = null;
    3.19 +			GeneralDBSqlExpr thirdArg = null;
    3.20  
    3.21  			ValueExpr left = functionCall.getArgs().get(0);
    3.22  
    3.23 @@ -684,7 +684,7 @@
    3.24  				leftArg = label(left);
    3.25  			}
    3.26  
    3.27 -			//These two functions only have one argument!!
    3.28 +			//Area function has only one argument!!
    3.29  			if(!(function instanceof AreaFunc))
    3.30  			{
    3.31  				ValueExpr right = functionCall.getArgs().get(1);
    3.32 @@ -697,16 +697,16 @@
    3.33  				{
    3.34  					rightArg = label(right);
    3.35  				}
    3.36 +				thirdArg = uri(functionCall.getArgs().get(2));
    3.37  			}
    3.38  
    3.39 -			result = spatialMetricPicker(function, leftArg, rightArg);
    3.40 +			result = spatialMetricPicker(function, leftArg, rightArg, thirdArg);
    3.41  		}
    3.42  		else //default case
    3.43  		{
    3.44  			meetNode(functionCall);
    3.45  		}
    3.46 -
    3.47 -			}
    3.48 +	}
    3.49  
    3.50  	/**
    3.51  	 * Addition for datetime metric functions
    3.52 @@ -890,6 +890,7 @@
    3.53  	{
    3.54  		GeneralDBSqlExpr leftArg = null;
    3.55  		GeneralDBSqlExpr rightArg = null;
    3.56 +		GeneralDBSqlExpr thirdArg = null;
    3.57  
    3.58  		ValueExpr left = functionCall.getArgs().get(0);
    3.59  
    3.60 @@ -903,8 +904,6 @@
    3.61  			leftArg = label(left);
    3.62  		}
    3.63  
    3.64 -
    3.65 -
    3.66  		if(!(function instanceof AreaFunc))
    3.67  		{
    3.68  			ValueExpr right = functionCall.getArgs().get(1);
    3.69 @@ -916,9 +915,10 @@
    3.70  			{
    3.71  				rightArg = label(right);
    3.72  			}
    3.73 +			thirdArg = uri(functionCall.getArgs().get(2));
    3.74  		}
    3.75  
    3.76 -		return spatialMetricPicker(function, leftArg, rightArg);
    3.77 +		return spatialMetricPicker(function, leftArg, rightArg, thirdArg);
    3.78  
    3.79  	}
    3.80  
    3.81 @@ -1218,11 +1218,11 @@
    3.82  	/***/
    3.83  	
    3.84  	//TODO more to be added here probably
    3.85 -	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    3.86 +	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, GeneralDBSqlExpr thirdArg)
    3.87  	{
    3.88  		if(function.getURI().equals(GeoConstants.distance))
    3.89  		{
    3.90 -			return geoDistance(leftArg, rightArg);
    3.91 +			return geoDistance(leftArg, rightArg, thirdArg);
    3.92  		}
    3.93  		else if(function.getURI().equals(GeoConstants.area))
    3.94  		{
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Tue Apr 02 01:03:35 2013 +0300
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Tue Apr 02 10:24:02 2013 +0300
     4.3 @@ -214,6 +214,7 @@
     4.4  
     4.5  		GeneralDBSqlExpr leftArg = null;
     4.6  		GeneralDBSqlExpr rightArg = null;
     4.7 +		GeneralDBSqlExpr thirdArg = null;
     4.8  
     4.9  		ValueExpr left = functionCall.getArgs().get(0);
    4.10  
    4.11 @@ -227,8 +228,6 @@
    4.12  			leftArg = label(left);
    4.13  		}
    4.14  
    4.15 -
    4.16 -
    4.17  		if((function instanceof DistanceFunc))
    4.18  		{
    4.19  			ValueExpr right = functionCall.getArgs().get(1);
    4.20 @@ -240,11 +239,13 @@
    4.21  			{
    4.22  				rightArg = label(right);
    4.23  			}
    4.24 +			
    4.25 +			thirdArg = uri(functionCall.getArgs().get(2));
    4.26  		}
    4.27  
    4.28  		if(function instanceof SpatialMetricFunc)
    4.29  		{
    4.30 -			return spatialMetricPicker(function, leftArg, rightArg);
    4.31 +			return spatialMetricPicker(function, leftArg, rightArg, thirdArg);
    4.32  		}
    4.33  		else //if(functionCall instanceof SpatialPropertyFunc)
    4.34  		{
    4.35 @@ -380,6 +381,7 @@
    4.36  	{
    4.37  		GeneralDBSqlExpr leftArg = null;
    4.38  		GeneralDBSqlExpr rightArg = null;
    4.39 +		GeneralDBSqlExpr thirdArg = null;
    4.40  
    4.41  		ValueExpr left = functionCall.getArgs().get(0);
    4.42  
    4.43 @@ -393,8 +395,6 @@
    4.44  			leftArg = label(left);
    4.45  		}
    4.46  
    4.47 -
    4.48 -
    4.49  		if(!(function instanceof AreaFunc))
    4.50  		{
    4.51  			ValueExpr right = functionCall.getArgs().get(1);
    4.52 @@ -406,10 +406,11 @@
    4.53  			{
    4.54  				rightArg = label(right);
    4.55  			}
    4.56 +
    4.57 +			thirdArg = uri(functionCall.getArgs().get(2));
    4.58  		}
    4.59  
    4.60 -		return spatialMetricPicker(function, leftArg, rightArg);
    4.61 -
    4.62 +		return spatialMetricPicker(function, leftArg, rightArg, thirdArg);
    4.63  	}
    4.64  
    4.65  	GeneralDBSqlExpr spatialPropertyFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
    4.66 @@ -524,11 +525,11 @@
    4.67  	/***/
    4.68  	
    4.69  	//TODO more to be added here probably
    4.70 -	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    4.71 +	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg, GeneralDBSqlExpr thirdArg)
    4.72  	{
    4.73  		if(function.getURI().equals(GeoConstants.distance))
    4.74  		{
    4.75 -			return geoDistance(leftArg, rightArg);
    4.76 +			return geoDistance(leftArg, rightArg, thirdArg);
    4.77  		}
    4.78  		else if(function.getURI().equals(GeoConstants.area))
    4.79  		{
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Apr 02 01:03:35 2013 +0300
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Apr 02 10:24:02 2013 +0300
     5.3 @@ -88,6 +88,7 @@
     5.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
     5.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
     5.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
     5.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricTriple;
     5.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
     5.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
    5.10  import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn;
    5.11 @@ -830,6 +831,14 @@
    5.12  			locateColumnVars(((GeneralDBSqlSpatialMetricBinary)expr).getLeftArg(),allKnown);
    5.13  			locateColumnVars(((GeneralDBSqlSpatialMetricBinary)expr).getRightArg(),allKnown);
    5.14  		}
    5.15 +
    5.16 +		else if(expr instanceof GeneralDBSqlSpatialMetricTriple)
    5.17 +		{
    5.18 +			locateColumnVars(((GeneralDBSqlSpatialMetricTriple)expr).getLeftArg(),allKnown);
    5.19 +			locateColumnVars(((GeneralDBSqlSpatialMetricTriple)expr).getRightArg(),allKnown);
    5.20 +			locateColumnVars(((GeneralDBSqlSpatialMetricTriple)expr).getThirdArg(),allKnown);
    5.21 +		}
    5.22 +
    5.23  		else if(expr instanceof GeneralDBSqlSpatialMetricUnary)
    5.24  		{
    5.25  			locateColumnVars(((GeneralDBSqlSpatialMetricUnary)expr).getArg(),allKnown);
    5.26 @@ -985,13 +994,14 @@
    5.27  		else if(expr instanceof GeneralDBSqlSpatialMetricBinary ||
    5.28  				expr instanceof GeneralDBSqlSpatialMetricUnary ||
    5.29  				expr instanceof GeneralDBSqlMathExpr ||
    5.30 +				expr instanceof GeneralDBSqlSpatialMetricTriple ||
    5.31  				/** Addition for datetime metric functions
    5.32  				 * 
    5.33  				 * @author George Garbis <ggarbis@di.uoa.gr>
    5.34 -				 * 
    5.35 +				 *
    5.36  				 */
    5.37 -				expr instanceof GeneralDBSqlDateTimeMetricBinary 
    5.38 -				/***/) 
    5.39 +				expr instanceof GeneralDBSqlDateTimeMetricBinary
    5.40 +				/***/)
    5.41  		{
    5.42  			return ResultType.DOUBLE;
    5.43  		}
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Tue Apr 02 01:03:35 2013 +0300
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Tue Apr 02 10:24:02 2013 +0300
     6.3 @@ -676,10 +676,6 @@
     6.4  		else if (expr instanceof GeneralDBSqlGeoSymDifference) {
     6.5  			append((GeneralDBSqlGeoSymDifference)expr, filter);
     6.6  		}
     6.7 -		//Metrics
     6.8 -		else if (expr instanceof GeneralDBSqlGeoDistance) {
     6.9 -			append((GeneralDBSqlGeoDistance)expr, filter);
    6.10 -		}
    6.11  		else if (expr instanceof GeneralDBSqlDiffDateTime) {
    6.12  			append((GeneralDBSqlDiffDateTime)expr, filter);
    6.13  		}
    6.14 @@ -691,19 +687,20 @@
    6.15  		}
    6.16  	}
    6.17  
    6.18 -	protected void dispatchTripleSqlOperator(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter)
    6.19 -			throws UnsupportedRdbmsOperatorException
    6.20 -			{
    6.21 +	protected void dispatchTripleSqlOperator(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
    6.22 +	{
    6.23  		if (expr instanceof GeneralDBSqlRelate) {
    6.24  			append((GeneralDBSqlRelate)expr, filter);
    6.25  		}
    6.26 +		//Metrics
    6.27 +		else if (expr instanceof GeneralDBSqlGeoDistance) {
    6.28 +			append((GeneralDBSqlGeoDistance)expr, filter);
    6.29 +		}
    6.30  		else
    6.31  		{
    6.32  			throw unsupported(expr);
    6.33  		}
    6.34 -			}
    6.35 -
    6.36 -
    6.37 +	}
    6.38  
    6.39  	protected void dispatchOther(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter)
    6.40  			throws UnsupportedRdbmsOperatorException
    6.41 @@ -1198,9 +1195,8 @@
    6.42  
    6.43  			}
    6.44  
    6.45 -	protected void appendMetricFunction(GeneralDBSqlExpr constr, GeneralDBSqlExprBuilder filter) 
    6.46 -			throws UnsupportedRdbmsOperatorException
    6.47 -			{
    6.48 +	protected void appendMetricFunction(GeneralDBSqlExpr constr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
    6.49 +	{
    6.50  		if(constr instanceof GeneralDBSqlGeoDistance)
    6.51  		{
    6.52  			append((GeneralDBSqlGeoDistance)constr, filter);
    6.53 @@ -1209,9 +1205,7 @@
    6.54  		{
    6.55  			append((GeneralDBSqlGeoArea)constr, filter);
    6.56  		}
    6.57 -
    6.58 -
    6.59 -			}
    6.60 +	}
    6.61  
    6.62  	/** Addition for datetime metric functions
    6.63  	 * 
     7.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Tue Apr 02 01:03:35 2013 +0300
     7.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Tue Apr 02 10:24:02 2013 +0300
     7.3 @@ -763,11 +763,10 @@
     7.4  	
     7.5  	@Override
     7.6  	//Spatial Metric Functions
     7.7 -	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
     7.8 -			throws UnsupportedRdbmsOperatorException
     7.9 -			{
    7.10 -		appendMonetDBSpatialFunctionBinary(expr, filter, SpatialFunctionsMonetDB.ST_Distance);
    7.11 -			}
    7.12 +	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
    7.13 +	{
    7.14 +		appendMonetDBDistance(expr, filter, SpatialFunctionsMonetDB.ST_Distance);
    7.15 +	}
    7.16  
    7.17  	@Override
    7.18  	protected void append(GeneralDBSqlGeoArea expr, GeneralDBSqlExprBuilder filter)
    7.19 @@ -1325,8 +1324,7 @@
    7.20  			case ST_Intersection: filter.appendFunction("Intersection"); break;
    7.21  			case ST_Union: filter.appendFunction("\"Union\""); break;
    7.22  			case ST_SymDifference: filter.appendFunction("SymDifference"); break;
    7.23 -			case ST_Buffer: filter.appendFunction("Buffer"); break;
    7.24 -			case ST_Distance: filter.appendFunction("Distance"); break;
    7.25 +			case ST_Buffer: filter.appendFunction("Buffer"); break;			
    7.26  			case ST_Touches: filter.appendFunction("Touches"); break;
    7.27  			case ST_Disjoint: filter.appendFunction("Disjoint"); break;
    7.28  			case ST_Crosses: filter.appendFunction("Crosses"); break;
    7.29 @@ -1441,6 +1439,178 @@
    7.30  			filter.append(sridExpr);
    7.31  		}
    7.32  			}
    7.33 +	
    7.34 +		protected void appendMonetDBDistance(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsMonetDB func) throws UnsupportedRdbmsOperatorException
    7.35 +		{
    7.36 +			String units = null;
    7.37 +
    7.38 +			filter.openBracket();
    7.39 +			
    7.40 +			boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
    7.41 +			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
    7.42 +			boolean check3 = expr.getThirdArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.MonetDBSqlNull");
    7.43 +			if(check1)
    7.44 +			{
    7.45 +				this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
    7.46 +			}
    7.47 +			else if(check2)
    7.48 +			{
    7.49 +				this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
    7.50 +			}
    7.51 +			else if(check3)
    7.52 +			{
    7.53 +				this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
    7.54 +			}
    7.55 +			
    7.56 +			else
    7.57 +			{								
    7.58 +				filter.appendFunction("Distance");
    7.59 +				
    7.60 +				filter.openBracket();
    7.61 +				
    7.62 +				if (expr.getThirdArg() instanceof GeneralDBStringValue)
    7.63 +				{			
    7.64 +					String unparsedUnits = ((GeneralDBStringValue)expr.getThirdArg()).getValue();
    7.65 +
    7.66 +					units = unparsedUnits.substring(unparsedUnits.lastIndexOf('/')+1);
    7.67 +					if(units.equals("metre") || units.equals("meter"))
    7.68 +					{					
    7.69 +						filter.appendFunction("GEOGRAPHY");
    7.70 +						filter.openBracket();
    7.71 +						filter.appendFunction("ST_TRANSFORM");
    7.72 +						filter.openBracket();
    7.73 +					}	
    7.74 +					else if(units.equals("degree"))
    7.75 +					{
    7.76 +						filter.appendFunction("ST_TRANSFORM");
    7.77 +						filter.openBracket();
    7.78 +					}	
    7.79 +				}	
    7.80 +				
    7.81 +				if(expr.getLeftArg() instanceof GeneralDBStringValue)
    7.82 +				{
    7.83 +					appendWKT(expr.getLeftArg(),filter);
    7.84 +				}
    7.85 +				else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
    7.86 +				{
    7.87 +					appendConstructFunction(expr.getLeftArg(), filter);
    7.88 +				}
    7.89 +				else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
    7.90 +				{
    7.91 +					appendConstructFunction(expr.getLeftArg(), filter);
    7.92 +				}
    7.93 +				else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
    7.94 +				{
    7.95 +					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
    7.96 +					appendMBB(onlyLabel,filter); 
    7.97 +				}
    7.98 +				else
    7.99 +				{
   7.100 +					appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   7.101 +				}
   7.102 +				
   7.103 +				if(units.equals("metre") || units.equals("meter"))
   7.104 +				{					
   7.105 +					filter.appendComma();
   7.106 +					filter.append("4326");
   7.107 +					filter.closeBracket(); //close st_transform
   7.108 +					filter.closeBracket(); //close geography
   7.109 +					
   7.110 +					filter.appendComma();
   7.111 +
   7.112 +					filter.appendFunction("GEOGRAPHY");
   7.113 +					filter.openBracket();
   7.114 +					filter.appendFunction("ST_TRANSFORM");
   7.115 +					filter.openBracket();				
   7.116 +				}
   7.117 +				else if(units.equals("degree"))
   7.118 +				{
   7.119 +					filter.appendComma();
   7.120 +					filter.append("4326");
   7.121 +					filter.closeBracket(); //close st_transform
   7.122 +					
   7.123 +					filter.appendComma();
   7.124 +					
   7.125 +					filter.appendFunction("ST_TRANSFORM");
   7.126 +					filter.openBracket();
   7.127 +				}	
   7.128 +				else
   7.129 +				{
   7.130 +					filter.appendComma();
   7.131 +				}																
   7.132 +				
   7.133 +				if(expr.getRightArg() instanceof GeneralDBStringValue)
   7.134 +				{
   7.135 +					appendWKT(expr.getRightArg(),filter);
   7.136 +				}
   7.137 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   7.138 +				{
   7.139 +					appendConstructFunction(expr.getRightArg(), filter);
   7.140 +				}
   7.141 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   7.142 +				{
   7.143 +					appendConstructFunction(expr.getRightArg(), filter);
   7.144 +				}
   7.145 +				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   7.146 +				{
   7.147 +					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   7.148 +					appendMBB(onlyLabel,filter);					 
   7.149 +				}
   7.150 +				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   7.151 +				{
   7.152 +					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   7.153 +				}
   7.154 +				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   7.155 +				{
   7.156 +					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   7.157 +				}
   7.158 +				else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
   7.159 +				{
   7.160 +					filter.keepSRID_part1();
   7.161 +					append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   7.162 +					filter.keepSRID_part2();
   7.163 +					append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   7.164 +					filter.keepSRID_part3();
   7.165 +				}
   7.166 +				//case met in buffer when in select -> buffer(?spatial,?thematic)
   7.167 +				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   7.168 +				{
   7.169 +					appendWithCastDouble(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   7.170 +					//					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   7.171 +					//					appendCastToDouble(filter);
   7.172 +				}
   7.173 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   7.174 +				{
   7.175 +					appendMetricFunction(expr.getRightArg(), filter);
   7.176 +				}
   7.177 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   7.178 +				{
   7.179 +					appendMetricFunction(expr.getRightArg(), filter);
   7.180 +				}
   7.181 +				else
   7.182 +				{
   7.183 +					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   7.184 +				}
   7.185 +
   7.186 +				if(units.equals("metre") || units.equals("meter"))
   7.187 +				{
   7.188 +					filter.appendComma();
   7.189 +					filter.append("4326");
   7.190 +					filter.closeBracket();
   7.191 +					filter.closeBracket();
   7.192 +				}
   7.193 +				else if(units.equals("degree"))
   7.194 +				{
   7.195 +					filter.appendComma();
   7.196 +					filter.append("4326");
   7.197 +					filter.closeBracket();
   7.198 +				}
   7.199 +
   7.200 +				filter.closeBracket();
   7.201 +			}
   7.202 +
   7.203 +			filter.closeBracket();
   7.204 +		}
   7.205  
   7.206  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 
   7.207  	protected void appendMonetDBSpatialFunctionUnary(UnaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsMonetDB func)
     8.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Apr 02 01:03:35 2013 +0300
     8.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Apr 02 10:24:02 2013 +0300
     8.3 @@ -58,6 +58,7 @@
     8.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
     8.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
     8.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
     8.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricTriple;
     8.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
     8.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
    8.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouches;
    8.11 @@ -339,6 +340,7 @@
    8.12  	public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException
    8.13  	{
    8.14  		if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 
    8.15 +				&&!(expr instanceof GeneralDBSqlSpatialMetricTriple)
    8.16  				&&!(expr instanceof GeneralDBSqlSpatialMetricUnary)
    8.17  				&&!(expr instanceof GeneralDBSqlMathExpr)
    8.18  				&&!(expr instanceof GeneralDBSqlSpatialProperty))
    8.19 @@ -357,6 +359,10 @@
    8.20  		{
    8.21  			dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select);
    8.22  		}
    8.23 +		else if(expr instanceof GeneralDBSqlSpatialMetricTriple)
    8.24 +		{
    8.25 +			dispatchTripleSqlOperator((GeneralDBSqlSpatialMetricTriple) expr, query.select);
    8.26 +		}
    8.27  		//SRID support must be explicitly added!
    8.28  
    8.29  		return this;
    8.30 @@ -756,11 +762,10 @@
    8.31  	
    8.32  	//Spatial Metric Functions
    8.33  	@Override
    8.34 -	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
    8.35 -			throws UnsupportedRdbmsOperatorException
    8.36 -			{
    8.37 -		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Distance);
    8.38 -			}
    8.39 +	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
    8.40 +	{
    8.41 +		appendDistance(expr, filter, SpatialFunctionsPostGIS.ST_Distance);
    8.42 +	}
    8.43  
    8.44  	@Override
    8.45  	protected void append(GeneralDBSqlGeoArea expr, GeneralDBSqlExprBuilder filter)
    8.46 @@ -1279,8 +1284,7 @@
    8.47  			filter.appendComma();
    8.48  			filter.append(sridExpr);
    8.49  		}
    8.50 -
    8.51 -			}
    8.52 +	}
    8.53  
    8.54  	/** Addition for datetime metric functions
    8.55  	 * 
    8.56 @@ -1405,7 +1409,7 @@
    8.57  		String sridExpr = null;
    8.58  
    8.59  		filter.openBracket();
    8.60 -
    8.61 +		
    8.62  		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
    8.63  		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
    8.64  
    8.65 @@ -1480,7 +1484,6 @@
    8.66  			case ST_Union: filter.appendFunction("ST_Union"); break;
    8.67  			case ST_SymDifference: filter.appendFunction("ST_SymDifference"); break;
    8.68  			case ST_Buffer: filter.appendFunction("ST_Buffer"); break;
    8.69 -			case ST_Distance: filter.appendFunction("ST_Distance"); break;
    8.70  			
    8.71  			case ST_Equals: filter.appendFunction("ST_Equals"); break;
    8.72  			case ST_Disjoint: filter.appendFunction("ST_Disjoint"); break;
    8.73 @@ -1490,9 +1493,8 @@
    8.74  			case ST_Within: filter.appendFunction("ST_Within"); break;
    8.75  			case ST_Contains: filter.appendFunction("ST_Contains"); break;
    8.76  			case ST_Overlaps: filter.appendFunction("ST_Overlaps"); break;
    8.77 -			
    8.78  			}
    8.79 -			
    8.80 +
    8.81  			filter.openBracket();
    8.82  			if(expr.getLeftArg() instanceof GeneralDBStringValue)
    8.83  			{
    8.84 @@ -1517,7 +1519,6 @@
    8.85  			}
    8.86  			filter.appendComma();
    8.87  
    8.88 -
    8.89  			if(expr.getRightArg() instanceof GeneralDBStringValue)
    8.90  			{
    8.91  				appendWKT(expr.getRightArg(),filter);
    8.92 @@ -1570,7 +1571,6 @@
    8.93  				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
    8.94  			}
    8.95  
    8.96 -
    8.97  			filter.closeBracket();
    8.98  			//SRID Support
    8.99  			if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
   8.100 @@ -1589,8 +1589,172 @@
   8.101  			filter.appendComma();
   8.102  			filter.append(sridExpr);
   8.103  		}
   8.104 +	}
   8.105  
   8.106 +	//Distance function
   8.107 +	protected void appendDistance(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) throws UnsupportedRdbmsOperatorException
   8.108 +	{
   8.109 +		String units = null;
   8.110 +		
   8.111 +		filter.openBracket();
   8.112 +
   8.113 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   8.114 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   8.115 +		boolean check3 = expr.getThirdArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   8.116 +
   8.117 +		if(check1)
   8.118 +		{
   8.119 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   8.120 +
   8.121 +		}
   8.122 +		else if(check2)
   8.123 +		{
   8.124 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   8.125 +		}
   8.126 +		else if(check3)
   8.127 +		{
   8.128 +			this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
   8.129 +
   8.130 +		}
   8.131 +		else
   8.132 +		{						
   8.133 +			filter.appendFunction("ST_Distance");
   8.134 +
   8.135 +			filter.openBracket();
   8.136 +	
   8.137 +			if (expr.getThirdArg() instanceof GeneralDBStringValue)
   8.138 +			{			
   8.139 +				String unparsedUnits = ((GeneralDBStringValue)expr.getThirdArg()).getValue();
   8.140 +
   8.141 +				units = unparsedUnits.substring(unparsedUnits.lastIndexOf('/')+1);
   8.142 +				if(units.equals("metre") || units.equals("meter"))
   8.143 +				{					
   8.144 +					filter.appendFunction("GEOGRAPHY");
   8.145 +					filter.openBracket();
   8.146 +					filter.appendFunction("ST_TRANSFORM");
   8.147 +					filter.openBracket();
   8.148 +				}
   8.149 +				else if(units.equals("degree"))
   8.150 +				{
   8.151 +					filter.appendFunction("ST_TRANSFORM");
   8.152 +					filter.openBracket();
   8.153 +				}	
   8.154 +			}	
   8.155 +			
   8.156 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
   8.157 +			{
   8.158 +				appendWKT(expr.getLeftArg(),filter);
   8.159  			}
   8.160 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
   8.161 +			{
   8.162 +				appendConstructFunction(expr.getLeftArg(), filter);
   8.163 +			}
   8.164 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
   8.165 +			{
   8.166 +				appendConstructFunction(expr.getLeftArg(), filter);
   8.167 +			}
   8.168 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
   8.169 +			{
   8.170 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
   8.171 +				appendMBB(onlyLabel,filter);
   8.172 +			}
   8.173 +			else
   8.174 +			{
   8.175 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   8.176 +			}
   8.177 +
   8.178 +			if(units.equals("metre") || units.equals("meter"))
   8.179 +			{					
   8.180 +				filter.appendComma();
   8.181 +				filter.append("4326");
   8.182 +				filter.closeBracket(); //close st_transform
   8.183 +				filter.closeBracket(); //close geography
   8.184 +				
   8.185 +				filter.appendComma();
   8.186 +
   8.187 +				filter.appendFunction("GEOGRAPHY");
   8.188 +				filter.openBracket();
   8.189 +				filter.appendFunction("ST_TRANSFORM");
   8.190 +				filter.openBracket();				
   8.191 +			}
   8.192 +			else if(units.equals("degree"))
   8.193 +			{
   8.194 +				filter.appendComma();
   8.195 +				filter.append("4326");
   8.196 +				filter.closeBracket(); //close st_transform
   8.197 +				
   8.198 +				filter.appendComma();
   8.199 +				
   8.200 +				filter.appendFunction("ST_TRANSFORM");
   8.201 +				filter.openBracket();
   8.202 +			}	
   8.203 +			else
   8.204 +			{
   8.205 +				filter.appendComma();
   8.206 +			}	
   8.207 +			
   8.208 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
   8.209 +			{
   8.210 +				appendWKT(expr.getRightArg(),filter);
   8.211 +			}
   8.212 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   8.213 +			{
   8.214 +				appendConstructFunction(expr.getRightArg(), filter);
   8.215 +			}
   8.216 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   8.217 +			{
   8.218 +				appendConstructFunction(expr.getRightArg(), filter);
   8.219 +			}
   8.220 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   8.221 +			{
   8.222 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   8.223 +				appendMBB(onlyLabel,filter);
   8.224 +			}						
   8.225 +			else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
   8.226 +			{
   8.227 +				filter.keepSRID_part1();
   8.228 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   8.229 +				filter.keepSRID_part2();
   8.230 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   8.231 +				filter.keepSRID_part3();
   8.232 +			}
   8.233 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   8.234 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   8.235 +			{
   8.236 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   8.237 +				appendCastToDouble(filter);
   8.238 +			}
   8.239 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   8.240 +			{
   8.241 +				appendMetricFunction(expr.getRightArg(), filter);
   8.242 +			}
   8.243 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   8.244 +			{
   8.245 +				appendMetricFunction(expr.getRightArg(), filter);
   8.246 +			}
   8.247 +			else
   8.248 +			{
   8.249 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   8.250 +			}
   8.251 +
   8.252 +			if(units.equals("metre") || units.equals("meter"))
   8.253 +			{
   8.254 +				filter.appendComma();
   8.255 +				filter.append("4326");
   8.256 +				filter.closeBracket();
   8.257 +				filter.closeBracket();
   8.258 +			}
   8.259 +			else if(units.equals("degree"))
   8.260 +			{
   8.261 +				filter.appendComma();
   8.262 +				filter.append("4326");
   8.263 +				filter.closeBracket();
   8.264 +			}	
   8.265 +
   8.266 +			filter.closeBracket();
   8.267 +		}
   8.268 +		filter.closeBracket();
   8.269 +	}
   8.270  
   8.271  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 
   8.272  	protected void appendGeneralDBSpatialFunctionUnary(UnaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)