Strabon

changeset 1409:f8639ac53007

now StrabonPolyhedron carries information about the datatype of the underlying geometry, so as to be consistent with the presentation of results
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Sep 21 19:02:29 2014 +0300 (2014-09-21)
parents 7273dbf377f7
children 2a7de8a1a022
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeometryDatatype.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java runtime/src/main/java/eu/earthobservatory/utils/Format.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Sun Sep 21 15:29:38 2014 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Sun Sep 21 19:02:29 2014 +0300
     1.3 @@ -16,8 +16,6 @@
     1.4  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
     1.5  import org.openrdf.rio.RDFFormat;
     1.6  
     1.7 -import eu.earthobservatory.utils.Format;
     1.8 -
     1.9  /**
    1.10   * Keeps common variables shared by beans and .jsp pages.
    1.11   *
    1.12 @@ -88,7 +86,6 @@
    1.13  				registeredQueryResultsFormatNames.add(format.getName());
    1.14  			//}
    1.15  		}
    1.16 -		
    1.17  	}
    1.18  	
    1.19  	/**
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeometryDatatype.java	Sun Sep 21 19:02:29 2014 +0300
     2.3 @@ -0,0 +1,81 @@
     2.4 +/**
     2.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     2.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     2.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.8 + * 
     2.9 + * Copyright (C) 2012, 2013 Pyravlos Team
    2.10 + * 
    2.11 + * http://www.sextant.di.uoa.gr/
    2.12 + */
    2.13 +package org.openrdf.query.algebra.evaluation.function.spatial;
    2.14 +
    2.15 +import java.util.HashMap;
    2.16 +import java.util.Map;
    2.17 +
    2.18 +import eu.earthobservatory.constants.GeoConstants;
    2.19 +
    2.20 +/**
    2.21 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    2.22 + */
    2.23 +public enum GeometryDatatype {
    2.24 +	/**
    2.25 +	 * stRDF WKT literal
    2.26 +	 */
    2.27 +	stRDFWKT(GeoConstants.WKT),
    2.28 +	
    2.29 +	/**
    2.30 +	 * GeoSPARQL WKT literal
    2.31 +	 */
    2.32 +	wktLiteral(GeoConstants.WKTLITERAL),
    2.33 +	
    2.34 +	/**
    2.35 +	 * GML literal
    2.36 +	 */
    2.37 +	GML(GeoConstants.GMLLITERAL),
    2.38 +	
    2.39 +	/**
    2.40 +	 * Unknown geometry format
    2.41 +	 */
    2.42 +	UNKNOWN("Unknown GeometryDatatype");
    2.43 +	
    2.44 +	/**
    2.45 +	 * The string representation of this format
    2.46 +	 */
    2.47 +	private String name;
    2.48 +	
    2.49 +	/**
    2.50 +	 * Map a string constant to a Format
    2.51 +	 */
    2.52 +	private static final Map<String, GeometryDatatype> stringToEnum = new HashMap<String, GeometryDatatype>();
    2.53 +	
    2.54 +	
    2.55 +	static { // initialize map from constant name to enum constant
    2.56 +		for (GeometryDatatype format : values()) {
    2.57 +			stringToEnum.put(format.toString(), format);
    2.58 +		}
    2.59 +	}
    2.60 +	
    2.61 +	/**
    2.62 +	 * GeometryDatatype constructor
    2.63 +	 * 
    2.64 +	 * @param name
    2.65 +	 */
    2.66 +	GeometryDatatype(String name) {
    2.67 +		this.name = name;
    2.68 +	}
    2.69 +	
    2.70 +	@Override
    2.71 +	public String toString() {
    2.72 +		return name;
    2.73 +	}
    2.74 +	
    2.75 +	/**
    2.76 +	 * Returns a GeometryDatatype enum given a format string.
    2.77 +	 * 
    2.78 +	 * @param lang
    2.79 +	 * @return
    2.80 +	 */
    2.81 +	public static GeometryDatatype fromString(String format) {
    2.82 +		return (stringToEnum.get(format) == null) ? UNKNOWN:stringToEnum.get(format);
    2.83 +	}
    2.84 +}
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Sun Sep 21 15:29:38 2014 +0300
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Sun Sep 21 19:02:29 2014 +0300
     3.3 @@ -31,8 +31,8 @@
     3.4  import com.vividsolutions.jts.io.ParseException;
     3.5  
     3.6  /**
     3.7 - * A {@link StrabonPolyhedron} is a @{link Value} that is used to represent geometries.
     3.8 - * Therefore, a {@link StrabonPolyhedron} wraps around the construct of an RDF @{link Value}
     3.9 + * A {@link StrabonPolyhedron} is a {@link Value} that is used to represent geometries.
    3.10 + * Therefore, a {@link StrabonPolyhedron} wraps around the construct of an RDF {@link Value}
    3.11   * the notion of geometry. This geometry can be expressed in different kinds of
    3.12   * representations, such as linear constraints over the reals with addition
    3.13   * (Semi-linear point sets), Well-Known Text (WKT), or Geography Markup Language (GML).
    3.14 @@ -69,8 +69,8 @@
    3.15  
    3.16  	public static final boolean EnableConstraintRepresentation = false;
    3.17  
    3.18 -	private static int MAX_POINTS = Integer.MAX_VALUE;//40000;//Integer.MAX_VALUE;//10000;
    3.19 -
    3.20 +	//private static int MAX_POINTS = Integer.MAX_VALUE;//40000;//Integer.MAX_VALUE;//10000;
    3.21 +	
    3.22  	/**
    3.23  	 * Get the Java Topology Suite wrapper instance.
    3.24  	 */
    3.25 @@ -81,12 +81,20 @@
    3.26  	 */
    3.27  	private Geometry geometry;
    3.28  
    3.29 +	private GeometryDatatype datatype;
    3.30 +	
    3.31  	/**
    3.32  	 * Creates a {@link StrabonPolyhedron} instance with an empty geometry.
    3.33  	 */
    3.34 -	public StrabonPolyhedron() {
    3.35 +	public StrabonPolyhedron(GeometryDatatype datatype) {
    3.36  		this.geometry = null;
    3.37 -
    3.38 +		this.datatype = datatype;
    3.39 +	}
    3.40 +	
    3.41 +	public StrabonPolyhedron(Geometry geo, int srid, GeometryDatatype datatype) {
    3.42 +		this(datatype);
    3.43 +		this.geometry = geo;
    3.44 +		this.geometry.setSRID(srid);
    3.45  	}
    3.46  	
    3.47  	/**
    3.48 @@ -95,9 +103,8 @@
    3.49  	 * @param geo
    3.50  	 * @throws Exception
    3.51  	 */
    3.52 -	public StrabonPolyhedron(Geometry geo) {
    3.53 -		this.geometry = geo;
    3.54 -		this.geometry.setSRID(geo.getSRID());
    3.55 +	public StrabonPolyhedron(Geometry geo, GeometryDatatype datatype) {
    3.56 +		this(geo, geo.getSRID(), datatype);
    3.57  	}
    3.58  	
    3.59  	/**
    3.60 @@ -114,7 +121,9 @@
    3.61  	 * @param representation
    3.62  	 * @throws Exception
    3.63  	 */
    3.64 -	public StrabonPolyhedron(String representation, int srid) throws ParseException {
    3.65 +	public StrabonPolyhedron(String representation, int srid, GeometryDatatype datatype) throws ParseException {
    3.66 +		this(datatype);
    3.67 +		
    3.68  		try {
    3.69  			// try first as WKT
    3.70  			geometry = jts.WKTread(representation);
    3.71 @@ -124,6 +133,12 @@
    3.72  				// try as GML
    3.73  				geometry = jts.GMLread(representation);
    3.74  				
    3.75 +				// set datatype (to be on the safe side, when the specified datatype
    3.76 +				// was unknown; after all, there is no other case for GML
    3.77 +				if (datatype == GeometryDatatype.UNKNOWN) {
    3.78 +					datatype = GeometryDatatype.GML;
    3.79 +				}
    3.80 +				
    3.81  			} catch (Exception e1) {
    3.82  				throw new ParseException("The given WKT/GML representation is not valid.");
    3.83  			}
    3.84 @@ -140,7 +155,8 @@
    3.85  	 * @param byteArray
    3.86  	 * @throws ParseException
    3.87  	 */
    3.88 -	public StrabonPolyhedron(byte[] byteArray) throws ParseException {
    3.89 +	public StrabonPolyhedron(byte[] byteArray, GeometryDatatype datatype) throws ParseException {
    3.90 +		this(datatype);
    3.91  		this.geometry = jts.WKBread(byteArray);
    3.92  	}
    3.93  
    3.94 @@ -152,18 +168,32 @@
    3.95  	 * @param srid
    3.96  	 * @throws ParseException
    3.97  	 */
    3.98 -	public StrabonPolyhedron(byte[] byteArray, int srid) throws ParseException {
    3.99 -		this(byteArray);
   3.100 +	public StrabonPolyhedron(byte[] byteArray, int srid, GeometryDatatype datatype) throws ParseException {
   3.101 +		this(byteArray, datatype);
   3.102  		this.geometry.setSRID(srid);
   3.103  	}
   3.104  	
   3.105 +	public GeometryDatatype getGeometryDatatype() {
   3.106 +		return datatype;
   3.107 +	}
   3.108 +	
   3.109  	/**
   3.110  	 * Returns the string representation of the geometry of this 
   3.111  	 * {@link StrabonPolyhedron} instance. The result of this method
   3.112  	 * is the same to the one of method {@link #toWKT()}.
   3.113  	 */
   3.114  	public String stringValue() {
   3.115 -		return toWKT();
   3.116 +		switch (datatype) {
   3.117 +			case GML:
   3.118 +				return toGML();
   3.119 +				
   3.120 +			case stRDFWKT:
   3.121 +			case wktLiteral:
   3.122 +				return toWKT();
   3.123 +				
   3.124 +			default: // UNKNOWN
   3.125 +				return toWKT();	
   3.126 +		}
   3.127  	}
   3.128  
   3.129  	@Override
   3.130 @@ -371,9 +401,13 @@
   3.131  	 * 
   3.132  	 * @return
   3.133  	 */
   3.134 -	public String toWKT() {
   3.135 +	protected String toWKT() {
   3.136  		return jts.WKTwrite(this.geometry);		
   3.137  	}
   3.138 +	
   3.139 +	protected String toGML() {
   3.140 +		return jts.GMLWrite(this.geometry);
   3.141 +	}
   3.142  
   3.143  	/**
   3.144  	 * Return the geometry of {@link StrabonPolyhedron} as a byte array.
   3.145 @@ -655,7 +689,7 @@
   3.146  	}
   3.147  
   3.148  	public static StrabonPolyhedron union(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   3.149 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.150 +		StrabonPolyhedron poly = new StrabonPolyhedron(A.getGeometryDatatype());
   3.151  
   3.152  		int targetSRID = A.getGeometry().getSRID();
   3.153  		int sourceSRID = B.getGeometry().getSRID();
   3.154 @@ -667,31 +701,28 @@
   3.155  	}
   3.156  
   3.157  	public static StrabonPolyhedron buffer(StrabonPolyhedron A, double B) throws Exception {
   3.158 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.159 +		StrabonPolyhedron poly = new StrabonPolyhedron(A.getGeometryDatatype());
   3.160  		poly.geometry = A.geometry.buffer(B);
   3.161  
   3.162  		return poly;
   3.163  	}
   3.164  
   3.165  	public static StrabonPolyhedron envelope(StrabonPolyhedron A) throws Exception {
   3.166 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.167 +		StrabonPolyhedron poly = new StrabonPolyhedron(A.getGeometryDatatype());
   3.168  		poly.geometry = A.geometry.getEnvelope();
   3.169  
   3.170  		return poly;
   3.171  	}
   3.172  
   3.173  	public static StrabonPolyhedron convexHull(StrabonPolyhedron A) throws Exception {
   3.174 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.175 +		StrabonPolyhedron poly = new StrabonPolyhedron(A.getGeometryDatatype());
   3.176  		poly.geometry = A.geometry.convexHull();
   3.177  
   3.178  		return poly;
   3.179  	}
   3.180  
   3.181  	public static StrabonPolyhedron boundary(StrabonPolyhedron A) throws Exception {
   3.182 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.183 -		poly.geometry = A.geometry.getBoundary();
   3.184 -
   3.185 -		return poly;
   3.186 +		return new StrabonPolyhedron(A.geometry.getBoundary(), A.getGeometry().getSRID(), A.getGeometryDatatype());
   3.187  	}
   3.188  
   3.189  	public static StrabonPolyhedron intersection(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   3.190 @@ -700,12 +731,11 @@
   3.191  		int sourceSRID = B.getGeometry().getSRID();
   3.192  		Geometry x = JTSWrapper.getInstance().transform(B.getGeometry(), sourceSRID, targetSRID);
   3.193  		Geometry geo = A.geometry.intersection(x);
   3.194 -		geo.setSRID(targetSRID);
   3.195 -		return new StrabonPolyhedron(geo);
   3.196 +		return new StrabonPolyhedron(geo, targetSRID, A.getGeometryDatatype());
   3.197  	}
   3.198  
   3.199  	public static StrabonPolyhedron difference(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   3.200 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.201 +		StrabonPolyhedron poly = new StrabonPolyhedron(A.getGeometryDatatype());
   3.202  
   3.203  		int targetSRID = A.getGeometry().getSRID();
   3.204  		int sourceSRID = B.getGeometry().getSRID();
   3.205 @@ -717,7 +747,7 @@
   3.206  	}
   3.207  
   3.208  	public static StrabonPolyhedron symDifference(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   3.209 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.210 +		StrabonPolyhedron poly = new StrabonPolyhedron(A.getGeometryDatatype());
   3.211  		int targetSRID = A.getGeometry().getSRID();
   3.212  		int sourceSRID = B.getGeometry().getSRID();
   3.213  		Geometry x = JTSWrapper.getInstance().transform(B.getGeometry(), sourceSRID, targetSRID);
   3.214 @@ -738,19 +768,16 @@
   3.215  	}
   3.216  
   3.217  	public static StrabonPolyhedron project(StrabonPolyhedron A, int[] dims) throws Exception {
   3.218 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.219  		ProjectionsFilter filter = new ProjectionsFilter(dims);
   3.220  		A.geometry.apply(filter);
   3.221  		A.geometry.geometryChanged();
   3.222 -		poly.geometry = A.geometry;
   3.223 -		return poly;
   3.224 +		return new StrabonPolyhedron(A.getGeometry(), A.getGeometry().getSRID(), A.getGeometryDatatype());
   3.225  	}
   3.226  	
   3.227  	public static StrabonPolyhedron transform(StrabonPolyhedron A, URI srid) throws Exception {
   3.228 -		
   3.229 -		int parsedSRID = Integer.parseInt(srid.toString().substring(srid.toString().lastIndexOf('/')+1));
   3.230 +		int parsedSRID = WKTHelper.getSRID_forURI(srid.toString());
   3.231  		Geometry converted = JTSWrapper.getInstance().transform(A.getGeometry(), A.getGeometry().getSRID(), parsedSRID);
   3.232 -		return new StrabonPolyhedron(converted);
   3.233 +		return new StrabonPolyhedron(converted, A.getGeometryDatatype());
   3.234  	}
   3.235  
   3.236  	/**
   3.237 @@ -765,7 +792,6 @@
   3.238  		System.out.println("Merging polyhedrons: A.coordinates=" + A.getGeometry().getCoordinates().length + 
   3.239  				", B.coordinates=" + B.getGeometry().getCoordinates().length);
   3.240  
   3.241 -		StrabonPolyhedron poly = new StrabonPolyhedron();
   3.242  		int polygons = 0;
   3.243  		if (Polygon.class.isInstance(A.geometry)) {			
   3.244  			polygons++;
   3.245 @@ -806,24 +832,24 @@
   3.246  			}
   3.247  		}
   3.248  
   3.249 -		poly.geometry = new MultiPolygon(polys, new GeometryFactory());
   3.250 -
   3.251 -		return poly;
   3.252 +		return new StrabonPolyhedron(new MultiPolygon(polys, new GeometryFactory()), 
   3.253 +									 A.getGeometry().getSRID(), 
   3.254 +									 A.getGeometryDatatype());
   3.255  	}
   3.256  
   3.257  	public StrabonPolyhedron getBuffer(double distance) throws Exception {
   3.258  		Geometry geo = this.geometry.buffer(distance);
   3.259 -		return new StrabonPolyhedron(geo);
   3.260 +		return new StrabonPolyhedron(geo, this.geometry.getSRID(), datatype);
   3.261  	}
   3.262  
   3.263  	public StrabonPolyhedron getBoundary() throws Exception {
   3.264  		Geometry geo = this.geometry.getBoundary();
   3.265 -		return new StrabonPolyhedron(geo);
   3.266 +		return new StrabonPolyhedron(geo, this.geometry.getSRID(), datatype);
   3.267  	}
   3.268  
   3.269  	public StrabonPolyhedron getEnvelope() throws Exception {
   3.270  		Geometry geo = this.geometry.getEnvelope();
   3.271 -		return new StrabonPolyhedron(geo);
   3.272 +		return new StrabonPolyhedron(geo, this.geometry.getSRID(), datatype);
   3.273  	}
   3.274  
   3.275  	public double getArea() throws Exception {
   3.276 @@ -862,6 +888,6 @@
   3.277  	 */
   3.278  	public StrabonPolyhedron getCentroid() {
   3.279  		Point point = geometry.getCentroid();
   3.280 -		return new StrabonPolyhedron(point);
   3.281 +		return new StrabonPolyhedron(point, geometry.getSRID(), datatype);
   3.282  	}
   3.283  }
     4.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Sun Sep 21 15:29:38 2014 +0300
     4.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Sun Sep 21 19:02:29 2014 +0300
     4.3 @@ -52,6 +52,7 @@
     4.4  import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     4.5  import org.openrdf.query.algebra.evaluation.function.Function;
     4.6  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
     4.7 +import org.openrdf.query.algebra.evaluation.function.spatial.GeometryDatatype;
     4.8  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     4.9  import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
    4.10  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc;
    4.11 @@ -245,6 +246,16 @@
    4.12  		private Map<String, FunctionCall> spatialAggregates;
    4.13  
    4.14  		private Map<FunctionCall, Geometry> spatialAggregatesResult;
    4.15 +		
    4.16 +		/**
    4.17 +		 * Map holding the datatypes of the geometries. We do not use
    4.18 +		 * a single map (like StrabonPolyhedron) for safety reasons of
    4.19 +		 * the implementation of hashCode(), equals(), etc. We need this
    4.20 +		 * to retain the datatype of the expression (or the constants) and
    4.21 +		 * pass it to the final result. Hence, the output will be consistent
    4.22 +		 * with the datatype of the input. 
    4.23 +		 */
    4.24 +		private Map<FunctionCall, GeometryDatatype> spatialAggregatesResultDatatype;
    4.25  
    4.26  		public Entry(BindingSet prototype)
    4.27  			throws ValueExprEvaluationException, QueryEvaluationException
    4.28 @@ -253,6 +264,7 @@
    4.29  			this.aggregates = new LinkedHashMap<String, Aggregate>();
    4.30  			this.spatialAggregates = new LinkedHashMap<String, FunctionCall>();
    4.31  			this.spatialAggregatesResult = new LinkedHashMap<FunctionCall, Geometry>();
    4.32 +			this.spatialAggregatesResultDatatype = new LinkedHashMap<FunctionCall, GeometryDatatype>();
    4.33  
    4.34  			for (GroupElem ge : group.getGroupElements()) {
    4.35  				if(ge.getName().endsWith("-aggregateInside-"))
    4.36 @@ -402,7 +414,8 @@
    4.37  					if(((FunctionCall) expr).getArgs().size()==1)
    4.38  					{
    4.39  						//Aggregate!!! => Value ready in spatialAggregatesResults
    4.40 -						return new StrabonPolyhedron(spatialAggregatesResult.get(expr));
    4.41 +						return new StrabonPolyhedron(spatialAggregatesResult.get(expr),
    4.42 +													 spatialAggregatesResultDatatype.get(expr));
    4.43  					}
    4.44  					else
    4.45  					{
    4.46 @@ -414,7 +427,8 @@
    4.47  				else if(function instanceof ExtentFunc)
    4.48  				{
    4.49  					//Aggregate!!! => Value ready in spatialAggregatesResults
    4.50 -					return new StrabonPolyhedron(spatialAggregatesResult.get(expr));
    4.51 +					return new StrabonPolyhedron(spatialAggregatesResult.get(expr),
    4.52 +							 					 spatialAggregatesResultDatatype.get(expr));
    4.53  				}
    4.54  				else if(function instanceof BufferFunc)
    4.55  				{
    4.56 @@ -451,7 +465,8 @@
    4.57  					if(((FunctionCall) expr).getArgs().size()==1)
    4.58  					{
    4.59  						//Aggregate!!! => Value ready in spatialAggregatesResults
    4.60 -						return new StrabonPolyhedron(spatialAggregatesResult.get(expr));
    4.61 +						return new StrabonPolyhedron(spatialAggregatesResult.get(expr),
    4.62 +								 					 spatialAggregatesResultDatatype.get(expr));
    4.63  					}
    4.64  					else
    4.65  					{
    4.66 @@ -575,27 +590,35 @@
    4.67  					}
    4.68  					poly = (StrabonPolyhedron) val;
    4.69  					Geometry aggr = this.spatialAggregatesResult.get(expr);
    4.70 +					
    4.71  					if(aggr==null)
    4.72  					{
    4.73  
    4.74  						if(function instanceof UnionFunc)
    4.75  						{
    4.76  							this.spatialAggregatesResult.put((FunctionCall) expr, poly.getGeometry());
    4.77 +							this.spatialAggregatesResultDatatype.put((FunctionCall) expr, poly.getGeometryDatatype());
    4.78  						}
    4.79  						else if(function instanceof IntersectionFunc)
    4.80  						{
    4.81  							this.spatialAggregatesResult.put((FunctionCall) expr, poly.getGeometry());
    4.82 +							this.spatialAggregatesResultDatatype.put((FunctionCall) expr, poly.getGeometryDatatype());
    4.83  						}
    4.84  						else if(function instanceof ExtentFunc)
    4.85  						{
    4.86  							Geometry env = poly.getGeometry().getEnvelope();
    4.87  							env.setSRID(poly.getGeometry().getSRID());
    4.88  							this.spatialAggregatesResult.put((FunctionCall) expr, env);
    4.89 +							this.spatialAggregatesResultDatatype.put((FunctionCall) expr, poly.getGeometryDatatype());
    4.90  						}
    4.91  					}
    4.92  					else
    4.93  					{
    4.94 +						// get the geometry datatype of the already computed aggregate
    4.95 +						GeometryDatatype aggrType = spatialAggregatesResultDatatype.get(expr);
    4.96 +						
    4.97  						this.spatialAggregatesResult.remove(expr);
    4.98 +						this.spatialAggregatesResultDatatype.remove(expr);
    4.99  						if(function instanceof UnionFunc)
   4.100  						{
   4.101  							//XXX possible issue with expressions like 
   4.102 @@ -604,6 +627,7 @@
   4.103  							Geometry united = aggr.union(poly.getGeometry());
   4.104  							united.setSRID(poly.getGeometry().getSRID());
   4.105  							this.spatialAggregatesResult.put((FunctionCall) expr, united);
   4.106 +							this.spatialAggregatesResultDatatype.put((FunctionCall) expr, aggrType);
   4.107  						}
   4.108  						else if(function instanceof IntersectionFunc)
   4.109  						{
   4.110 @@ -613,6 +637,7 @@
   4.111  							Geometry intersection = aggr.intersection(poly.getGeometry());
   4.112  							intersection.setSRID(poly.getGeometry().getSRID());
   4.113  							this.spatialAggregatesResult.put((FunctionCall) expr, intersection);
   4.114 +							this.spatialAggregatesResultDatatype.put((FunctionCall) expr, aggrType);
   4.115  						}
   4.116  						else if(function instanceof ExtentFunc)
   4.117  						{
   4.118 @@ -622,6 +647,7 @@
   4.119  							Geometry env = aggr.union(poly.getGeometry().getEnvelope()).getEnvelope();
   4.120  							env.setSRID(poly.getGeometry().getSRID());
   4.121  							this.spatialAggregatesResult.put((FunctionCall) expr, env);
   4.122 +							this.spatialAggregatesResultDatatype.put((FunctionCall) expr, aggrType);
   4.123  						}
   4.124  					}
   4.125  				}
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Sun Sep 21 15:29:38 2014 +0300
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Sun Sep 21 19:02:29 2014 +0300
     5.3 @@ -45,6 +45,7 @@
     5.4  import org.openrdf.query.algebra.evaluation.function.Function;
     5.5  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
     5.6  import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT;
     5.7 +import org.openrdf.query.algebra.evaluation.function.spatial.GeometryDatatype;
     5.8  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
     5.9  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
    5.10  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
    5.11 @@ -53,7 +54,6 @@
    5.12  import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
    5.13  import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.property.GeoSparqlGetSRIDFunc;
    5.14  import org.openrdf.query.algebra.evaluation.function.spatial.postgis.construct.Centroid;
    5.15 -import org.openrdf.query.algebra.evaluation.function.spatial.postgis.construct.MakeLine;
    5.16  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc;
    5.17  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.DistanceFunc;
    5.18  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.AsGMLFunc;
    5.19 @@ -131,7 +131,6 @@
    5.20  import org.slf4j.LoggerFactory;
    5.21  
    5.22  import com.vividsolutions.jts.geom.Geometry;
    5.23 -import com.vividsolutions.jts.geom.LineString;
    5.24  import com.vividsolutions.jts.io.ParseException;
    5.25  
    5.26  import eu.earthobservatory.constants.GeoConstants;
    5.27 @@ -518,9 +517,9 @@
    5.28  			else if(right instanceof RdbmsURI)
    5.29  			{
    5.30  				RdbmsURI srid = (RdbmsURI) right;
    5.31 -				int parsedSRID = Integer.parseInt(srid.toString().substring(srid.toString().lastIndexOf('/')+1));
    5.32 +				int parsedSRID = WKTHelper.getSRID_forURI(srid.toString());
    5.33  				Geometry converted = JTSWrapper.getInstance().transform(leftArg.getGeometry(),leftArg.getGeometry().getSRID(), parsedSRID);
    5.34 -				return new StrabonPolyhedron(converted);
    5.35 +				return new StrabonPolyhedron(converted, leftArg.getGeometryDatatype());
    5.36  			}
    5.37  
    5.38  		}
    5.39 @@ -1034,7 +1033,9 @@
    5.40  				wkt = new AbstractWKT(literal.stringValue(), literal.getDatatype().stringValue());
    5.41  			}
    5.42  			
    5.43 -			return new StrabonPolyhedron(wkt.getWKT(), wkt.getSRID());
    5.44 +			return new StrabonPolyhedron(wkt.getWKT(), 
    5.45 +										 wkt.getSRID(), 
    5.46 +										 GeometryDatatype.fromString(literal.getDatatype().stringValue()));
    5.47  			
    5.48  		} else { // wrong case
    5.49  			throw new IllegalArgumentException("The provided argument is not a valid spatial value: " + value.getClass());
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java	Sun Sep 21 15:29:38 2014 +0300
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java	Sun Sep 21 19:02:29 2014 +0300
     6.3 @@ -3,6 +3,7 @@
     6.4  import java.io.IOException;
     6.5  
     6.6  import org.openrdf.model.URI;
     6.7 +import org.openrdf.query.algebra.evaluation.function.spatial.GeometryDatatype;
     6.8  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     6.9  import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
    6.10  import org.openrdf.sail.rdbms.model.RdbmsValue;
    6.11 @@ -43,7 +44,7 @@
    6.12  		super(id, version);
    6.13  
    6.14  		try {
    6.15 -			this.polyhedron = new StrabonPolyhedron(polyhedron, srid);
    6.16 +			this.polyhedron = new StrabonPolyhedron(polyhedron, srid, GeometryDatatype.fromString(datatype.stringValue()));
    6.17  			
    6.18  		} catch (ParseException e) {
    6.19  
    6.20 @@ -62,14 +63,11 @@
    6.21  	}
    6.22  
    6.23  	public void setPolyhedronStringRep(StrabonPolyhedron polyhedron) throws IOException, ClassNotFoundException {
    6.24 -		//TODO kkyzir prepares this method
    6.25 -		// TODO add GML
    6.26 -		
    6.27  		if (StrabonPolyhedron.EnableConstraintRepresentation) {
    6.28  			this.polyhedronStringRep = polyhedron.toConstraints();	
    6.29  			
    6.30  		} else {
    6.31 -			this.polyhedronStringRep = polyhedron.toWKT();
    6.32 +			this.polyhedronStringRep = polyhedron.stringValue();
    6.33  		}		
    6.34  	}
    6.35  
     7.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java	Sun Sep 21 15:29:38 2014 +0300
     7.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java	Sun Sep 21 19:02:29 2014 +0300
     7.3 @@ -15,7 +15,7 @@
     7.4  import org.openrdf.model.Value;
     7.5  import org.openrdf.model.datatypes.XMLDateTime;
     7.6  import org.openrdf.model.vocabulary.XMLSchema;
     7.7 -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
     7.8 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     7.9  
    7.10  import eu.earthobservatory.constants.GeoConstants;
    7.11  import eu.earthobservatory.constants.WKTConstants;
    7.12 @@ -56,7 +56,7 @@
    7.13  				return true;
    7.14  			}
    7.15  			
    7.16 -		} else if (value instanceof GeneralDBPolyhedron) {
    7.17 +		} else if (value instanceof GeneralDBPolyhedron || value instanceof StrabonPolyhedron) {
    7.18  			return true;
    7.19  		}
    7.20  		
     8.1 --- a/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Sun Sep 21 15:29:38 2014 +0300
     8.2 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Sun Sep 21 19:02:29 2014 +0300
     8.3 @@ -24,10 +24,13 @@
     8.4  import org.opengis.feature.simple.SimpleFeatureType;
     8.5  import org.openrdf.model.Literal;
     8.6  import org.openrdf.model.Value;
     8.7 +import org.openrdf.model.impl.LiteralImpl;
     8.8 +import org.openrdf.model.impl.URIImpl;
     8.9  import org.openrdf.query.Binding;
    8.10  import org.openrdf.query.BindingSet;
    8.11  import org.openrdf.query.TupleQueryResultHandlerException;
    8.12  import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT;
    8.13 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    8.14  import org.openrdf.query.algebra.evaluation.util.JTSWrapper;
    8.15  import org.openrdf.query.resultio.TupleQueryResultFormat;
    8.16  import org.openrdf.query.resultio.TupleQueryResultWriter;
    8.17 @@ -157,6 +160,11 @@
    8.18  						geom = dbpolyhedron.getPolyhedron().getGeometry();
    8.19  						srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID();
    8.20  						
    8.21 +					} else if (value instanceof StrabonPolyhedron) { // spatial case from new geometry construction (SELECT) 
    8.22 +						StrabonPolyhedron poly = (StrabonPolyhedron) value;
    8.23 +						geom = poly.getGeometry();
    8.24 +						srid = geom.getSRID();
    8.25 +							
    8.26  					} else { // spatial literal WKT or GML
    8.27  						// get the textual representation of the geometry (WKT or GML)
    8.28  						String geoText = value.stringValue();
     9.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Sun Sep 21 15:29:38 2014 +0300
     9.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Sun Sep 21 19:02:29 2014 +0300
     9.3 @@ -22,10 +22,13 @@
     9.4  import org.openrdf.model.BNode;
     9.5  import org.openrdf.model.Literal;
     9.6  import org.openrdf.model.Value;
     9.7 +import org.openrdf.model.impl.LiteralImpl;
     9.8 +import org.openrdf.model.impl.URIImpl;
     9.9  import org.openrdf.query.Binding;
    9.10  import org.openrdf.query.BindingSet;
    9.11  import org.openrdf.query.TupleQueryResultHandlerException;
    9.12  import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT;
    9.13 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    9.14  import org.openrdf.query.algebra.evaluation.util.JTSWrapper;
    9.15  import org.openrdf.query.resultio.TupleQueryResultFormat;
    9.16  import org.openrdf.query.resultio.TupleQueryResultWriter;
    9.17 @@ -330,6 +333,11 @@
    9.18  				geom = dbpolyhedron.getPolyhedron().getGeometry();
    9.19  				srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID();
    9.20  				
    9.21 +			} else if (value instanceof StrabonPolyhedron) { // spatial case from new geometry construction (SELECT) 
    9.22 +					StrabonPolyhedron poly = (StrabonPolyhedron) value;
    9.23 +					geom = poly.getGeometry();
    9.24 +					srid = geom.getSRID();
    9.25 +					
    9.26  			} else { // spatial literal
    9.27  				Literal spatial = (Literal) value;
    9.28  				String geomRep = spatial.stringValue();
    9.29 @@ -339,9 +347,9 @@
    9.30  					AbstractWKT awkt = null;
    9.31  					if (spatial.getDatatype() == null) { // plain WKT literal
    9.32  						awkt = new AbstractWKT(geomRep);
    9.33 +						
    9.34  					} else { // typed WKT literal
    9.35 -						awkt = new AbstractWKT(geomRep, spatial.getDatatype()
    9.36 -								.stringValue());
    9.37 +						awkt = new AbstractWKT(geomRep, spatial.getDatatype().stringValue());
    9.38  					}
    9.39  
    9.40  					geom = jts.WKTread(awkt.getWKT());
    10.1 --- a/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java	Sun Sep 21 15:29:38 2014 +0300
    10.2 +++ b/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java	Sun Sep 21 19:02:29 2014 +0300
    10.3 @@ -40,8 +40,6 @@
    10.4  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    10.5  import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
    10.6  
    10.7 -import eu.earthobservatory.constants.GeoConstants;
    10.8 -
    10.9  /**
   10.10   * A {@link TupleQueryResultWriter} that writes tuple query results in the <a
   10.11   * href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query Results XML
   10.12 @@ -176,8 +174,8 @@
   10.13  			writeLiteral(new LiteralImpl(poly.stringValue(), poly.getDatatype()));
   10.14  			
   10.15  		} else if (value instanceof StrabonPolyhedron) { // spatial case from new geometry construction (SELECT) 
   10.16 -			URI datatype = new URIImpl(GeoConstants.default_WKT_datatype);
   10.17 -			Literal literal = new LiteralImpl(((StrabonPolyhedron) value).stringValue(), datatype);
   10.18 +			StrabonPolyhedron poly = (StrabonPolyhedron) value;
   10.19 +			Literal literal = new LiteralImpl(poly.stringValue(), new URIImpl(poly.getGeometryDatatype().toString()));
   10.20  			writeLiteral(literal);
   10.21  		}
   10.22  	}
    11.1 --- a/resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java	Sun Sep 21 15:29:38 2014 +0300
    11.2 +++ b/resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java	Sun Sep 21 19:02:29 2014 +0300
    11.3 @@ -19,8 +19,6 @@
    11.4  import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriter;
    11.5  import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
    11.6  
    11.7 -import eu.earthobservatory.constants.GeoConstants;
    11.8 -
    11.9  /**
   11.10   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
   11.11   * 
   11.12 @@ -40,7 +38,8 @@
   11.13  			val = new LiteralImpl(dbpolyhedron.stringValue(), dbpolyhedron.getDatatype());
   11.14  			
   11.15  		} else if (val instanceof StrabonPolyhedron) { // might come from the construction of new constants in SELECT
   11.16 -			val = new LiteralImpl(((StrabonPolyhedron) val).stringValue(), new URIImpl(GeoConstants.default_WKT_datatype));
   11.17 +			StrabonPolyhedron poly = (StrabonPolyhedron) val;
   11.18 +			val = new LiteralImpl(poly.stringValue(), new URIImpl(poly.getGeometryDatatype().toString()));
   11.19  		}
   11.20  		
   11.21  		// write value
    12.1 --- a/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Sun Sep 21 15:29:38 2014 +0300
    12.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Sun Sep 21 19:02:29 2014 +0300
    12.3 @@ -17,7 +17,6 @@
    12.4   * for the results of the evaluation of a SPARQL query.
    12.5   * 
    12.6   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    12.7 - *
    12.8   */
    12.9  public enum Format {
   12.10