Strabon

changeset 1436:1f370b2e7e9c

#74 fixed: now when a constant appears inside a spatial function, it is transformed to 4326.
Special case when both arguments are constants, no transformation is done, since the user
is responsible to give geometries expressed in the same reference system.
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Wed Oct 22 12:31:13 2014 +0300 (2014-10-22)
parents 04dad6cae27c
children 0f5d155b0feb
files 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/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Tue Oct 14 12:44:19 2014 +0300
     1.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Wed Oct 22 12:31:13 2014 +0300
     1.3 @@ -965,6 +965,19 @@
     1.4  		return raw;
     1.5  	}
     1.6  
     1.7 +	protected String appendConstantWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter)
     1.8 +	{
     1.9 +		GeneralDBStringValue arg = (GeneralDBStringValue) expr;
    1.10 +		String raw = arg.getValue();
    1.11 +
    1.12 +		AbstractWKT wkt = new AbstractWKT(raw);
    1.13 +		filter.append("Transform(");
    1.14 +		filter.append(" GeomFromText('" + wkt.getWKT() + "'," + String.valueOf(GeoConstants.defaultSRID) + ")");
    1.15 +		filter.append(", "+GeoConstants.defaultSRID +")");
    1.16 +
    1.17 +		return raw;
    1.18 +	}
    1.19 +	
    1.20  	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
    1.21  	protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter)
    1.22  			throws UnsupportedRdbmsOperatorException
    1.23 @@ -1319,7 +1332,9 @@
    1.24  			}
    1.25  			/////
    1.26  
    1.27 -
    1.28 +			//case where both arguments are constnats
    1.29 +			boolean constantArgs = false;	
    1.30 + 
    1.31  			switch(func)
    1.32  			{
    1.33  			//XXX Careful: ST_Transform support MISSING!!!
    1.34 @@ -1340,7 +1355,15 @@
    1.35  			filter.openBracket();
    1.36  			if(expr.getLeftArg() instanceof GeneralDBStringValue)
    1.37  			{
    1.38 -				appendWKT(expr.getLeftArg(),filter);
    1.39 +				if(expr.getRightArg() instanceof GeneralDBStringValue)
    1.40 +				{	
    1.41 +					//both arguments are constants so we do not need
    1.42 +					//to transform the geometries to WGS84
    1.43 +					constantArgs = true;
    1.44 +					appendWKT(expr.getLeftArg(), filter);
    1.45 +				}
    1.46 +				else
    1.47 +					appendConstantWKT(expr.getLeftArg(), filter);
    1.48  			}
    1.49  			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
    1.50  			{
    1.51 @@ -1369,7 +1392,12 @@
    1.52  			{
    1.53  				if(expr.getRightArg() instanceof GeneralDBStringValue)
    1.54  				{
    1.55 -					appendWKT(expr.getRightArg(),filter);
    1.56 +					if(constantArgs == true)
    1.57 +						// both arguments are constants, so we do not need
    1.58 +						// to transform the geometries to WGS84
    1.59 +						appendWKT(expr.getRightArg(), filter);
    1.60 +					else
    1.61 +						appendConstantWKT(expr.getRightArg(),filter);
    1.62  				}
    1.63  				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
    1.64  				{
     2.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Oct 14 12:44:19 2014 +0300
     2.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Wed Oct 22 12:31:13 2014 +0300
     2.3 @@ -1009,6 +1009,21 @@
     2.4  		return raw;
     2.5  	}
     2.6  
     2.7 +	protected String appendConstantWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter) throws UnsupportedRdbmsOperatorException
     2.8 +	{
     2.9 +		GeneralDBStringValue arg = (GeneralDBStringValue) expr;
    2.10 +		String raw = arg.getValue();
    2.11 +		
    2.12 +		// parse raw WKT
    2.13 +		AbstractWKT wkt = new AbstractWKT(raw);
    2.14 +		// transform constant geometry to the default SRID
    2.15 +		filter.append("ST_Transform(");
    2.16 +		filter.append(" ST_GeomFromText('" + wkt.getWKT() + "'," + String.valueOf(wkt.getSRID()) + ")");
    2.17 +		filter.append(", "+GeoConstants.defaultSRID +")");
    2.18 +		
    2.19 +		return raw;
    2.20 +	}
    2.21 +	
    2.22  	//Used in all the generaldb boolean spatial functions of the form ?GEO1 ~ ?GEO2 
    2.23  	//	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
    2.24  	//	{
    2.25 @@ -1531,7 +1546,8 @@
    2.26  			}
    2.27  			/////
    2.28  
    2.29 -
    2.30 +			//case where both arguments are constnats
    2.31 +			boolean constantArgs = false;	
    2.32  
    2.33  			switch(func)
    2.34  			{
    2.35 @@ -1540,7 +1556,6 @@
    2.36  			case ST_Intersection: filter.appendFunction("ST_Intersection"); break;
    2.37  			case ST_Union: filter.appendFunction("ST_Union"); break;
    2.38  			case ST_SymDifference: filter.appendFunction("ST_SymDifference"); break;
    2.39 -			case ST_Buffer: filter.appendFunction("ST_Buffer"); break;
    2.40  			
    2.41  			// PostGIS
    2.42  			case ST_MakeLine: filter.appendFunction("ST_MakeLine"); break;
    2.43 @@ -1558,7 +1573,15 @@
    2.44  			filter.openBracket();
    2.45  			if(expr.getLeftArg() instanceof GeneralDBStringValue)
    2.46  			{
    2.47 -				appendWKT(expr.getLeftArg(),filter);
    2.48 +				if(expr.getRightArg() instanceof GeneralDBStringValue)
    2.49 +				{	
    2.50 +					//both arguments are constants so we do not need
    2.51 +					//to transform the geometries to WGS84
    2.52 +					constantArgs = true;
    2.53 +					appendWKT(expr.getLeftArg(), filter);
    2.54 +				}
    2.55 +				else
    2.56 +					appendConstantWKT(expr.getLeftArg(), filter);
    2.57  			}
    2.58  			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
    2.59  			{
    2.60 @@ -1585,7 +1608,12 @@
    2.61  
    2.62  			if(expr.getRightArg() instanceof GeneralDBStringValue)
    2.63  			{
    2.64 -				appendWKT(expr.getRightArg(),filter);
    2.65 +				if(constantArgs == true)
    2.66 +					// both arguments are constants, so we do not need
    2.67 +					// to transform the geometries to WGS84
    2.68 +					appendWKT(expr.getRightArg(), filter);
    2.69 +				else
    2.70 +					appendConstantWKT(expr.getRightArg(),filter);
    2.71  			}
    2.72  			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
    2.73  			{