Strabon
changeset 1404:1b3558b9e2e8
a lot of refactoring and cleaning in GeneralDBEvaluation.evaluate(FunctionCall, BindingSet) + support of grounded ST_Centroid in SELECT (ST_MakeLine is still missing)
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialConstructFunc.java Sat Sep 20 19:36:24 2014 +0300 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialConstructFunc.java Sun Sep 21 00:02:12 2014 +0300 1.3 @@ -28,9 +28,7 @@ 1.4 public abstract class SpatialConstructFunc implements Function { 1.5 1.6 //No need for any implementation, I will have replaced this class's presence before reaching this place 1.7 - public Value evaluate(ValueFactory valueFactory, Value... args) 1.8 - throws ValueExprEvaluationException { 1.9 - 1.10 + public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { 1.11 return null; 1.12 } 1.13
2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Sat Sep 20 19:36:24 2014 +0300 2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Sun Sep 21 00:02:12 2014 +0300 2.3 @@ -95,15 +95,17 @@ 2.4 * @param geo 2.5 * @throws Exception 2.6 */ 2.7 - public StrabonPolyhedron(Geometry geo) throws Exception { 2.8 - this.geometry = new StrabonPolyhedron(geo, 1).geometry; 2.9 + public StrabonPolyhedron(Geometry geo) { 2.10 + this.geometry = geo; 2.11 this.geometry.setSRID(geo.getSRID()); 2.12 } 2.13 2.14 /** 2.15 * Creates a {@link StrabonPolyhedron} instance with a geometry given 2.16 * in the representation of the argument. The representation could be 2.17 - * either in WKT or in GML. 2.18 + * either in WKT or in GML. Since, we construct the {@link Geometry} 2.19 + * object ourselves there is no way of knowing the SRID, so the 2.20 + * constructor requires it as well. 2.21 * 2.22 * NOTICE: whoever creates StrabonPolyhedron objects is responsible 2.23 * for cleaning the representation of the geometry by removing any 2.24 @@ -112,7 +114,7 @@ 2.25 * @param representation 2.26 * @throws Exception 2.27 */ 2.28 - public StrabonPolyhedron(String representation) throws ParseException { 2.29 + public StrabonPolyhedron(String representation, int srid) throws ParseException { 2.30 try { 2.31 // try first as WKT 2.32 geometry = jts.WKTread(representation); 2.33 @@ -126,6 +128,9 @@ 2.34 throw new ParseException("The given WKT/GML representation is not valid."); 2.35 } 2.36 } 2.37 + 2.38 + // set its SRID 2.39 + geometry.setSRID(srid); 2.40 } 2.41 2.42 /** 2.43 @@ -175,28 +180,9 @@ 2.44 return false; 2.45 } 2.46 2.47 + // unused 2.48 @Deprecated 2.49 - public StrabonPolyhedron(String WKT, int algorithm) throws Exception { 2.50 - if(WKT.contains("gml")) 2.51 - { 2.52 - Geometry geo = jts.GMLread(WKT); 2.53 - this.geometry = new StrabonPolyhedron(geo).geometry; 2.54 - } 2.55 - else 2.56 - { 2.57 - Geometry geo = jts.WKTread(WKT); 2.58 - this.geometry = new StrabonPolyhedron(geo, algorithm).geometry; 2.59 - } 2.60 - 2.61 - } 2.62 - 2.63 - @Deprecated 2.64 - public StrabonPolyhedron(Geometry geo, int algorithm) throws Exception { 2.65 - this.geometry = new StrabonPolyhedron(geo, algorithm, MAX_POINTS).geometry; 2.66 - } 2.67 - 2.68 - // unused 2.69 - public StrabonPolyhedron(Geometry geo, int algorithm, int maxPoints) throws Exception { 2.70 + private StrabonPolyhedron(Geometry geo, int algorithm, int maxPoints) throws Exception { 2.71 if (geo.isEmpty()) { 2.72 this.geometry = geo; 2.73 return; 2.74 @@ -860,4 +846,22 @@ 2.75 GeometryCollection.class.isInstance(geo) ? "GeometryCollection" : 2.76 "Unknown"; 2.77 } 2.78 + 2.79 + 2.80 + /*** 2.81 + * Additions by charnik. 2.82 + * Why all the above operations (symdifference, boundary, etc.) are static methods 2.83 + * and not member methods? 2.84 + */ 2.85 + 2.86 + /** 2.87 + * Returns the centroid of this StrabonPolyhedron as 2.88 + * a new StrabonPolyhedron. 2.89 + * 2.90 + * @return 2.91 + */ 2.92 + public StrabonPolyhedron getCentroid() { 2.93 + Point point = geometry.getCentroid(); 2.94 + return new StrabonPolyhedron(point); 2.95 + } 2.96 }
3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/postgis/construct/Centroid.java Sat Sep 20 19:36:24 2014 +0300 3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/postgis/construct/Centroid.java Sun Sep 21 00:02:12 2014 +0300 3.3 @@ -27,5 +27,4 @@ 3.4 public String getURI() { 3.5 return PostGIS.ST_CENTROID; 3.6 } 3.7 - 3.8 }
4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Sat Sep 20 19:36:24 2014 +0300 4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Sun Sep 21 00:02:12 2014 +0300 4.3 @@ -20,10 +20,11 @@ 4.4 4.5 import org.openrdf.model.Literal; 4.6 import org.openrdf.model.Value; 4.7 +import org.openrdf.model.ValueFactory; 4.8 import org.openrdf.model.impl.BooleanLiteralImpl; 4.9 import org.openrdf.model.impl.LiteralImpl; 4.10 -import org.openrdf.model.impl.NumericLiteralImpl; 4.11 import org.openrdf.model.impl.URIImpl; 4.12 +import org.openrdf.model.impl.ValueFactoryImpl; 4.13 import org.openrdf.query.BindingSet; 4.14 import org.openrdf.query.Dataset; 4.15 import org.openrdf.query.QueryEvaluationException; 4.16 @@ -51,6 +52,8 @@ 4.17 import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 4.18 import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 4.19 import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.property.GeoSparqlGetSRIDFunc; 4.20 +import org.openrdf.query.algebra.evaluation.function.spatial.postgis.construct.Centroid; 4.21 +import org.openrdf.query.algebra.evaluation.function.spatial.postgis.construct.MakeLine; 4.22 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc; 4.23 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.DistanceFunc; 4.24 import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.AsGMLFunc; 4.25 @@ -128,6 +131,7 @@ 4.26 import org.slf4j.LoggerFactory; 4.27 4.28 import com.vividsolutions.jts.geom.Geometry; 4.29 +import com.vividsolutions.jts.geom.LineString; 4.30 import com.vividsolutions.jts.io.ParseException; 4.31 4.32 import eu.earthobservatory.constants.GeoConstants; 4.33 @@ -253,6 +257,13 @@ 4.34 4.35 /** 4.36 * Had to use it for the cases met in group by (Union as an aggregate) 4.37 + * 4.38 + * There is a lot of work here to be done for refactoring the code. 4.39 + * For example, while it returns a Value, that value might be a 4.40 + * StrabonPolyhedron and thus we have lost the datatype of the input 4.41 + * geometries (constant or GeneralDBPolyhedron -- database values). 4.42 + * Therefore, later on, when the writer iterates over the results, it 4.43 + * has to select the default WKT datatype for StrabonPolyhedron values. 4.44 */ 4.45 @Override 4.46 public Value evaluate(FunctionCall fc, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException 4.47 @@ -306,106 +317,32 @@ 4.48 if (function instanceof SpatialMetricFunc) 4.49 { 4.50 double funcResult = 0; 4.51 - Geometry leftGeom = null; 4.52 - Geometry rightGeom = null; 4.53 - if(leftResult instanceof StrabonPolyhedron) 4.54 - { 4.55 - leftGeom = ((StrabonPolyhedron) leftResult).getGeometry(); 4.56 - } 4.57 - else if(leftResult instanceof GeneralDBPolyhedron) 4.58 - { 4.59 - leftGeom = ((GeneralDBPolyhedron) leftResult).getPolyhedron().getGeometry(); 4.60 - } 4.61 - else if(leftResult instanceof Literal) 4.62 - { 4.63 - /** 4.64 - * Duplicate work done here in order to retain the literal's datatype... 4.65 - * Instead of only utilizing StrabonPolyhedron items, I converted them to Literals 4.66 - * in order to have them appear in Select Clause along with the appropriate datatype. 4.67 - */ 4.68 - leftGeom = new StrabonPolyhedron(((Literal) leftResult).getLabel()).getGeometry(); 4.69 - int sridPosition = ((Literal) leftResult).getLabel().indexOf(';'); 4.70 - //Default case 4.71 - if(sridPosition == -1) 4.72 - { 4.73 - leftGeom.setSRID(GeoConstants.defaultSRID); 4.74 - } 4.75 - else 4.76 - { 4.77 - sridPosition = ((Literal) leftResult).getLabel().lastIndexOf('/'); 4.78 - int srid = Integer.parseInt(((Literal) leftResult).getLabel().substring(sridPosition+1)); 4.79 - leftGeom.setSRID(srid); 4.80 - } 4.81 - } 4.82 - else 4.83 - { //SHOULD NEVER REACH THIS CASE! 4.84 - return null; 4.85 - } 4.86 - 4.87 - 4.88 - if(rightResult != null) 4.89 - { 4.90 - if(rightResult instanceof StrabonPolyhedron) 4.91 - { 4.92 - rightGeom = ((StrabonPolyhedron) rightResult).getGeometry(); 4.93 - } 4.94 - else if(rightResult instanceof GeneralDBPolyhedron) 4.95 - { 4.96 - rightGeom = ((GeneralDBPolyhedron) rightResult).getPolyhedron().getGeometry(); 4.97 - } 4.98 - else if(rightResult instanceof Literal) 4.99 - { 4.100 - /** 4.101 - * Duplicate work done here in order to retain the literal's datatype... 4.102 - * Instead of only utilizing StrabonPolyhedron items, I converted them to Literals 4.103 - * in order to have them appear in Select Clause along with the appropriate datatype. 4.104 - */ 4.105 - rightGeom = new StrabonPolyhedron(((Literal) rightResult).getLabel()).getGeometry(); 4.106 - int sridPosition = ((Literal) rightResult).getLabel().indexOf(';'); 4.107 - //Default case 4.108 - if(sridPosition == -1) 4.109 - { 4.110 - rightGeom.setSRID(GeoConstants.defaultSRID); 4.111 - } 4.112 - else 4.113 - { 4.114 - sridPosition = ((Literal) rightResult).getLabel().lastIndexOf('/'); 4.115 - int srid = Integer.parseInt(((Literal) rightResult).getLabel().substring(sridPosition+1)); 4.116 - rightGeom.setSRID(srid); 4.117 - } 4.118 - } 4.119 - else 4.120 - { //SHOULD NEVER REACH THIS CASE! 4.121 - return null; 4.122 - } 4.123 - } 4.124 - else 4.125 - { 4.126 - //it's ok, maybe this is a non-binary function! 4.127 - } 4.128 - 4.129 + Geometry leftGeom = getValueAsStrabonPolyhedron(leftResult).getGeometry(); 4.130 4.131 if(function instanceof AreaFunc) 4.132 { 4.133 funcResult = leftGeom.getArea(); 4.134 - } 4.135 - if(function instanceof DistanceFunc) 4.136 + } 4.137 + else if(function instanceof DistanceFunc) 4.138 { 4.139 + // get the second geometry 4.140 + Geometry rightGeom = getValueAsStrabonPolyhedron(rightResult).getGeometry(); 4.141 + 4.142 int targetSRID = leftGeom.getSRID(); 4.143 int sourceSRID = rightGeom.getSRID(); 4.144 Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.145 funcResult = leftGeom.distance(rightConverted); 4.146 } 4.147 - return org.openrdf.model.impl.ValueFactoryImpl.getInstance().createLiteral(funcResult); 4.148 + 4.149 + return ValueFactoryImpl.getInstance().createLiteral(funcResult); 4.150 4.151 } 4.152 4.153 // 4.154 // SPATIAL CONSTRUCT FUNCTIONS 4.155 // 4.156 - else if ( function instanceof SpatialConstructFunc ) { 4.157 + else if (function instanceof SpatialConstructFunc) { 4.158 return spatialConstructPicker(function, leftResult, rightResult); 4.159 - 4.160 } 4.161 4.162 // 4.163 @@ -416,224 +353,114 @@ 4.164 4.165 boolean funcResult = false; 4.166 4.167 - //For the time being I only include stSPARQL ones 4.168 - Geometry leftGeom = null; 4.169 - Geometry rightGeom = null; 4.170 + // get the geometries and the SRIDs of the left/right arguments 4.171 + Geometry leftGeom = getValueAsStrabonPolyhedron(leftResult).getGeometry(); 4.172 + Geometry rightGeom = getValueAsStrabonPolyhedron(rightResult).getGeometry(); 4.173 + int targetSRID = leftGeom.getSRID(); 4.174 + int sourceSRID = rightGeom.getSRID(); 4.175 4.176 - if(leftResult instanceof StrabonPolyhedron) 4.177 - { 4.178 - leftGeom = ((StrabonPolyhedron) leftResult).getGeometry(); 4.179 - } 4.180 - else if(leftResult instanceof GeneralDBPolyhedron) 4.181 - { 4.182 - leftGeom = ((GeneralDBPolyhedron) leftResult).getPolyhedron().getGeometry(); 4.183 - } 4.184 - else if(leftResult instanceof Literal) 4.185 - { 4.186 - /** 4.187 - * Duplicate work done here in order to retain the literal's datatype... 4.188 - * Instead of only utilizing StrabonPolyhedron items, I converted them to Literals 4.189 - * in order to have them appear in Select Clause along with the appropriate datatype. 4.190 - */ 4.191 - leftGeom = new StrabonPolyhedron(((Literal) leftResult).getLabel()).getGeometry(); 4.192 - int sridPosition = ((Literal) leftResult).getLabel().indexOf(';'); 4.193 - //Default case 4.194 - if(sridPosition == -1) 4.195 - { 4.196 - leftGeom.setSRID(GeoConstants.defaultSRID); 4.197 - } 4.198 - else 4.199 - { 4.200 - sridPosition = ((Literal) leftResult).getLabel().lastIndexOf('/'); 4.201 - int srid = Integer.parseInt(((Literal) leftResult).getLabel().substring(sridPosition+1)); 4.202 - leftGeom.setSRID(srid); 4.203 - } 4.204 - } 4.205 - else 4.206 - { //SHOULD NEVER REACH THIS CASE! 4.207 - return null; 4.208 - } 4.209 - 4.210 - if(rightResult instanceof StrabonPolyhedron) 4.211 - { 4.212 - rightGeom = ((StrabonPolyhedron) rightResult).getGeometry(); 4.213 - } 4.214 - else if(rightResult instanceof GeneralDBPolyhedron) 4.215 - { 4.216 - rightGeom = ((GeneralDBPolyhedron) rightResult).getPolyhedron().getGeometry(); 4.217 - } 4.218 - else if(rightResult instanceof Literal) 4.219 - { 4.220 - /** 4.221 - * Duplicate work done here in order to retain the literal's datatype... 4.222 - * Instead of only utilizing StrabonPolyhedron items, I converted them to Literals 4.223 - * in order to have them appear in Select Clause along with the appropriate datatype. 4.224 - */ 4.225 - rightGeom = new StrabonPolyhedron(((Literal) rightResult).getLabel()).getGeometry(); 4.226 - int sridPosition = ((Literal) rightResult).getLabel().indexOf(';'); 4.227 - //Default case 4.228 - if(sridPosition == -1) 4.229 - { 4.230 - rightGeom.setSRID(GeoConstants.defaultSRID); 4.231 - } 4.232 - else 4.233 - { 4.234 - sridPosition = ((Literal) rightResult).getLabel().lastIndexOf('/'); 4.235 - int srid = Integer.parseInt(((Literal) rightResult).getLabel().substring(sridPosition+1)); 4.236 - rightGeom.setSRID(srid); 4.237 - } 4.238 - } 4.239 - else 4.240 - { //SHOULD NEVER REACH THIS CASE! 4.241 - return null; 4.242 - } 4.243 - 4.244 + // transform the second geometry to the SRID of the first one 4.245 + Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.246 + 4.247 + // check the spatial relationship 4.248 if(function instanceof AboveFunc) 4.249 { 4.250 - int targetSRID = leftGeom.getSRID(); 4.251 - int sourceSRID = rightGeom.getSRID(); 4.252 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.253 funcResult = leftGeom.getEnvelopeInternal().getMinY() > rightConverted.getEnvelopeInternal().getMaxY(); 4.254 } 4.255 else if(function instanceof IntersectsFunc) 4.256 { 4.257 - int targetSRID = leftGeom.getSRID(); 4.258 - int sourceSRID = rightGeom.getSRID(); 4.259 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.260 funcResult = leftGeom.intersects(rightConverted); 4.261 } 4.262 else if(function instanceof BelowFunc) 4.263 { 4.264 - int targetSRID = leftGeom.getSRID(); 4.265 - int sourceSRID = rightGeom.getSRID(); 4.266 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.267 funcResult = leftGeom.getEnvelopeInternal().getMaxY() < rightConverted.getEnvelopeInternal().getMinY(); 4.268 } 4.269 else if(function instanceof ContainsFunc) 4.270 { 4.271 - int targetSRID = leftGeom.getSRID(); 4.272 - int sourceSRID = rightGeom.getSRID(); 4.273 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.274 funcResult = leftGeom.contains(rightConverted); 4.275 } 4.276 else if(function instanceof CrossesFunc) 4.277 { 4.278 - int targetSRID = leftGeom.getSRID(); 4.279 - int sourceSRID = rightGeom.getSRID(); 4.280 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.281 funcResult = leftGeom.crosses(rightConverted); 4.282 } 4.283 else if(function instanceof DisjointFunc) 4.284 { 4.285 - int targetSRID = leftGeom.getSRID(); 4.286 - int sourceSRID = rightGeom.getSRID(); 4.287 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.288 funcResult = leftGeom.disjoint(rightConverted); 4.289 } 4.290 else if(function instanceof EqualsFunc) 4.291 { 4.292 - int targetSRID = leftGeom.getSRID(); 4.293 - int sourceSRID = rightGeom.getSRID(); 4.294 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.295 funcResult = leftGeom.equals(rightConverted); 4.296 } 4.297 else if(function instanceof WithinFunc) 4.298 { 4.299 - int targetSRID = leftGeom.getSRID(); 4.300 - int sourceSRID = rightGeom.getSRID(); 4.301 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.302 funcResult = leftGeom.within(rightConverted); 4.303 } 4.304 else if(function instanceof LeftFunc) 4.305 { 4.306 - int targetSRID = leftGeom.getSRID(); 4.307 - int sourceSRID = rightGeom.getSRID(); 4.308 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.309 funcResult = leftGeom.getEnvelopeInternal().getMaxX() < rightConverted.getEnvelopeInternal().getMinX(); 4.310 } 4.311 else if(function instanceof OverlapsFunc) 4.312 { 4.313 - int targetSRID = leftGeom.getSRID(); 4.314 - int sourceSRID = rightGeom.getSRID(); 4.315 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.316 funcResult = leftGeom.overlaps(rightConverted); 4.317 } 4.318 else if(function instanceof RightFunc) 4.319 { 4.320 - int targetSRID = leftGeom.getSRID(); 4.321 - int sourceSRID = rightGeom.getSRID(); 4.322 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.323 funcResult = leftGeom.getEnvelopeInternal().getMinX() > rightConverted.getEnvelopeInternal().getMaxX(); 4.324 } 4.325 else if(function instanceof TouchesFunc) 4.326 { 4.327 - int targetSRID = leftGeom.getSRID(); 4.328 - int sourceSRID = rightGeom.getSRID(); 4.329 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.330 funcResult = leftGeom.touches(rightConverted); 4.331 } 4.332 else if(function instanceof MbbIntersectsFunc) 4.333 { 4.334 - int targetSRID = leftGeom.getSRID(); 4.335 - int sourceSRID = rightGeom.getSRID(); 4.336 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.337 funcResult = leftGeom.getEnvelope().intersects(rightConverted.getEnvelope()); 4.338 } 4.339 else if(function instanceof MbbWithinFunc) 4.340 { 4.341 - int targetSRID = leftGeom.getSRID(); 4.342 - int sourceSRID = rightGeom.getSRID(); 4.343 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.344 funcResult = leftGeom.getEnvelope().within(rightConverted.getEnvelope()); 4.345 } 4.346 else if(function instanceof MbbContainsFunc) 4.347 { 4.348 - int targetSRID = leftGeom.getSRID(); 4.349 - int sourceSRID = rightGeom.getSRID(); 4.350 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.351 funcResult = leftGeom.getEnvelope().contains(rightConverted.getEnvelope()); 4.352 } 4.353 else if(function instanceof MbbEqualsFunc) 4.354 { 4.355 - int targetSRID = leftGeom.getSRID(); 4.356 - int sourceSRID = rightGeom.getSRID(); 4.357 - Geometry rightConverted = JTSWrapper.getInstance().transform(rightGeom, sourceSRID, targetSRID); 4.358 funcResult = leftGeom.getEnvelope().equals(rightConverted.getEnvelope()); 4.359 } 4.360 4.361 return funcResult ? BooleanLiteralImpl.TRUE : BooleanLiteralImpl.FALSE; 4.362 - 4.363 } 4.364 4.365 // 4.366 // SPATIAL PROPERTY FUNCTIONS 4.367 // 4.368 else if (function instanceof SpatialPropertyFunc) { 4.369 + ValueFactory localvf = ValueFactoryImpl.getInstance(); 4.370 4.371 if (function instanceof GeoSparqlGetSRIDFunc) { 4.372 - return new URIImpl(WKTHelper.getURI_forSRID(getSRIDFromValue(leftResult))); 4.373 + return localvf.createURI(WKTHelper.getURI_forSRID(getSRIDFromValue(leftResult))); 4.374 4.375 } else if (function instanceof SridFunc) { 4.376 - return new NumericLiteralImpl(getSRIDFromValue(leftResult)); 4.377 + return localvf.createLiteral(getSRIDFromValue(leftResult)); 4.378 4.379 } else if (function instanceof IsSimpleFunc) { 4.380 - return new BooleanLiteralImpl(getGeometryFromValue(leftResult).isSimple()); 4.381 + return localvf.createLiteral(getGeometryFromValue(leftResult).isSimple()); 4.382 4.383 } else if (function instanceof IsEmptyFunc) { 4.384 - return new BooleanLiteralImpl(getGeometryFromValue(leftResult).isEmpty()); 4.385 + return localvf.createLiteral(getGeometryFromValue(leftResult).isEmpty()); 4.386 4.387 } else if (function instanceof GeometryTypeFunc) { 4.388 - return new LiteralImpl(getGeometryFromValue(leftResult).getGeometryType()); 4.389 + return localvf.createLiteral(getGeometryFromValue(leftResult).getGeometryType()); 4.390 4.391 } else if (function instanceof DimensionFunc) { 4.392 - return new NumericLiteralImpl(getGeometryFromValue(leftResult).getDimension()); 4.393 + return localvf.createLiteral(getGeometryFromValue(leftResult).getDimension()); 4.394 4.395 } else if (function instanceof AsTextFunc) { 4.396 // already handled 4.397 return leftResult; 4.398 4.399 } else if (function instanceof AsGMLFunc) { 4.400 - return new LiteralImpl(JTSWrapper.getInstance().GMLWrite(getGeometryFromValue(leftResult))); 4.401 + return localvf.createLiteral(JTSWrapper.getInstance().GMLWrite(getGeometryFromValue(leftResult))); 4.402 4.403 } else { 4.404 logger.error("[Strabon.evaluate(FunctionCall)] Function {} has not been implemented yet. ", function.getURI()); 4.405 @@ -661,7 +488,7 @@ 4.406 4.407 public StrabonPolyhedron spatialConstructPicker(Function function, Value left, Value right) throws Exception 4.408 { 4.409 - StrabonPolyhedron leftArg = ((GeneralDBPolyhedron) left).getPolyhedron(); 4.410 + StrabonPolyhedron leftArg = getValueAsStrabonPolyhedron(left); 4.411 if(function.getURI().equals(GeoConstants.stSPARQLunion)) 4.412 { 4.413 StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron(); 4.414 @@ -722,10 +549,17 @@ 4.415 else if(function.getURI().equals(GeoConstants.stSPARQLsymDifference)) 4.416 { 4.417 StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron(); 4.418 - return StrabonPolyhedron.symDifference(leftArg, rightArg); 4.419 - } 4.420 + return StrabonPolyhedron.symDifference(leftArg, rightArg); 4.421 + 4.422 + } else if (function instanceof Centroid) { 4.423 + return leftArg.getCentroid(); 4.424 + 4.425 + } //else if (function instanceof MakeLine) { 4.426 + // return null; 4.427 + //} 4.428 + 4.429 + logger.error("[GeneralDBEvaluation.spatialConstructPicker] Extension function {} has not been implemented yet in this kind of expressions.", function.getURI()); 4.430 return null; 4.431 - 4.432 } 4.433 4.434 @Override 4.435 @@ -1181,6 +1015,31 @@ 4.436 return null; 4.437 } 4.438 } 4.439 + 4.440 + StrabonPolyhedron getValueAsStrabonPolyhedron(Value value) throws ParseException { 4.441 + if (value instanceof GeneralDBPolyhedron) { 4.442 + return ((GeneralDBPolyhedron) value).getPolyhedron(); 4.443 + 4.444 + } else if (value instanceof StrabonPolyhedron) { 4.445 + return (StrabonPolyhedron) value; 4.446 + 4.447 + } else if (value instanceof Literal) { 4.448 + Literal literal = (Literal) value; 4.449 + AbstractWKT wkt = null; 4.450 + 4.451 + if (literal.getDatatype() == null) { 4.452 + wkt = new AbstractWKT(literal.stringValue()); 4.453 + 4.454 + } else { 4.455 + wkt = new AbstractWKT(literal.stringValue(), literal.getDatatype().stringValue()); 4.456 + } 4.457 + 4.458 + return new StrabonPolyhedron(wkt.getWKT(), wkt.getSRID()); 4.459 + 4.460 + } else { // wrong case 4.461 + throw new IllegalArgumentException("The provided argument is not a valid spatial value: " + value.getClass()); 4.462 + } 4.463 + } 4.464 4.465 /** 4.466 * Given an expression get the type of the result.
5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java Sat Sep 20 19:36:24 2014 +0300 5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java Sun Sep 21 00:02:12 2014 +0300 5.3 @@ -118,10 +118,6 @@ 5.4 { 5.5 table.insertGML(id, label, dt, null, null); 5.6 } 5.7 - else if(XMLGSDatatypeUtil.isSemiLinearPointSetDatatype(datatype)) // SemiLinearPointSet case 5.8 - { 5.9 - table.insertGeoSpatial(id, label,dt,null,null); 5.10 - } 5.11 } 5.12 5.13 }
6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Sat Sep 20 19:36:24 2014 +0300 6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Sun Sep 21 00:02:12 2014 +0300 6.3 @@ -166,47 +166,6 @@ 6.4 datatypes.insert(id, datatype); 6.5 } 6.6 6.7 - /********************************************************************/ 6.8 - /** 6.9 - * @deprecated This method is called from {@link LiteralManager.insert} when 6.10 - * the datatype of the label is a SemiLinearPointSet (that is http://stsparql.di.uoa.gr/SemiLinearPointSet). 6.11 - * 6.12 - * @param id 6.13 - * @param label 6.14 - * @param datatype 6.15 - * @param start 6.16 - * @param end 6.17 - * @throws SQLException 6.18 - * @throws InterruptedException 6.19 - */ 6.20 - public void insertGeoSpatial(Number id, String label, String datatype,Timestamp start,Timestamp end) throws SQLException, InterruptedException 6.21 - { 6.22 - 6.23 - byte[] geomWKB = null; 6.24 - 6.25 - try { 6.26 - 6.27 - /***XXX new stuff dictated by kkyzir's StrabonPolyhedron - will be added when the functionality is complete***/ 6.28 - StrabonPolyhedron polyhedron = new StrabonPolyhedron(label); 6.29 - geomWKB = polyhedron.toByteArray(); 6.30 - 6.31 - 6.32 - } catch (IllegalArgumentException e) { 6.33 - e.printStackTrace(); 6.34 - } catch (Exception e) { 6.35 - throw new SQLException("An issue occurred in the underlying StrabonPolyhedron's constructor!"); 6.36 - 6.37 - } 6.38 - 6.39 - //Removed 'value' field 6.40 - Integer srid= findSRID(label); 6.41 - geoSpatialTable.insert(id,srid/*,start,end*/, geomWKB); 6.42 - 6.43 - //XXX not needed currently because this method is called AFTER an insertDatatype() 6.44 - // insertSimple(id, label); 6.45 - // datatypes.insert(id, datatype); 6.46 - } 6.47 - 6.48 //the new version will actually deal with WKB 6.49 public void insertWKT(Number id, String label, String datatype, Timestamp start, Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException 6.50 { 6.51 @@ -292,53 +251,4 @@ 6.52 bool |= geoSpatialTable.expunge(condition); 6.53 return bool; 6.54 } 6.55 - 6.56 - 6.57 - /** 6.58 - * @deprecated To find the SRID for a geometry literal, one has to use the {@link AbstractWKT} 6.59 - * class. Luckily enough, this method is called only from method {@link LiteralTable.insertGeoSpatial}. 6.60 - * 6.61 - * @param label 6.62 - * @return 6.63 - */ 6.64 - protected static Integer findSRID(String label){ 6.65 - String[] crs=label.split(";"); 6.66 - String crsUri=null; 6.67 - 6.68 - if((crs.length == 1)) 6.69 - { 6.70 - if(label.contains("gml")) 6.71 - { 6.72 - try { 6.73 - StrabonPolyhedron poly = new StrabonPolyhedron(label); 6.74 - if(poly.getGeometry().getSRID()>0) 6.75 - return poly.getGeometry().getSRID(); 6.76 - } catch (Exception e) { 6.77 - // TODO Auto-generated catch block 6.78 - e.printStackTrace(); 6.79 - } 6.80 - 6.81 - } 6.82 - else 6.83 - { 6.84 - return 4326; 6.85 - } 6.86 - } 6.87 - else 6.88 - crsUri = crs[1]; 6.89 - 6.90 - String prefix="http://www.opengis.net/def/crs/EPSG/0/"; 6.91 - if(crsUri.startsWith(prefix)){ 6.92 - int index=crsUri.lastIndexOf('/'); 6.93 - index++; 6.94 - Integer srid = Integer.parseInt(crsUri.substring(index)); 6.95 - //System.out.println("The EPSG code: " + srid); 6.96 - 6.97 - //System.out.println("SRS FOUND:"+srid); 6.98 - return srid; 6.99 - }else{ 6.100 - throw new IllegalArgumentException("MALFORMED URI FOR SRID!!!"); 6.101 - 6.102 - } 6.103 } 6.104 -}
7.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java Sat Sep 20 19:36:24 2014 +0300 7.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java Sun Sep 21 00:02:12 2014 +0300 7.3 @@ -9,7 +9,7 @@ 7.4 import java.util.List; 7.5 7.6 import org.openrdf.query.algebra.QueryModelNode; 7.7 -import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 7.8 +import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT; 7.9 import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 7.10 import org.openrdf.sail.generaldb.algebra.GeneralDBDoubleValue; 7.11 import org.openrdf.sail.generaldb.algebra.GeneralDBLabelColumn; 7.12 @@ -959,14 +959,8 @@ 7.13 GeneralDBStringValue arg = (GeneralDBStringValue) expr; 7.14 String raw = arg.getValue(); 7.15 7.16 - StrabonPolyhedron poly = null; 7.17 - try{ 7.18 - poly = new StrabonPolyhedron(raw); 7.19 - } catch (Exception e) { 7.20 - e.printStackTrace(); 7.21 - } 7.22 - 7.23 - filter.append(" GeomFromText('"+poly.toWKT() +"',"+String.valueOf(GeoConstants.defaultSRID)+")"); 7.24 + AbstractWKT wkt = new AbstractWKT(raw); 7.25 + filter.append(" GeomFromText('" + wkt.getWKT() + "'," + String.valueOf(GeoConstants.defaultSRID) + ")"); 7.26 7.27 return raw; 7.28 }
8.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Sat Sep 20 19:36:24 2014 +0300 8.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Sun Sep 21 00:02:12 2014 +0300 8.3 @@ -13,7 +13,6 @@ 8.4 import java.util.List; 8.5 8.6 import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT; 8.7 -import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 8.8 import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 8.9 import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 8.10 import org.openrdf.sail.generaldb.algebra.GeneralDBDateTimeColumn; 8.11 @@ -993,19 +992,10 @@ 8.12 { 8.13 GeneralDBStringValue arg = (GeneralDBStringValue) expr; 8.14 String raw = arg.getValue(); 8.15 - 8.16 - StrabonPolyhedron poly = null; 8.17 - try{ 8.18 - // have to parse it before and clean it from possible appearance of CRS 8.19 - AbstractWKT wkt = new AbstractWKT(raw); 8.20 - 8.21 - poly = new StrabonPolyhedron(wkt.getWKT()); 8.22 - 8.23 - filter.append(" ST_GeomFromText('"+poly.toWKT() +"',"+String.valueOf(wkt.getSRID())+")"); 8.24 - 8.25 - } catch (Exception e) { 8.26 - throw new UnsupportedRdbmsOperatorException(e.getMessage()); 8.27 - } 8.28 + 8.29 + // parse raw WKT 8.30 + AbstractWKT wkt = new AbstractWKT(raw); 8.31 + filter.append(" ST_GeomFromText('" + wkt.getWKT() + "'," + String.valueOf(wkt.getSRID()) + ")"); 8.32 8.33 return raw; 8.34 }
9.1 --- a/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java Sat Sep 20 19:36:24 2014 +0300 9.2 +++ b/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java Sun Sep 21 00:02:12 2014 +0300 9.3 @@ -34,6 +34,7 @@ 9.4 import org.openrdf.query.Binding; 9.5 import org.openrdf.query.BindingSet; 9.6 import org.openrdf.query.TupleQueryResultHandlerException; 9.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 9.8 import org.openrdf.query.resultio.TupleQueryResultFormat; 9.9 import org.openrdf.query.resultio.TupleQueryResultWriter; 9.10 import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 9.11 @@ -163,16 +164,20 @@ 9.12 private void writeValue(Value value) throws IOException { 9.13 if (value instanceof URI) { 9.14 writeURI((URI) value); 9.15 + 9.16 } else if (value instanceof BNode) { 9.17 writeBNode((BNode) value); 9.18 + 9.19 } else if (value instanceof Literal) { 9.20 writeLiteral((Literal) value); 9.21 - } 9.22 - else { // spatial literal 9.23 - // else if (value instanceof RdbmsPolyhedron) 9.24 - URI datatype = new URIImpl(GeoConstants.WKT); 9.25 - GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value; 9.26 - Literal literal = new LiteralImpl(value.stringValue(), dbpolyhedron.getDatatype()); 9.27 + 9.28 + } else if (value instanceof GeneralDBPolyhedron) { // spatial case from database 9.29 + GeneralDBPolyhedron poly = (GeneralDBPolyhedron) value; 9.30 + writeLiteral(new LiteralImpl(poly.stringValue(), poly.getDatatype())); 9.31 + 9.32 + } else if (value instanceof StrabonPolyhedron) { // spatial case from new geometry construction (SELECT) 9.33 + URI datatype = new URIImpl(GeoConstants.default_WKT_datatype); 9.34 + Literal literal = new LiteralImpl(((StrabonPolyhedron) value).stringValue(), datatype); 9.35 writeLiteral(literal); 9.36 } 9.37 }
10.1 --- a/resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java Sat Sep 20 19:36:24 2014 +0300 10.2 +++ b/resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java Sun Sep 21 00:02:12 2014 +0300 10.3 @@ -14,9 +14,13 @@ 10.4 10.5 import org.openrdf.model.Value; 10.6 import org.openrdf.model.impl.LiteralImpl; 10.7 +import org.openrdf.model.impl.URIImpl; 10.8 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 10.9 import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriter; 10.10 import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 10.11 10.12 +import eu.earthobservatory.constants.GeoConstants; 10.13 + 10.14 /** 10.15 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 10.16 * 10.17 @@ -34,6 +38,9 @@ 10.18 // constructing a new literal is the only way if we want to reuse the {@link #writeValue(Value)} method 10.19 GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) val; 10.20 val = new LiteralImpl(dbpolyhedron.stringValue(), dbpolyhedron.getDatatype()); 10.21 + 10.22 + } else if (val instanceof StrabonPolyhedron) { // might come from the construction of new constants in SELECT 10.23 + val = new LiteralImpl(((StrabonPolyhedron) val).stringValue(), new URIImpl(GeoConstants.default_WKT_datatype)); 10.24 } 10.25 10.26 // write value
11.1 --- a/testsuite/src/test/java/eu/earthobservatory/testsuite/stSPARQL/AggregateFunctionsTest.java Sat Sep 20 19:36:24 2014 +0300 11.2 +++ b/testsuite/src/test/java/eu/earthobservatory/testsuite/stSPARQL/AggregateFunctionsTest.java Sun Sep 21 00:02:12 2014 +0300 11.3 @@ -16,5 +16,4 @@ 11.4 * 11.5 * @author Panayiotis Smeros <psmeros@di.uoa.gr> 11.6 */ 11.7 - 11.8 public class AggregateFunctionsTest extends TemplateTest {}
12.1 --- a/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java Sat Sep 20 19:36:24 2014 +0300 12.2 +++ b/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java Sun Sep 21 00:02:12 2014 +0300 12.3 @@ -175,7 +175,7 @@ 12.4 * WGS 84 longitude-latitude 12.5 */ 12.6 public static final String WGS84_LONG_LAT = "http://www.opengis.net/def/crs/OGC/1.3/CRS84"; 12.7 - 12.8 + 12.9 /** 12.10 * EPSG:4326 12.11 */