Strabon

changeset 53:17c697469b47

merge with mine
author Giorgos Garbis <ggarbis@di.uoa.gr>
date Wed Mar 14 15:27:35 2012 +0200 (2012-03-14)
parents bd92581c8a5b b2625b0d312b
children b678ff809288
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java
line diff
     1.1 --- a/evaluation/pom.xml	Tue Mar 13 15:01:43 2012 +0200
     1.2 +++ b/evaluation/pom.xml	Wed Mar 14 15:27:35 2012 +0200
     1.3 @@ -1,4 +1,5 @@
     1.4 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     1.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     1.6 +	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     1.7  
     1.8  	<modelVersion>4.0.0</modelVersion>
     1.9  
    1.10 @@ -35,13 +36,8 @@
    1.11  			<artifactId>sesame-model</artifactId>
    1.12  			<version>${sesame.version}</version>
    1.13  		</dependency>
    1.14 -		<!--
    1.15 -		<dependency>
    1.16 -			<groupId>info.aduna.commons</groupId>
    1.17 -			<artifactId>aduna-commons-lang</artifactId>
    1.18 -			<version>2.10.0-SNAPSHOT</version>
    1.19 -		</dependency>
    1.20 -		-->
    1.21 +		<!-- <dependency> <groupId>info.aduna.commons</groupId> <artifactId>aduna-commons-lang</artifactId> 
    1.22 +			<version>2.10.0-SNAPSHOT</version> </dependency> -->
    1.23  		<dependency>
    1.24  			<groupId>org.slf4j</groupId>
    1.25  			<artifactId>slf4j-api</artifactId>
    1.26 @@ -55,10 +51,16 @@
    1.27  			<groupId>junit</groupId>
    1.28  			<artifactId>junit</artifactId>
    1.29  		</dependency>
    1.30 +
    1.31 +		<!-- <dependency> -->
    1.32 +		<!-- <groupId>org.opengis</groupId> -->
    1.33 +		<!-- <artifactId>geoapi</artifactId> -->
    1.34 +		<!-- </dependency> -->
    1.35  		<dependency>
    1.36 -			<groupId>org.opengis</groupId>
    1.37 -			<artifactId>geoapi</artifactId>
    1.38 +			<groupId>org.geotools</groupId>
    1.39 +			<artifactId>gt-opengis</artifactId>
    1.40  		</dependency>
    1.41 +
    1.42  		<dependency>
    1.43  			<groupId>org.geotools</groupId>
    1.44  			<artifactId>gt-referencing</artifactId>
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Tue Mar 13 15:01:43 2012 +0200
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Wed Mar 14 15:27:35 2012 +0200
     2.3 @@ -36,8 +36,8 @@
     2.4  	public static String TABLE_COUNTS = "counts.bin";
     2.5  	public static String TABLE_SUBJ_OBJ_TYPES = "tableProperties.bin";
     2.6  	public static String TABLE_SHIFTING = "groupbys.bin";
     2.7 -	
     2.8 -	
     2.9 +
    2.10 +
    2.11  	public static final boolean EnableConstraintRepresentation = false;
    2.12  
    2.13  	public static final String stRDFSemiLinearPointset="http://strdf.di.uoa.gr/ontology#SemiLinearPointSet";
    2.14 @@ -82,9 +82,9 @@
    2.15  	//Spatial Aggregate Functions
    2.16  	public static final String extent="http://strdf.di.uoa.gr/ontology#extent";
    2.17  	////
    2.18 -	
    2.19 +
    2.20  	//GEOSPARQL
    2.21 -	
    2.22 +
    2.23  	//Non-topological
    2.24  	public static final String geoSparqlDistance = geof+"distance"; //3 arguments
    2.25  	public static final String geoSparqlBuffer = geof+"buffer"; //3 arguments
    2.26 @@ -95,7 +95,7 @@
    2.27  	public static final String geoSparqlSymmetricDifference = geof+"symmetricDifference";
    2.28  	public static final String geoSparqlEnvelope = geof+"envelope";
    2.29  	public static final String geoSparqlBoundary = geof+"boundary";
    2.30 -	
    2.31 +
    2.32  	//Simple Features - 8 functions - all with 2 arguments + boolean
    2.33  	public static final String sfEquals = geof+"sf-equals";  
    2.34  	public static final String sfDisjoint = geof+"sf-disjoint";  
    2.35 @@ -105,7 +105,7 @@
    2.36  	public static final String sfWithin = geof+"sf-within";
    2.37  	public static final String sfContains = geof+"sf-contains";
    2.38  	public static final String sfOverlaps = geof+"sf-overlaps";
    2.39 -	
    2.40 +
    2.41  	//Egenhofer - 8 functions - all with 2 arguments + boolean
    2.42  	public static final String ehEquals = geof+"eh-equals";  
    2.43  	public static final String ehDisjoint = geof+"eh-disjoint";  
    2.44 @@ -127,16 +127,17 @@
    2.45  	public static final String rccNonTangentialProperPartInverse = geof+"rcc8-ntppi";
    2.46  
    2.47  	public static final String geoSparqlRelate = geof+"relate";
    2.48 -	
    2.49 +
    2.50  	private static int MAX_POINTS = Integer.MAX_VALUE;//40000;//Integer.MAX_VALUE;//10000;
    2.51  
    2.52  	private Geometry geometry;
    2.53  
    2.54  	public StrabonPolyhedron() {
    2.55  		this.geometry = null;
    2.56 +
    2.57  	}
    2.58 -	
    2.59 -		
    2.60 +
    2.61 +
    2.62  	public void setGeometry(Geometry geometry) {
    2.63  		this.geometry = geometry;
    2.64  	}
    2.65 @@ -146,27 +147,36 @@
    2.66  	public static StrabonPolyhedron ConstructFromWKB(byte[] byteArray) throws Exception {
    2.67  		return new StrabonPolyhedron(new WKBReader().read(byteArray));
    2.68  	}
    2.69 -	
    2.70 +
    2.71  	public static Geometry convertSRID(Geometry A, int sourceSRID, int targetSRID)
    2.72  	{
    2.73  
    2.74 -		MathTransform transform;
    2.75 -		try {
    2.76 -			//EPSG supported currently - is there a way to be more general??
    2.77 -			CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:"+sourceSRID);
    2.78 -			CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:"+targetSRID);
    2.79 -			transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
    2.80 -			return JTS.transform(A, transform);
    2.81 -		} catch (FactoryException e) {
    2.82 -			// TODO Auto-generated catch block
    2.83 -			e.printStackTrace();
    2.84 -		} catch (MismatchedDimensionException e) {
    2.85 -			// TODO Auto-generated catch block
    2.86 -			e.printStackTrace();
    2.87 -		} catch (TransformException e) {
    2.88 -			System.out.println("Transformation is not possible!!");
    2.89 -			e.printStackTrace();
    2.90 -		} 
    2.91 +		if(sourceSRID != targetSRID)
    2.92 +		{
    2.93 +			CoordinateReferenceSystem sourceCRS = null;
    2.94 +			CoordinateReferenceSystem targetCRS = null;
    2.95 +			
    2.96 +			MathTransform transform;
    2.97 +			try {
    2.98 +				//EPSG supported currently - is there a way to be more general??
    2.99 +				sourceCRS = CRS.decode("EPSG:"+sourceSRID);
   2.100 +				targetCRS = CRS.decode("EPSG:"+targetSRID);
   2.101 +				transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
   2.102 +
   2.103 +				Geometry x = JTS.transform(A, transform);
   2.104 +				x.setSRID(targetSRID);
   2.105 +				return x;
   2.106 +			} catch (FactoryException e) {
   2.107 +				// TODO Auto-generated catch block
   2.108 +				e.printStackTrace();
   2.109 +			} catch (MismatchedDimensionException e) {
   2.110 +				// TODO Auto-generated catch block
   2.111 +				e.printStackTrace();
   2.112 +			} catch (TransformException e) {
   2.113 +				System.out.println("Transformation is not possible!!");
   2.114 +				e.printStackTrace();
   2.115 +			} 
   2.116 +		}
   2.117  		return A;
   2.118  	}
   2.119  
   2.120 @@ -174,7 +184,9 @@
   2.121  	//	Polyhedron poly = new Polyhedron(constraints);
   2.122  	//	this.geometry = new WKTReader().read(poly.toWKT());
   2.123  	//}
   2.124 -	
   2.125 +
   2.126 +
   2.127 +
   2.128  	public StrabonPolyhedron(Geometry geo) throws Exception {
   2.129  		this.geometry = new StrabonPolyhedron(geo, 1).geometry;
   2.130  	}
   2.131 @@ -182,18 +194,18 @@
   2.132  	public StrabonPolyhedron(Geometry geo, int algorithm) throws Exception {
   2.133  		this.geometry = new StrabonPolyhedron(geo, algorithm, MAX_POINTS).geometry;
   2.134  	}
   2.135 -	
   2.136 +
   2.137  	public StrabonPolyhedron(Geometry geo, int algorithm, int maxPoints) throws Exception {		
   2.138  		if (geo.isEmpty()) {
   2.139  			this.geometry = geo;
   2.140  			return;
   2.141  		}
   2.142 -		
   2.143 +
   2.144  		if (!EnableConstraintRepresentation) {
   2.145  			this.geometry = geo;
   2.146  			return;
   2.147  		}
   2.148 -		
   2.149 +
   2.150  		//always returns true...
   2.151  		//if (!geo.isSimple())
   2.152  		//	throw new Exception("The polygon is not simple. Only simple polygons are supported.");
   2.153 @@ -209,7 +221,7 @@
   2.154  			//	System.out.println("Converted to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid. ("+geo.toString()+")");
   2.155  			//	this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
   2.156  			//} else {
   2.157 -				this.geometry = new StrabonPolyhedron((Polygon) geo, algorithm, maxPoints).geometry;
   2.158 +			this.geometry = new StrabonPolyhedron((Polygon) geo, algorithm, maxPoints).geometry;
   2.159  			//}
   2.160  		} else if (MultiPoint.class.isInstance(geo)) {
   2.161  			this.geometry = geo;
   2.162 @@ -236,115 +248,115 @@
   2.163  			}
   2.164  			this.geometry = new MultiLineString(linecollection, new GeometryFactory());
   2.165  		} else if (MultiPolygon.class.isInstance(geo)) {
   2.166 -//			if (!geo.isValid()) {
   2.167 -////				System.out.println("Non valid " + FindGeoType(geo) + " found.");
   2.168 -////				geo = geo.buffer(0.0);
   2.169 -////				
   2.170 -////				Geometry[] geometries = new Geometry[geo.getNumGeometries()];
   2.171 -////				for (int i = 0; i < geo.getNumGeometries(); i++) {
   2.172 -////					boolean before = geo.getGeometryN(i).isValid();
   2.173 -////					geometries[i] = geo.getGeometryN(i).buffer(0.0);
   2.174 -////					boolean after = geometries[i].isValid();
   2.175 -////					//System.out.println("Geometry " + i + " was " + (before ? "" : "not ") + "valid and now it is " + (after ? "still " : "not ") + "valid.");
   2.176 -////				}			
   2.177 -////				
   2.178 -////				Geometry col = new GeometryCollection(geometries, new GeometryFactory()).buffer(0.0);
   2.179 -////				System.out.println("Converted to a "+FindGeoType(col)+" that is "+(col.isValid() ? "" : "not ")+"valid.");
   2.180 -////				this.geometry = new StrabonPolyhedron(col, algorithm, maxPoints).geometry;
   2.181 -//				
   2.182 -////				System.out.println("Non valid " + FindGeoType(geo) + " found.");
   2.183 -////				
   2.184 -////				System.out.println("Number of geometries: " + geo.getNumGeometries());
   2.185 -////				MultiPolygon multipoly = (MultiPolygon)geo;
   2.186 -////				Geometry newPoly = multipoly.getGeometryN(0);
   2.187 -////				
   2.188 -////				for (int i = 1; i < geo.getNumGeometries(); i++) {
   2.189 -////					newPoly = newPoly.union(geo.getGeometryN(i));
   2.190 -////				}			
   2.191 -////				
   2.192 -////				newPoly.buffer(0.0);
   2.193 -////				
   2.194 -////				//Geometry col = new GeometryCollection(geometries, new GeometryFactory()).buffer(0.0);
   2.195 -////				System.out.println("Converted to a "+FindGeoType(newPoly)+" that is "+(newPoly.isValid() ? "" : "not ")+"valid.");
   2.196 -////				this.geometry = new StrabonPolyhedron(newPoly, algorithm, maxPoints).geometry;
   2.197 -//				
   2.198 -//				//System.out.println("Non valid " + FindGeoType(geo) + " found. (coordinates:"+geo.getCoordinates().length+")");
   2.199 -//				//geo = TopologyPreservingSimplifier.simplify(geo, 0.2);
   2.200 -//				while (true) {
   2.201 -//					if (geo.getCoordinates().length > 300000) {
   2.202 -//						geo = TopologyPreservingSimplifier.simplify(geo, 0.1);
   2.203 -//						System.out.println("Simplified to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid (coordinates:"+geo.getCoordinates().length+").");
   2.204 -//					}
   2.205 -//					geo = geo.buffer(0.0);
   2.206 -//					System.out.println("Buffered to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid (coordinates:"+geo.getCoordinates().length+").");
   2.207 -//					
   2.208 -//					if (geo.isValid() && (geo.getCoordinates().length < 300000))
   2.209 -//						break;
   2.210 -//				}								
   2.211 -//				
   2.212 -//				this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
   2.213 -//				
   2.214 -//				//System.out.println("Are the geometries the same? Answer: " + (geo.equals(this.geometry) ? "true" : "false"));
   2.215 -//				
   2.216 -//			} else {
   2.217 -				MultiPolygon mpoly = (MultiPolygon)geo;
   2.218 -				ArrayList<Polygon> collection = new ArrayList<Polygon>(mpoly.getNumGeometries());
   2.219 -	
   2.220 -				for (int i = 0; i < mpoly.getNumGeometries(); i++) {
   2.221 -					System.out.println("[1] " + mpoly.getNumGeometries());
   2.222 -					StrabonPolyhedron poly = new StrabonPolyhedron(mpoly.getGeometryN(i), algorithm, maxPoints);
   2.223 -					System.out.println("[2] " + poly.geometry.getNumGeometries());
   2.224 -					for (int j = 0; j < poly.geometry.getNumGeometries(); j++) {
   2.225 -						collection.add((Polygon)poly.geometry.getGeometryN(j));
   2.226 -					}
   2.227 +			//			if (!geo.isValid()) {
   2.228 +			////				System.out.println("Non valid " + FindGeoType(geo) + " found.");
   2.229 +			////				geo = geo.buffer(0.0);
   2.230 +			////				
   2.231 +			////				Geometry[] geometries = new Geometry[geo.getNumGeometries()];
   2.232 +			////				for (int i = 0; i < geo.getNumGeometries(); i++) {
   2.233 +			////					boolean before = geo.getGeometryN(i).isValid();
   2.234 +			////					geometries[i] = geo.getGeometryN(i).buffer(0.0);
   2.235 +			////					boolean after = geometries[i].isValid();
   2.236 +			////					//System.out.println("Geometry " + i + " was " + (before ? "" : "not ") + "valid and now it is " + (after ? "still " : "not ") + "valid.");
   2.237 +			////				}			
   2.238 +			////				
   2.239 +			////				Geometry col = new GeometryCollection(geometries, new GeometryFactory()).buffer(0.0);
   2.240 +			////				System.out.println("Converted to a "+FindGeoType(col)+" that is "+(col.isValid() ? "" : "not ")+"valid.");
   2.241 +			////				this.geometry = new StrabonPolyhedron(col, algorithm, maxPoints).geometry;
   2.242 +			//				
   2.243 +			////				System.out.println("Non valid " + FindGeoType(geo) + " found.");
   2.244 +			////				
   2.245 +			////				System.out.println("Number of geometries: " + geo.getNumGeometries());
   2.246 +			////				MultiPolygon multipoly = (MultiPolygon)geo;
   2.247 +			////				Geometry newPoly = multipoly.getGeometryN(0);
   2.248 +			////				
   2.249 +			////				for (int i = 1; i < geo.getNumGeometries(); i++) {
   2.250 +			////					newPoly = newPoly.union(geo.getGeometryN(i));
   2.251 +			////				}			
   2.252 +			////				
   2.253 +			////				newPoly.buffer(0.0);
   2.254 +			////				
   2.255 +			////				//Geometry col = new GeometryCollection(geometries, new GeometryFactory()).buffer(0.0);
   2.256 +			////				System.out.println("Converted to a "+FindGeoType(newPoly)+" that is "+(newPoly.isValid() ? "" : "not ")+"valid.");
   2.257 +			////				this.geometry = new StrabonPolyhedron(newPoly, algorithm, maxPoints).geometry;
   2.258 +			//				
   2.259 +			//				//System.out.println("Non valid " + FindGeoType(geo) + " found. (coordinates:"+geo.getCoordinates().length+")");
   2.260 +			//				//geo = TopologyPreservingSimplifier.simplify(geo, 0.2);
   2.261 +			//				while (true) {
   2.262 +			//					if (geo.getCoordinates().length > 300000) {
   2.263 +			//						geo = TopologyPreservingSimplifier.simplify(geo, 0.1);
   2.264 +			//						System.out.println("Simplified to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid (coordinates:"+geo.getCoordinates().length+").");
   2.265 +			//					}
   2.266 +			//					geo = geo.buffer(0.0);
   2.267 +			//					System.out.println("Buffered to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid (coordinates:"+geo.getCoordinates().length+").");
   2.268 +			//					
   2.269 +			//					if (geo.isValid() && (geo.getCoordinates().length < 300000))
   2.270 +			//						break;
   2.271 +			//				}								
   2.272 +			//				
   2.273 +			//				this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
   2.274 +			//				
   2.275 +			//				//System.out.println("Are the geometries the same? Answer: " + (geo.equals(this.geometry) ? "true" : "false"));
   2.276 +			//				
   2.277 +			//			} else {
   2.278 +			MultiPolygon mpoly = (MultiPolygon)geo;
   2.279 +			ArrayList<Polygon> collection = new ArrayList<Polygon>(mpoly.getNumGeometries());
   2.280 +
   2.281 +			for (int i = 0; i < mpoly.getNumGeometries(); i++) {
   2.282 +				System.out.println("[1] " + mpoly.getNumGeometries());
   2.283 +				StrabonPolyhedron poly = new StrabonPolyhedron(mpoly.getGeometryN(i), algorithm, maxPoints);
   2.284 +				System.out.println("[2] " + poly.geometry.getNumGeometries());
   2.285 +				for (int j = 0; j < poly.geometry.getNumGeometries(); j++) {
   2.286 +					collection.add((Polygon)poly.geometry.getGeometryN(j));
   2.287  				}
   2.288 -	
   2.289 -				Polygon[] polycollection = new Polygon[collection.size()];
   2.290 -				int k = 0;
   2.291 -				for (Polygon polygon : collection) {
   2.292 -					polycollection[k] = polygon;
   2.293 -					k++;
   2.294 -					assert (!polygon.isEmpty());
   2.295 +			}
   2.296 +
   2.297 +			Polygon[] polycollection = new Polygon[collection.size()];
   2.298 +			int k = 0;
   2.299 +			for (Polygon polygon : collection) {
   2.300 +				polycollection[k] = polygon;
   2.301 +				k++;
   2.302 +				assert (!polygon.isEmpty());
   2.303 +			}
   2.304 +			this.geometry = new MultiPolygon(polycollection, new GeometryFactory());
   2.305 +			//			}
   2.306 +		} else {
   2.307 +			//			if (!geo.isValid()) {
   2.308 +			//				System.out.println("Non valid " + FindGeoType(geo) + " found.");
   2.309 +			//				geo = geo.buffer(0.0);
   2.310 +			//				System.out.println("Converted to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid+.");
   2.311 +			//				this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
   2.312 +			//			} else {
   2.313 +			for (int i = 0; i < geo.getNumGeometries(); i++) {
   2.314 +				StrabonPolyhedron smallGeo = new StrabonPolyhedron(geo.getGeometryN(i), algorithm, maxPoints);
   2.315 +
   2.316 +				if (this.geometry == null) {
   2.317 +					this.geometry = smallGeo.geometry;
   2.318 +				} else {
   2.319 +					this.geometry.union(smallGeo.geometry);
   2.320  				}
   2.321 -				this.geometry = new MultiPolygon(polycollection, new GeometryFactory());
   2.322 -//			}
   2.323 -		} else {
   2.324 -//			if (!geo.isValid()) {
   2.325 -//				System.out.println("Non valid " + FindGeoType(geo) + " found.");
   2.326 -//				geo = geo.buffer(0.0);
   2.327 -//				System.out.println("Converted to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid+.");
   2.328 -//				this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
   2.329 -//			} else {
   2.330 -				for (int i = 0; i < geo.getNumGeometries(); i++) {
   2.331 -					StrabonPolyhedron smallGeo = new StrabonPolyhedron(geo.getGeometryN(i), algorithm, maxPoints);
   2.332 -					
   2.333 -					if (this.geometry == null) {
   2.334 -						this.geometry = smallGeo.geometry;
   2.335 -					} else {
   2.336 -						this.geometry.union(smallGeo.geometry);
   2.337 -					}
   2.338 -				}
   2.339 -//			}
   2.340 +			}
   2.341 +			//			}
   2.342  		}
   2.343  	}
   2.344  
   2.345  	public static StrabonPolyhedron ParseBigPolyhedron(Geometry polygon, int algorithm, boolean horizontal, int maxPoints) throws Exception {
   2.346  		assert (Polygon.class.isInstance(polygon) || (MultiPolygon.class.isInstance(polygon)));
   2.347 -		
   2.348 +
   2.349  		if (polygon.getCoordinates().length > maxPoints) {
   2.350 -//			if (polygon.isValid()){
   2.351 -//				System.out.println("Found big polyhedron. Coordinates: " + polygon.getCoordinates().length + " (valid="+polygon.isValid()+").");
   2.352 -//			} else {
   2.353 -//				System.out.println("Found invalid big polyhedron. Coordinates: " + polygon.getCoordinates().length + ".");
   2.354 -//				//IsValidOp err = new IsValidOp(polygon);
   2.355 -//				//System.out.println("Validation error: " + err.getValidationError());
   2.356 -//				//new Point(new CoordinateArraySequence(new Coordinate[] {polygon.getCoordinates()[0]}), new GeometryFactory());
   2.357 -//				//polygon = polygon.union(onePoint);
   2.358 -//				polygon = polygon.buffer(0.0);
   2.359 -//				System.out.println("After conversion, coordinates: " + polygon.getCoordinates().length + " (valid="+polygon.isValid()+").");
   2.360 -//			}
   2.361 +			//			if (polygon.isValid()){
   2.362 +			//				System.out.println("Found big polyhedron. Coordinates: " + polygon.getCoordinates().length + " (valid="+polygon.isValid()+").");
   2.363 +			//			} else {
   2.364 +			//				System.out.println("Found invalid big polyhedron. Coordinates: " + polygon.getCoordinates().length + ".");
   2.365 +			//				//IsValidOp err = new IsValidOp(polygon);
   2.366 +			//				//System.out.println("Validation error: " + err.getValidationError());
   2.367 +			//				//new Point(new CoordinateArraySequence(new Coordinate[] {polygon.getCoordinates()[0]}), new GeometryFactory());
   2.368 +			//				//polygon = polygon.union(onePoint);
   2.369 +			//				polygon = polygon.buffer(0.0);
   2.370 +			//				System.out.println("After conversion, coordinates: " + polygon.getCoordinates().length + " (valid="+polygon.isValid()+").");
   2.371 +			//			}
   2.372  			double minx = Double.MAX_VALUE, miny = Double.MAX_VALUE, 
   2.373 -			       maxx = Double.MIN_VALUE, maxy = Double.MIN_VALUE;
   2.374 +					maxx = Double.MIN_VALUE, maxy = Double.MIN_VALUE;
   2.375  
   2.376  			Geometry bbox = polygon.getEnvelope();
   2.377  			for (int i = 0; i < bbox.getCoordinates().length; i++) {
   2.378 @@ -362,30 +374,30 @@
   2.379  							new Coordinate(horizontal ? (minx + (maxx-minx)/2) : maxx, 	horizontal ? maxy : (miny + (maxy-miny)/2)),
   2.380  							new Coordinate(minx, 										horizontal ? maxy : (miny + (maxy-miny)/2)),
   2.381  							new Coordinate(minx, 										miny)}
   2.382 -			), new GeometryFactory()), null, new GeometryFactory());
   2.383 +					), new GeometryFactory()), null, new GeometryFactory());
   2.384  
   2.385  			firsthalf.normalize();
   2.386 -			
   2.387 +
   2.388  			Polygon secondhalf = (Polygon) bbox.difference(firsthalf);
   2.389  			secondhalf.normalize();
   2.390 -			
   2.391 -//			double a = polygon.getArea();
   2.392 -//			double b = polygon.getEnvelope().getArea();
   2.393 -//			double c = firsthalf.getArea();
   2.394 -//			double d = bbox.difference(firsthalf).getArea();
   2.395 -//			
   2.396 -//			double e = b-c-d;
   2.397 -//			double f = c-d;
   2.398 -//			
   2.399 -//			double kk = firsthalf.difference(bbox).difference(firsthalf).getArea();
   2.400 -//			
   2.401 -//			boolean g = firsthalf.equals(bbox.difference(firsthalf));
   2.402 -//			boolean h = firsthalf.disjoint(bbox.difference(firsthalf));
   2.403 -//			boolean i = bbox.equals(firsthalf.union(bbox.difference(firsthalf)));
   2.404 -//			
   2.405 -//			boolean j = firsthalf.intersects(polygon);
   2.406 -//			boolean k = bbox.difference(firsthalf).intersects(polygon);
   2.407 -			
   2.408 +
   2.409 +			//			double a = polygon.getArea();
   2.410 +			//			double b = polygon.getEnvelope().getArea();
   2.411 +			//			double c = firsthalf.getArea();
   2.412 +			//			double d = bbox.difference(firsthalf).getArea();
   2.413 +			//			
   2.414 +			//			double e = b-c-d;
   2.415 +			//			double f = c-d;
   2.416 +			//			
   2.417 +			//			double kk = firsthalf.difference(bbox).difference(firsthalf).getArea();
   2.418 +			//			
   2.419 +			//			boolean g = firsthalf.equals(bbox.difference(firsthalf));
   2.420 +			//			boolean h = firsthalf.disjoint(bbox.difference(firsthalf));
   2.421 +			//			boolean i = bbox.equals(firsthalf.union(bbox.difference(firsthalf)));
   2.422 +			//			
   2.423 +			//			boolean j = firsthalf.intersects(polygon);
   2.424 +			//			boolean k = bbox.difference(firsthalf).intersects(polygon);
   2.425 +
   2.426  			Geometry A = polygon.intersection(firsthalf);
   2.427  			System.out.println("First half  : " + A.getCoordinates().length + " coordinates.");
   2.428  			//Geometry B = polygon.intersection(bbox.difference(firsthalf));
   2.429 @@ -394,31 +406,31 @@
   2.430  
   2.431  			StrabonPolyhedron polyA = ParseBigPolyhedron(A, algorithm, !horizontal, maxPoints);			
   2.432  			StrabonPolyhedron polyB = ParseBigPolyhedron(B, algorithm, !horizontal, maxPoints);
   2.433 -			
   2.434 +
   2.435  			return StrabonPolyhedron.quickUnion(polyA, polyB);
   2.436  		} else {
   2.437 -System.out.println("Found small polyhedron. Coordinates: " + polygon.getCoordinates().length);
   2.438 +			System.out.println("Found small polyhedron. Coordinates: " + polygon.getCoordinates().length);
   2.439  			return new StrabonPolyhedron(polygon, algorithm, maxPoints);
   2.440  		}
   2.441  	}
   2.442  
   2.443  	public StrabonPolyhedron(Polygon polygon, int algorithm, int maxPoints) throws Exception {
   2.444 -//		if (!polygon.isSimple())
   2.445 -//			throw new Exception(
   2.446 -//			"The polygon is not simple. Only simple polygons are supported");
   2.447 +		//		if (!polygon.isSimple())
   2.448 +		//			throw new Exception(
   2.449 +		//			"The polygon is not simple. Only simple polygons are supported");
   2.450  
   2.451  		Coordinate[] coordinates = polygon.getCoordinates();
   2.452 -		
   2.453 +
   2.454  		if (coordinates.length > maxPoints) {
   2.455  			this.geometry = ParseBigPolyhedron(polygon, algorithm, true, maxPoints).geometry;
   2.456  			return;
   2.457  		}		
   2.458 -		
   2.459 +
   2.460  		int distinctCoordinates = 0;
   2.461 -boolean fix = false;
   2.462 +		boolean fix = false;
   2.463  		for (int i = 0; i <= coordinates.length - 1; i++) {
   2.464  			Coordinate c1 = coordinates[i];
   2.465 -			
   2.466 +
   2.467  			if (i == (coordinates.length - 1)) {
   2.468  				// eimaste sto teleutaio simeio
   2.469  				if ((c1.x != coordinates[0].x) || (c1.y != coordinates[0].y)) {
   2.470 @@ -428,27 +440,27 @@
   2.471  					fix = true;
   2.472  				} else 
   2.473  					if ((c1.x == coordinates[i-1].x) && (c1.y == coordinates[i-1].y)) {
   2.474 -					//einai to idio me to proigoumeno opote den kanoume tipota giati
   2.475 -					//exoun hdh auksithei ta dinstinct
   2.476 -				} else {				
   2.477 -					// den einai to idio me to proigoumeno opote auksise ta distinct
   2.478 -					distinctCoordinates++;
   2.479 -				}
   2.480 +						//einai to idio me to proigoumeno opote den kanoume tipota giati
   2.481 +						//exoun hdh auksithei ta dinstinct
   2.482 +					} else {				
   2.483 +						// den einai to idio me to proigoumeno opote auksise ta distinct
   2.484 +						distinctCoordinates++;
   2.485 +					}
   2.486  				continue;
   2.487  			} 
   2.488 -			
   2.489 +
   2.490  			Coordinate c2 = coordinates[i+1];
   2.491 -			
   2.492 +
   2.493  			if ((c1.x != c2.x) || (c1.y != c2.y)) {
   2.494  				distinctCoordinates++;
   2.495  			}
   2.496  		}
   2.497 -		
   2.498 +
   2.499  		//System.out.println("---\n---\n---\n---\n---\n");
   2.500  		//System.out.println("--- Coordinates.length   = " + coordinates.length);
   2.501  		//System.out.println("--- Distinct coordinates = " + distinctCoordinates);
   2.502  		//System.out.println("---\n---\n---\n---\n---\n");
   2.503 -		
   2.504 +
   2.505  		// cgal wants counter clockwise order
   2.506  		//double[][] c = new double[coordinates.length - 1][2];
   2.507  		int counter = 0;
   2.508 @@ -456,59 +468,59 @@
   2.509  		for (int i = 0; i <= coordinates.length - 2; i++) {
   2.510  			Coordinate c1 = coordinates[i];
   2.511  			Coordinate c2 = coordinates[i+1];
   2.512 -			
   2.513 +
   2.514  			if ((c1.x != c2.x) || (c1.y != c2.y)) {
   2.515  				c[counter][0] = c1.x;
   2.516  				c[counter][1] = c1.y;
   2.517  				counter++;
   2.518  			}			
   2.519  		}
   2.520 -		
   2.521 +
   2.522  		if (fix) {
   2.523  			c[distinctCoordinates-1][0] = coordinates[coordinates.length-1].x;
   2.524  			c[distinctCoordinates-1][1] = coordinates[coordinates.length-1].y;
   2.525  		}
   2.526 -		
   2.527 +
   2.528  		//System.out.println("--- Counter              = " + counter);
   2.529  		//System.out.println("---\n---\n---\n---\n---\n");
   2.530 -		
   2.531 -//		BufferedWriter bww = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/cfunction.dat")));
   2.532 -//		BufferedWriter bw2 = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/original.dat")));
   2.533 -//		bww.write("void make_polygon(Polygon_2& polygon) {");
   2.534 -//		for (int i = 0; i < coordinates.length - 1; i++) {
   2.535 -//			Coordinate coordinate = coordinates[i];
   2.536 -//			bww.write("\tpolygon.push_back(Point_2(");
   2.537 -//			bww.write(new Double(coordinate.x).toString());
   2.538 -//			bww.write(",");
   2.539 -//			bww.write(new Double(coordinate.y).toString());
   2.540 -//			bww.write("));\n");
   2.541 -//			
   2.542 -//			bw2.write(new Double(coordinate.x).toString());
   2.543 -//			bw2.write(" ");
   2.544 -//			bw2.write(new Double(coordinate.y).toString());
   2.545 -//			bw2.write("\n");
   2.546 -//		}
   2.547 -//		bww.write("}\n");
   2.548 -//		bww.flush();
   2.549 -//		bww.close();
   2.550 -//		
   2.551 -//		bw2.flush();
   2.552 -//		bw2.close();
   2.553 +
   2.554 +		//		BufferedWriter bww = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/cfunction.dat")));
   2.555 +		//		BufferedWriter bw2 = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/original.dat")));
   2.556 +		//		bww.write("void make_polygon(Polygon_2& polygon) {");
   2.557 +		//		for (int i = 0; i < coordinates.length - 1; i++) {
   2.558 +		//			Coordinate coordinate = coordinates[i];
   2.559 +		//			bww.write("\tpolygon.push_back(Point_2(");
   2.560 +		//			bww.write(new Double(coordinate.x).toString());
   2.561 +		//			bww.write(",");
   2.562 +		//			bww.write(new Double(coordinate.y).toString());
   2.563 +		//			bww.write("));\n");
   2.564 +		//			
   2.565 +		//			bw2.write(new Double(coordinate.x).toString());
   2.566 +		//			bw2.write(" ");
   2.567 +		//			bw2.write(new Double(coordinate.y).toString());
   2.568 +		//			bw2.write("\n");
   2.569 +		//		}
   2.570 +		//		bww.write("}\n");
   2.571 +		//		bww.flush();
   2.572 +		//		bww.close();
   2.573 +		//		
   2.574 +		//		bw2.flush();
   2.575 +		//		bw2.close();
   2.576  
   2.577  		double start = System.nanoTime();
   2.578 -//		double[][][] convexified = Polyhedron.ConvexifyPolygon(c, algorithm);
   2.579 +		//		double[][][] convexified = Polyhedron.ConvexifyPolygon(c, algorithm);
   2.580  		double[][][] convexified = new double[1][2][3];		
   2.581 -		
   2.582 -//		if (convexified == null) {
   2.583 -//			throw new ParseGeometryException("Invalid geometry. Only simple geometries are supported.");
   2.584 -//		}
   2.585 -		
   2.586 +
   2.587 +		//		if (convexified == null) {
   2.588 +		//			throw new ParseGeometryException("Invalid geometry. Only simple geometries are supported.");
   2.589 +		//		}
   2.590 +
   2.591  		System.out.println("ConvexifyTime " + (System.nanoTime()-start));
   2.592  
   2.593  		int[] sizes = new int[255];
   2.594  		double min = Double.MAX_VALUE;
   2.595  		double max = Double.MIN_VALUE;
   2.596 -			
   2.597 +
   2.598  		for (int i = 0; i < convexified.length; i++) {
   2.599  			double[][] convexCoordinates = convexified[i];
   2.600  			for (int j = 0; j < convexCoordinates.length; j++) {
   2.601 @@ -517,55 +529,55 @@
   2.602  				if (convexCoordinates[j][0] < min)
   2.603  					min = convexCoordinates[j][0];
   2.604  			}
   2.605 -		
   2.606 +
   2.607  		}
   2.608 -				
   2.609 -//		String gnuPlotScript = "";
   2.610 -//		
   2.611 -//		for (int i = 0; i < convexified.length; i++) {
   2.612 -//			double[][] convexCoordinates = convexified[i];
   2.613 -//			sizes[convexCoordinates.length]++;
   2.614 -//			
   2.615 -//			BufferedWriter bw = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/data-" + i + ".dat")));
   2.616 -//			bw2 = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/script-" + i + ".gnuplot")));
   2.617 -//			for (int j = 0; j < convexCoordinates.length; j++) {
   2.618 -//				bw.write(new Double(convexCoordinates[j][0]).toString());
   2.619 -//				bw.write(" ");
   2.620 -//				bw.write(new Double(convexCoordinates[j][1]).toString());
   2.621 -//				bw.write("\n");
   2.622 -//
   2.623 -//			}
   2.624 -//			bw.flush();
   2.625 -//			bw.close();
   2.626 -//			
   2.627 -//			gnuPlotScript += "'data-" + i + ".dat' with lines,";
   2.628 -//			
   2.629 -//			bw2.write("set terminal postscript eps color\n");
   2.630 -//			bw2.write("set out '/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/geo-"+i+".eps'\n");
   2.631 -//			bw2.write("set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n");
   2.632 -//			bw2.write("plot ["+0.95*min+":"+1.05*max+"] 'data-" + i +".dat' with lines, 'original.dat' with lines\n");
   2.633 -//			bw2.flush();
   2.634 -//			bw2.close();
   2.635 -//		}
   2.636 -//			
   2.637 -//		gnuPlotScript = "plot ["+0.95*min+":"+1.05*max+"] " + gnuPlotScript.substring(0, gnuPlotScript.length()-1);
   2.638 -//		gnuPlotScript = "set terminal postscript eps color\n" +
   2.639 -//						"set out '/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/all.eps'\n" +
   2.640 -//						"set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n" + 
   2.641 -//						gnuPlotScript;
   2.642 -//		
   2.643 -//		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/script-all.gnuplot")));
   2.644 -//		bw.write(gnuPlotScript);
   2.645 -//		bw.flush();
   2.646 -//		bw.close();
   2.647 -//		
   2.648 -//		for (int i = 0; i < convexified.length; i++) {
   2.649 -//			Runtime.getRuntime().exec("gnuplot /home/kkyzir/Desktop/Spatial\\ data/ssg4env/geometries/gnuplot/script-"+i+".gnuplot");
   2.650 -//		}
   2.651 -//		
   2.652 -//		Runtime.getRuntime().exec("gnuplot /home/kkyzir/Desktop/Spatial\\ data/ssg4env/geometries/gnuplot/script-all.gnuplot");
   2.653 -//		
   2.654 -		
   2.655 +
   2.656 +		//		String gnuPlotScript = "";
   2.657 +		//		
   2.658 +		//		for (int i = 0; i < convexified.length; i++) {
   2.659 +		//			double[][] convexCoordinates = convexified[i];
   2.660 +		//			sizes[convexCoordinates.length]++;
   2.661 +		//			
   2.662 +		//			BufferedWriter bw = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/data-" + i + ".dat")));
   2.663 +		//			bw2 = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/script-" + i + ".gnuplot")));
   2.664 +		//			for (int j = 0; j < convexCoordinates.length; j++) {
   2.665 +		//				bw.write(new Double(convexCoordinates[j][0]).toString());
   2.666 +		//				bw.write(" ");
   2.667 +		//				bw.write(new Double(convexCoordinates[j][1]).toString());
   2.668 +		//				bw.write("\n");
   2.669 +		//
   2.670 +		//			}
   2.671 +		//			bw.flush();
   2.672 +		//			bw.close();
   2.673 +		//			
   2.674 +		//			gnuPlotScript += "'data-" + i + ".dat' with lines,";
   2.675 +		//			
   2.676 +		//			bw2.write("set terminal postscript eps color\n");
   2.677 +		//			bw2.write("set out '/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/geo-"+i+".eps'\n");
   2.678 +		//			bw2.write("set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n");
   2.679 +		//			bw2.write("plot ["+0.95*min+":"+1.05*max+"] 'data-" + i +".dat' with lines, 'original.dat' with lines\n");
   2.680 +		//			bw2.flush();
   2.681 +		//			bw2.close();
   2.682 +		//		}
   2.683 +		//			
   2.684 +		//		gnuPlotScript = "plot ["+0.95*min+":"+1.05*max+"] " + gnuPlotScript.substring(0, gnuPlotScript.length()-1);
   2.685 +		//		gnuPlotScript = "set terminal postscript eps color\n" +
   2.686 +		//						"set out '/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/all.eps'\n" +
   2.687 +		//						"set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n" + 
   2.688 +		//						gnuPlotScript;
   2.689 +		//		
   2.690 +		//		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/script-all.gnuplot")));
   2.691 +		//		bw.write(gnuPlotScript);
   2.692 +		//		bw.flush();
   2.693 +		//		bw.close();
   2.694 +		//		
   2.695 +		//		for (int i = 0; i < convexified.length; i++) {
   2.696 +		//			Runtime.getRuntime().exec("gnuplot /home/kkyzir/Desktop/Spatial\\ data/ssg4env/geometries/gnuplot/script-"+i+".gnuplot");
   2.697 +		//		}
   2.698 +		//		
   2.699 +		//		Runtime.getRuntime().exec("gnuplot /home/kkyzir/Desktop/Spatial\\ data/ssg4env/geometries/gnuplot/script-all.gnuplot");
   2.700 +		//		
   2.701 +
   2.702  		//Geometry[] collection = new Geometry[convexified.length];
   2.703  		Polygon[] collection = new Polygon[convexified.length];
   2.704  		System.out.println("Convex parts: " + convexified.length);		
   2.705 @@ -604,52 +616,68 @@
   2.706  	}
   2.707  
   2.708  	public StrabonPolyhedron(String geometry) throws Exception {
   2.709 -        if (geometry.startsWith("POINT") || 
   2.710 -                        geometry.startsWith("LINESTRING") || 
   2.711 -                        geometry.startsWith("POLYGON") || 
   2.712 -                        geometry.startsWith("MULTIPOINT") || 
   2.713 -                        geometry.startsWith("MULTILINESTRING") || 
   2.714 -                        geometry.startsWith("MULTIPOLYGON") || 
   2.715 -                        geometry.startsWith("GEOMETRYCOLLECTION")) {
   2.716 -                Geometry geo = new WKTReader().read(geometry);
   2.717 -                this.geometry = new StrabonPolyhedron(geo).geometry;
   2.718 -        } else {
   2.719 -                //Polyhedron polyhedron = new Polyhedron(geometry);
   2.720 -                //String polyhedronWKT = polyhedron.toWKT();
   2.721 -                //WKTReader reader = new WKTReader();
   2.722 -                //Geometry geo = reader.read(polyhedronWKT);
   2.723 -                //
   2.724 -                //if (!EnableConstraintRepresentation) {
   2.725 -                //	this.geometry = geo.union(geo);
   2.726 -                //}
   2.727 -        }
   2.728 -}
   2.729 -	
   2.730 +		int geomSRID = 4326;
   2.731 +		if(geometry.contains(";"))
   2.732 +		{
   2.733 +			int whereToCut = geometry.lastIndexOf('/');
   2.734 +			geomSRID = Integer.parseInt(geometry.substring(whereToCut+1));
   2.735 +			whereToCut = geometry.indexOf(';');
   2.736 +			geometry.substring(0,whereToCut);
   2.737 +		}
   2.738 +		if (geometry.startsWith("POINT") || 
   2.739 +				geometry.startsWith("LINESTRING") || 
   2.740 +				geometry.startsWith("POLYGON") || 
   2.741 +				geometry.startsWith("MULTIPOINT") || 
   2.742 +				geometry.startsWith("MULTILINESTRING") || 
   2.743 +				geometry.startsWith("MULTIPOLYGON") || 
   2.744 +				geometry.startsWith("GEOMETRYCOLLECTION")) {
   2.745 +			Geometry geo = new WKTReader().read(geometry);
   2.746 +			this.geometry = new StrabonPolyhedron(geo).geometry;
   2.747 +			//Default 
   2.748 +			this.geometry.setSRID(geomSRID);
   2.749 +		} else {
   2.750 +			//Polyhedron polyhedron = new Polyhedron(geometry);
   2.751 +			//String polyhedronWKT = polyhedron.toWKT();
   2.752 +			//WKTReader reader = new WKTReader();
   2.753 +			//Geometry geo = reader.read(polyhedronWKT);
   2.754 +			//
   2.755 +			//if (!EnableConstraintRepresentation) {
   2.756 +			//	this.geometry = geo.union(geo);
   2.757 +			//}
   2.758 +		}
   2.759 +	}
   2.760 +
   2.761  	public StrabonPolyhedron(String WKT, int algorithm) throws Exception {
   2.762  		Geometry geo = new WKTReader().read(WKT);
   2.763  		this.geometry = new StrabonPolyhedron(geo, algorithm).geometry;
   2.764  	}
   2.765 -	
   2.766 +
   2.767  	public StrabonPolyhedron(String WKT, int algorithm, int maxPoints) throws Exception {
   2.768  		Geometry geo = new WKTReader().read(WKT);
   2.769  		this.geometry = new StrabonPolyhedron(geo, algorithm).geometry;
   2.770  	}
   2.771  
   2.772  	public StrabonPolyhedron(byte[] byteArray) throws ParseException {
   2.773 -		
   2.774 +
   2.775  		this.geometry = new WKBReader().read(byteArray);
   2.776 -//		System.out.println(geometry.toString()+" "+geometry.getSRID());
   2.777 +		//		System.out.println(geometry.toString()+" "+geometry.getSRID());
   2.778 +	}
   2.779 +
   2.780 +	public StrabonPolyhedron(byte[] byteArray, int srid) throws ParseException {
   2.781 +
   2.782 +		this.geometry = new WKBReader().read(byteArray);
   2.783 +		this.geometry.setSRID(srid);
   2.784  	}
   2.785  
   2.786  	public String toConstraints() //throws ConversionException 
   2.787  	{
   2.788  		if (this.geometry.isEmpty())
   2.789  			return "";
   2.790 -		
   2.791 +
   2.792  		if (!EnableConstraintRepresentation) {
   2.793  			return "Constraint representation is disabled.";
   2.794  		}
   2.795 -		
   2.796 +
   2.797  		//Polyhedron poly = new Polyhedron(this.geometry);
   2.798  		//return poly.toConstraints();
   2.799  		return "";
   2.800 @@ -662,12 +690,12 @@
   2.801  	public String toText() {
   2.802  		return this.geometry.toText();
   2.803  	}
   2.804 -	
   2.805 +
   2.806  	public byte[] toWKB() {
   2.807  		WKBWriter writer = new WKBWriter();
   2.808  		return writer.write(this.geometry);		
   2.809  	}
   2.810 -	
   2.811 +
   2.812  	public String toWKT() {
   2.813  		WKTWriter writer = new WKTWriter();
   2.814  		return writer.write(this.geometry);		
   2.815 @@ -677,69 +705,91 @@
   2.816  		return new WKBWriter().write(this.geometry);
   2.817  	}
   2.818  
   2.819 +
   2.820 +
   2.821  	public static StrabonPolyhedron union(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   2.822  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.823 -		poly.geometry = A.geometry.union(B.geometry);
   2.824 +
   2.825 +		int targetSRID = A.getGeometry().getSRID();
   2.826 +		int sourceSRID = B.getGeometry().getSRID();
   2.827 +		Geometry x = convertSRID(B.getGeometry(), sourceSRID, targetSRID);
   2.828 +
   2.829 +		poly.geometry = A.geometry.union(x);
   2.830  
   2.831  		return poly;
   2.832  	}
   2.833 -	
   2.834 +
   2.835  	public static StrabonPolyhedron buffer(StrabonPolyhedron A, double B) throws Exception {
   2.836  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.837  		poly.geometry = A.geometry.buffer(B);
   2.838 -		
   2.839 +
   2.840  		return poly;
   2.841  	}
   2.842 -	
   2.843 +
   2.844  	public static StrabonPolyhedron envelope(StrabonPolyhedron A) throws Exception {
   2.845  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.846  		poly.geometry = A.geometry.getEnvelope();
   2.847  
   2.848  		return poly;
   2.849  	}
   2.850 -	
   2.851 +
   2.852  	public static StrabonPolyhedron convexHull(StrabonPolyhedron A) throws Exception {
   2.853  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.854  		poly.geometry = A.geometry.convexHull();
   2.855  
   2.856  		return poly;
   2.857  	}
   2.858 -	
   2.859 +
   2.860  	public static StrabonPolyhedron boundary(StrabonPolyhedron A) throws Exception {
   2.861  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.862  		poly.geometry = A.geometry.getBoundary();
   2.863  
   2.864  		return poly;
   2.865  	}
   2.866 -	
   2.867 +
   2.868  	public static StrabonPolyhedron intersection(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   2.869 -		Geometry geo = A.geometry.intersection(B.geometry);
   2.870 -		
   2.871 +
   2.872 +		int targetSRID = A.getGeometry().getSRID();
   2.873 +		int sourceSRID = B.getGeometry().getSRID();
   2.874 +		Geometry x = convertSRID(B.getGeometry(), sourceSRID, targetSRID);
   2.875 +		Geometry geo = A.geometry.intersection(x);
   2.876 +
   2.877  		return new StrabonPolyhedron(geo);
   2.878  	}
   2.879  
   2.880  	public static StrabonPolyhedron difference(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   2.881  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.882 -		poly.geometry = A.geometry.difference(B.geometry);
   2.883 +
   2.884 +		int targetSRID = A.getGeometry().getSRID();
   2.885 +		int sourceSRID = B.getGeometry().getSRID();
   2.886 +		Geometry x = convertSRID(B.getGeometry(), sourceSRID, targetSRID);
   2.887 +
   2.888 +		poly.geometry = A.geometry.difference(x);
   2.889  
   2.890  		return poly;
   2.891  	}
   2.892 -	
   2.893 +
   2.894  	public static StrabonPolyhedron symDifference(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   2.895  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.896 -		poly.geometry = A.geometry.symDifference(B.geometry);
   2.897 +		int targetSRID = A.getGeometry().getSRID();
   2.898 +		int sourceSRID = B.getGeometry().getSRID();
   2.899 +		Geometry x = convertSRID(B.getGeometry(), sourceSRID, targetSRID);
   2.900 +		poly.geometry = A.geometry.symDifference(x);
   2.901  
   2.902  		return poly;
   2.903  	}
   2.904 -	
   2.905 +
   2.906  	public static double area(StrabonPolyhedron A) throws Exception {
   2.907  		return A.geometry.getArea();
   2.908  	}
   2.909 -	
   2.910 +
   2.911  	public static double distance(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   2.912 -		return A.geometry.distance(B.geometry);
   2.913 +		int targetSRID = A.getGeometry().getSRID();
   2.914 +		int sourceSRID = B.getGeometry().getSRID();
   2.915 +		Geometry x = convertSRID(B.getGeometry(), sourceSRID, targetSRID);
   2.916 +		return A.geometry.distance(x);
   2.917  	}
   2.918 -	
   2.919 +
   2.920  	public static StrabonPolyhedron project(StrabonPolyhedron A, int[] dims) throws Exception {
   2.921  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.922  		ProjectionsFilter filter = new ProjectionsFilter(dims);
   2.923 @@ -760,13 +810,13 @@
   2.924  	public static StrabonPolyhedron quickUnion(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
   2.925  		System.out.println("Merging polyhedrons: A.coordinates=" + A.getGeometry().getCoordinates().length + 
   2.926  				", B.coordinates=" + B.getGeometry().getCoordinates().length);
   2.927 -		
   2.928 +
   2.929  		StrabonPolyhedron poly = new StrabonPolyhedron();
   2.930  		int polygons = 0;
   2.931  		if (Polygon.class.isInstance(A.geometry)) {			
   2.932  			polygons++;
   2.933  		} else if (MultiPolygon.class.isInstance(A.geometry)) {
   2.934 -				polygons += ((MultiPolygon)(A.geometry)).getNumGeometries();
   2.935 +			polygons += ((MultiPolygon)(A.geometry)).getNumGeometries();
   2.936  		}
   2.937  		if (Polygon.class.isInstance(B.geometry)) {
   2.938  			polygons++;
   2.939 @@ -801,13 +851,13 @@
   2.940  				index++;
   2.941  			}
   2.942  		}
   2.943 -		
   2.944 +
   2.945  		poly.geometry = new MultiPolygon(polys, new GeometryFactory());
   2.946  
   2.947  		return poly;
   2.948  	}
   2.949  
   2.950 -	
   2.951 +
   2.952  	public StrabonPolyhedron getBuffer(double distance) throws Exception {
   2.953  		Geometry geo = this.geometry.buffer(distance);
   2.954  		System.out.println("TEMPORARY ----> BUFFER EXECUTED!!");
   2.955 @@ -833,21 +883,21 @@
   2.956  	public Geometry getGeometry() {
   2.957  		return this.geometry;
   2.958  	}
   2.959 -	
   2.960 +
   2.961  	public int getNumPoints() {
   2.962  		return this.geometry.getNumPoints();
   2.963  	}
   2.964 -	
   2.965 +
   2.966  	private static String FindGeoType(Geometry geo) {
   2.967  		return 
   2.968 -		Point.class.isInstance(geo) ? "Point" :
   2.969 -			MultiPoint.class.isInstance(geo) ? "MultiPoint" :
   2.970 -				LineString.class.isInstance(geo) ? "LineString" :
   2.971 -					MultiLineString.class.isInstance(geo) ? "MultiLineString" :
   2.972 -						Polygon.class.isInstance(geo) ? "Polygon" :
   2.973 -							MultiPolygon.class.isInstance(geo) ? "MultiPolygon" :
   2.974 -								GeometryCollection.class.isInstance(geo) ? "GeometryCollection" : 
   2.975 -									"Unknown";
   2.976 +				Point.class.isInstance(geo) ? "Point" :
   2.977 +					MultiPoint.class.isInstance(geo) ? "MultiPoint" :
   2.978 +						LineString.class.isInstance(geo) ? "LineString" :
   2.979 +							MultiLineString.class.isInstance(geo) ? "MultiLineString" :
   2.980 +								Polygon.class.isInstance(geo) ? "Polygon" :
   2.981 +									MultiPolygon.class.isInstance(geo) ? "MultiPolygon" :
   2.982 +										GeometryCollection.class.isInstance(geo) ? "GeometryCollection" : 
   2.983 +											"Unknown";
   2.984  	}
   2.985  
   2.986  	public static void main(String[] args) {		
   2.987 @@ -860,23 +910,23 @@
   2.988  		for (int i = 0; i < 100; i++) {
   2.989  			try {			
   2.990  				String WKT = "POLYGON(("
   2.991 -					+ "342164.38954080583 5536425.686612717 , "
   2.992 -					+ "341626.21626698505 5536449.481769281 , "
   2.993 -					+ "341533.2278808594  5536525.216353727 , "
   2.994 -					+ "341233.98619135865 5536475.226529011 , "
   2.995 -					+ "341127.21075357014 5536983.653040268 , "
   2.996 -					+ "341215.02899532224 5537144.780243294 , "
   2.997 -					+ "340955.95747845445 5537799.537709246 , "
   2.998 -					+ "343211.19068847306 5537879.8934287615, "
   2.999 -					+ "343442.00065602345 5537324.533655008 , "
  2.1000 -					+ "343314.06638177147 5537172.864526819 , "
  2.1001 -					+ "343297.4180221379  5536922.705445975 , "
  2.1002 -					+ "342969.57149877446 5536768.366861146 , "
  2.1003 -					+ "342464.2661603174  5536951.549574836 , "
  2.1004 -					+ "342296.77657097764 5536842.341803761 , "
  2.1005 -					+ "342222.48151387094 5536641.402704332 , "
  2.1006 -					+ "342286.9145411997  5536458.319970291 , "
  2.1007 -					+ "342164.38954080583 5536425.686612717" + "))";
  2.1008 +						+ "342164.38954080583 5536425.686612717 , "
  2.1009 +						+ "341626.21626698505 5536449.481769281 , "
  2.1010 +						+ "341533.2278808594  5536525.216353727 , "
  2.1011 +						+ "341233.98619135865 5536475.226529011 , "
  2.1012 +						+ "341127.21075357014 5536983.653040268 , "
  2.1013 +						+ "341215.02899532224 5537144.780243294 , "
  2.1014 +						+ "340955.95747845445 5537799.537709246 , "
  2.1015 +						+ "343211.19068847306 5537879.8934287615, "
  2.1016 +						+ "343442.00065602345 5537324.533655008 , "
  2.1017 +						+ "343314.06638177147 5537172.864526819 , "
  2.1018 +						+ "343297.4180221379  5536922.705445975 , "
  2.1019 +						+ "342969.57149877446 5536768.366861146 , "
  2.1020 +						+ "342464.2661603174  5536951.549574836 , "
  2.1021 +						+ "342296.77657097764 5536842.341803761 , "
  2.1022 +						+ "342222.48151387094 5536641.402704332 , "
  2.1023 +						+ "342286.9145411997  5536458.319970291 , "
  2.1024 +						+ "342164.38954080583 5536425.686612717" + "))";
  2.1025  
  2.1026  				start = System.nanoTime();
  2.1027  				Geometry geo = new WKTReader().read(WKT);
  2.1028 @@ -920,7 +970,7 @@
  2.1029  	public String stringValue() {
  2.1030  		return this.toWKT();
  2.1031  	}
  2.1032 -	
  2.1033 +
  2.1034  	@Override
  2.1035  	public boolean equals(Object other) {
  2.1036  
  2.1037 @@ -930,7 +980,7 @@
  2.1038  			{
  2.1039  				return true;
  2.1040  			}
  2.1041 -			
  2.1042 +
  2.1043  		}
  2.1044  		return false;
  2.1045  	}
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Tue Mar 13 15:01:43 2012 +0200
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Wed Mar 14 15:27:35 2012 +0200
     3.3 @@ -346,17 +346,23 @@
     3.4  				//Must compute the spatial construct at this point
     3.5  				ValueExpr expr = spatialAggregates.get(name);
     3.6  
     3.7 -				StrabonPolyhedron poly = null;
     3.8  				Value val = null;
     3.9 -				//LiteralImpl lit 
    3.10  				try {
    3.11  					val = evaluateConstruct(expr, this.prototype);
    3.12  					} catch (Exception e) {
    3.13  					e.printStackTrace();
    3.14  				}
    3.15  				if (val != null) {
    3.16 -					Literal wkt = new LiteralImpl(val.toString(),new URIImpl(StrabonPolyhedron.ogcGeometry));
    3.17 -					sol.setBinding(name,wkt);
    3.18 +					if(val instanceof StrabonPolyhedron)
    3.19 +					{
    3.20 +						String label = val.toString()+";http://www.opengis.net/def/crs/EPSG/0/"+((StrabonPolyhedron)val).getGeometry().getSRID();
    3.21 +						Literal wkt = new LiteralImpl(label,new URIImpl(StrabonPolyhedron.ogcGeometry));
    3.22 +						sol.setBinding(name,wkt);
    3.23 +					}
    3.24 +					else
    3.25 +					{
    3.26 +						sol.setBinding(name, val);
    3.27 +					}
    3.28  				}
    3.29  
    3.30  			}
    3.31 @@ -401,14 +407,6 @@
    3.32  					{
    3.33  						leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
    3.34  						rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
    3.35 -
    3.36 -						int leftSRID = leftArg.getGeometry().getSRID();
    3.37 -						int rightSRID = rightArg.getGeometry().getSRID();
    3.38 -						if(leftSRID != rightSRID)
    3.39 -						{
    3.40 -							//XXX Will have to express the second argument in the SRID of the first
    3.41 -							rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
    3.42 -						}
    3.43  						return StrabonPolyhedron.union(leftArg, rightArg);
    3.44  					}
    3.45  				}
    3.46 @@ -444,39 +442,18 @@
    3.47  				{
    3.48  					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
    3.49  					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
    3.50 -					int leftSRID = leftArg.getGeometry().getSRID();
    3.51 -					int rightSRID = rightArg.getGeometry().getSRID();
    3.52 -					if(leftSRID != rightSRID)
    3.53 -					{
    3.54 -						//XXX Will have to express the second argument in the SRID of the first
    3.55 -						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
    3.56 -					}
    3.57  					return StrabonPolyhedron.intersection(leftArg, rightArg);
    3.58  				}
    3.59  				else if(function instanceof DifferenceFunc)
    3.60  				{
    3.61  					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
    3.62  					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
    3.63 -					int leftSRID = leftArg.getGeometry().getSRID();
    3.64 -					int rightSRID = rightArg.getGeometry().getSRID();
    3.65 -					if(leftSRID != rightSRID)
    3.66 -					{
    3.67 -						//XXX Will have to express the second argument in the SRID of the first
    3.68 -						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
    3.69 -					}
    3.70  					return StrabonPolyhedron.difference(leftArg, rightArg);
    3.71  				}
    3.72  				else if(function instanceof SymDifferenceFunc)
    3.73  				{
    3.74  					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
    3.75  					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
    3.76 -					int leftSRID = leftArg.getGeometry().getSRID();
    3.77 -					int rightSRID = rightArg.getGeometry().getSRID();
    3.78 -					if(leftSRID != rightSRID)
    3.79 -					{
    3.80 -						//XXX Will have to express the second argument in the SRID of the first
    3.81 -						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
    3.82 -					}
    3.83  					return StrabonPolyhedron.symDifference(leftArg, rightArg);
    3.84  				}
    3.85  				//FOR HAVING!!
    3.86 @@ -489,13 +466,6 @@
    3.87  				{
    3.88  					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
    3.89  					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
    3.90 -					int leftSRID = leftArg.getGeometry().getSRID();
    3.91 -					int rightSRID = rightArg.getGeometry().getSRID();
    3.92 -					if(leftSRID != rightSRID)
    3.93 -					{
    3.94 -						//XXX Will have to express the second argument in the SRID of the first
    3.95 -						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
    3.96 -					}
    3.97  					return vf.createLiteral(""+StrabonPolyhedron.distance(leftArg, rightArg), XMLSchema.DOUBLE);
    3.98  				}
    3.99  				else
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java	Tue Mar 13 15:01:43 2012 +0200
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java	Wed Mar 14 15:27:35 2012 +0200
     4.3 @@ -371,11 +371,11 @@
     4.4  	 * @throws ParseException 
     4.5  	 */
     4.6  
     4.7 -	public GeneralDBPolyhedron getRdbmsPolyhedron(Number num, String datatype, byte[] pointSet)  {
     4.8 +	public GeneralDBPolyhedron getRdbmsPolyhedron(Number num, String datatype, byte[] wkb, int srid)  {
     4.9  
    4.10  		Number id = ids.idOf(num);
    4.11  		try {
    4.12 -			return new GeneralDBPolyhedron(id, literals.getIdVersion(), vf.createURI(datatype), pointSet);
    4.13 +			return new GeneralDBPolyhedron(id, literals.getIdVersion(), vf.createURI(datatype), wkb, srid);
    4.14  		} catch (IOException e) {
    4.15  			e.printStackTrace();
    4.16  		} catch (ClassNotFoundException e) {
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Mar 13 15:01:43 2012 +0200
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Wed Mar 14 15:27:35 2012 +0200
     5.3 @@ -169,8 +169,8 @@
     5.4  	@Override
     5.5  	public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr,
     5.6  			BindingSet bindings)
     5.7 -			throws QueryEvaluationException
     5.8 -			{
     5.9 +					throws QueryEvaluationException
    5.10 +					{
    5.11  		if (expr instanceof GeneralDBSelectQuery)
    5.12  			return evaluate((GeneralDBSelectQuery)expr, bindings);
    5.13  		else if (expr instanceof Group) {
    5.14 @@ -180,11 +180,11 @@
    5.15  			return evaluate((Order)expr, bindings);
    5.16  		}
    5.17  		return super.evaluate(expr, bindings);
    5.18 -			}
    5.19 +					}
    5.20  	@Override
    5.21  	public Value evaluate(ValueExpr expr, BindingSet bindings)
    5.22 -	throws ValueExprEvaluationException, QueryEvaluationException
    5.23 -	{
    5.24 +			throws ValueExprEvaluationException, QueryEvaluationException
    5.25 +			{
    5.26  		if (expr instanceof Var) {
    5.27  			return evaluate((Var)expr, bindings);
    5.28  		}
    5.29 @@ -192,7 +192,7 @@
    5.30  			return evaluate((FunctionCall)expr, bindings);
    5.31  		}
    5.32  		return super.evaluate(expr, bindings);
    5.33 -	}
    5.34 +			}
    5.35  
    5.36  	/**
    5.37  	 * Had to use it for the cases met in group by (Union as an aggregate)
    5.38 @@ -245,7 +245,7 @@
    5.39  	@Override
    5.40  	public Value evaluate(FunctionCall fc, BindingSet bindings)
    5.41  	{
    5.42 -//		System.out.println("FunctionCall placeholder");
    5.43 +		//		System.out.println("FunctionCall placeholder");
    5.44  
    5.45  		if(fc.getParentNode() instanceof Avg)
    5.46  		{
    5.47 @@ -373,62 +373,101 @@
    5.48  
    5.49  				if(function instanceof AboveFunc)
    5.50  				{
    5.51 -					funcResult = leftGeom.getEnvelopeInternal().getMinY() > rightGeom.getEnvelopeInternal().getMaxY();
    5.52 +					int targetSRID = leftGeom.getSRID();
    5.53 +					int sourceSRID = rightGeom.getSRID();
    5.54 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
    5.55 +					funcResult = leftGeom.getEnvelopeInternal().getMinY() > rightConverted.getEnvelopeInternal().getMaxY();
    5.56  				}
    5.57  				else if(function instanceof AnyInteractFunc)
    5.58  				{
    5.59 -					funcResult = leftGeom.intersects(rightGeom);
    5.60 +					int targetSRID = leftGeom.getSRID();
    5.61 +					int sourceSRID = rightGeom.getSRID();
    5.62 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
    5.63 +					funcResult = leftGeom.intersects(rightConverted);
    5.64  				}
    5.65  				else if(function instanceof BelowFunc)
    5.66  				{
    5.67 -					funcResult = leftGeom.getEnvelopeInternal().getMaxY() < rightGeom.getEnvelopeInternal().getMinY();
    5.68 +					int targetSRID = leftGeom.getSRID();
    5.69 +					int sourceSRID = rightGeom.getSRID();
    5.70 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
    5.71 +					funcResult = leftGeom.getEnvelopeInternal().getMaxY() < rightConverted.getEnvelopeInternal().getMinY();
    5.72  				}
    5.73  				else if(function instanceof ContainsFunc)
    5.74  				{
    5.75 -					funcResult = leftGeom.contains(rightGeom);
    5.76 +					int targetSRID = leftGeom.getSRID();
    5.77 +					int sourceSRID = rightGeom.getSRID();
    5.78 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
    5.79 +					funcResult = leftGeom.contains(rightConverted);
    5.80  				}
    5.81  				else if(function instanceof CoveredByFunc)
    5.82  				{
    5.83 -					funcResult = leftGeom.coveredBy(rightGeom);
    5.84 +					int targetSRID = leftGeom.getSRID();
    5.85 +					int sourceSRID = rightGeom.getSRID();
    5.86 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
    5.87 +					funcResult = leftGeom.coveredBy(rightConverted);
    5.88  				}
    5.89  				else if(function instanceof CoversFunc)
    5.90  				{
    5.91 -					funcResult = leftGeom.covers(rightGeom);
    5.92 +					int targetSRID = leftGeom.getSRID();
    5.93 +					int sourceSRID = rightGeom.getSRID();
    5.94 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
    5.95 +					funcResult = leftGeom.covers(rightConverted);
    5.96  				}
    5.97  				else if(function instanceof DisjointFunc)
    5.98  				{
    5.99 -					funcResult = leftGeom.disjoint(rightGeom);
   5.100 +					int targetSRID = leftGeom.getSRID();
   5.101 +					int sourceSRID = rightGeom.getSRID();
   5.102 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.103 +					funcResult = leftGeom.disjoint(rightConverted);
   5.104  				}
   5.105  				else if(function instanceof EqualsFunc)
   5.106  				{
   5.107 -					funcResult = leftGeom.equals(rightGeom);
   5.108 +					int targetSRID = leftGeom.getSRID();
   5.109 +					int sourceSRID = rightGeom.getSRID();
   5.110 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.111 +					funcResult = leftGeom.equals(rightConverted);
   5.112  				}
   5.113  				else if(function instanceof InsideFunc)
   5.114  				{
   5.115 -					funcResult = leftGeom.within(rightGeom);
   5.116 +					int targetSRID = leftGeom.getSRID();
   5.117 +					int sourceSRID = rightGeom.getSRID();
   5.118 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.119 +					funcResult = leftGeom.within(rightConverted);
   5.120  				}
   5.121  				else if(function instanceof LeftFunc)
   5.122  				{
   5.123 -					funcResult = leftGeom.getEnvelopeInternal().getMaxX() < rightGeom.getEnvelopeInternal().getMinX();
   5.124 +					int targetSRID = leftGeom.getSRID();
   5.125 +					int sourceSRID = rightGeom.getSRID();
   5.126 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.127 +					funcResult = leftGeom.getEnvelopeInternal().getMaxX() < rightConverted.getEnvelopeInternal().getMinX();
   5.128  				}
   5.129  				else if(function instanceof OverlapFunc)
   5.130  				{
   5.131 -					funcResult = leftGeom.overlaps(rightGeom);
   5.132 +					int targetSRID = leftGeom.getSRID();
   5.133 +					int sourceSRID = rightGeom.getSRID();
   5.134 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.135 +					//System.out.println(rightConverted.toString());
   5.136 +					funcResult = leftGeom.overlaps(rightConverted);
   5.137  				}
   5.138  				else if(function instanceof RightFunc)
   5.139  				{
   5.140 -					funcResult = leftGeom.getEnvelopeInternal().getMinX() > rightGeom.getEnvelopeInternal().getMaxX();
   5.141 -
   5.142 +					int targetSRID = leftGeom.getSRID();
   5.143 +					int sourceSRID = rightGeom.getSRID();
   5.144 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.145 +					funcResult = leftGeom.getEnvelopeInternal().getMinX() > rightConverted.getEnvelopeInternal().getMaxX();
   5.146  				}
   5.147  				else if(function instanceof TouchFunc)
   5.148  				{
   5.149 -					funcResult = leftGeom.touches(rightGeom);
   5.150 +					int targetSRID = leftGeom.getSRID();
   5.151 +					int sourceSRID = rightGeom.getSRID();
   5.152 +					Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID);
   5.153 +					funcResult = leftGeom.touches(rightConverted);
   5.154  				}
   5.155  
   5.156  				return funcResult ? BooleanLiteralImpl.TRUE : BooleanLiteralImpl.FALSE;
   5.157  			}
   5.158  			else {
   5.159 -			//Default Sesame Behavior
   5.160 +				//Default Sesame Behavior
   5.161  				List<ValueExpr> args = fc.getArgs();
   5.162  
   5.163  				Value[] argValues = new Value[args.size()];
   5.164 @@ -451,49 +490,48 @@
   5.165  		if(function.getURI().equals(StrabonPolyhedron.union))
   5.166  		{
   5.167  			StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron();
   5.168 -
   5.169 -			return new StrabonPolyhedron(leftArg.getGeometry().union(rightArg.getGeometry()));
   5.170 +			return StrabonPolyhedron.union(leftArg, rightArg);
   5.171  		}
   5.172  		else if(function.getURI().equals(StrabonPolyhedron.buffer))
   5.173  		{
   5.174  			if(right instanceof LiteralImpl)
   5.175  			{
   5.176  				LiteralImpl radius = (LiteralImpl) right;
   5.177 -				return new StrabonPolyhedron(leftArg.getGeometry().buffer(radius.doubleValue()));
   5.178 +				return StrabonPolyhedron.buffer(leftArg,radius.doubleValue());
   5.179  			}
   5.180  			else if(right instanceof RdbmsLiteral)
   5.181  			{
   5.182  				RdbmsLiteral radius = (RdbmsLiteral) right;
   5.183 -				return new StrabonPolyhedron(leftArg.getGeometry().buffer(radius.doubleValue()));
   5.184 +				return StrabonPolyhedron.buffer(leftArg,radius.doubleValue());
   5.185  			}
   5.186  
   5.187  		}
   5.188  		else if(function.getURI().equals(StrabonPolyhedron.envelope))
   5.189  		{
   5.190 -			return new StrabonPolyhedron(leftArg.getGeometry().getEnvelope());
   5.191 +			return StrabonPolyhedron.envelope(leftArg);
   5.192  		}
   5.193  		else if(function.getURI().equals(StrabonPolyhedron.convexHull))
   5.194  		{
   5.195 -			return new StrabonPolyhedron(leftArg.getGeometry().convexHull());
   5.196 +			return StrabonPolyhedron.convexHull(leftArg);
   5.197  		}
   5.198  		else if(function.getURI().equals(StrabonPolyhedron.boundary))
   5.199  		{
   5.200 -			return new StrabonPolyhedron(leftArg.getGeometry().getBoundary());
   5.201 +			return StrabonPolyhedron.boundary(leftArg);
   5.202  		}
   5.203  		else if(function.getURI().equals(StrabonPolyhedron.intersection))
   5.204  		{
   5.205  			StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron();
   5.206 -			return new StrabonPolyhedron(leftArg.getGeometry().intersection(rightArg.getGeometry()));
   5.207 +			return StrabonPolyhedron.intersection(leftArg, rightArg);
   5.208  		}
   5.209  		else if(function.getURI().equals(StrabonPolyhedron.difference))
   5.210  		{
   5.211  			StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron();
   5.212 -			return new StrabonPolyhedron(leftArg.getGeometry().difference(rightArg.getGeometry()));
   5.213 +			return StrabonPolyhedron.difference(leftArg, rightArg);		
   5.214  		}
   5.215  		else if(function.getURI().equals(StrabonPolyhedron.symDifference))
   5.216  		{
   5.217  			StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron();
   5.218 -			return new StrabonPolyhedron(leftArg.getGeometry().symDifference(rightArg.getGeometry()));
   5.219 +			return StrabonPolyhedron.symDifference(leftArg, rightArg);		
   5.220  		}
   5.221  		return null;
   5.222  
   5.223 @@ -501,8 +539,8 @@
   5.224  
   5.225  	@Override
   5.226  	public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Group node, BindingSet bindings)
   5.227 -	throws QueryEvaluationException
   5.228 -	{
   5.229 +			throws QueryEvaluationException
   5.230 +			{
   5.231  		//		Set<String> tmp1 = node.getAggregateBindingNames();
   5.232  		//		Set<String> tmp2 = node.getAssuredBindingNames();
   5.233  		//		Set<String> tmp3 = node.getBindingNames();
   5.234 @@ -512,18 +550,18 @@
   5.235  		//			//System.out.println(node.g);
   5.236  		//		}
   5.237  		return new StSPARQLGroupIterator(this, node, bindings);
   5.238 -	}
   5.239 +			}
   5.240  
   5.241  	@Override
   5.242  	public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Order node, BindingSet bindings)
   5.243 -	throws QueryEvaluationException
   5.244 -	{
   5.245 +			throws QueryEvaluationException
   5.246 +			{
   5.247  		StSPARQLValueComparator vcmp = new StSPARQLValueComparator();
   5.248  		StSPARQLOrderComparator cmp = new StSPARQLOrderComparator(this, node, vcmp);
   5.249  		boolean reduced = isReduced(node);
   5.250  		long limit = getLimit(node);
   5.251  		return new OrderIterator(evaluate(node.getArg(), bindings), cmp, limit, reduced);
   5.252 -	}
   5.253 +			}
   5.254  
   5.255  	//Duplicated from EvaluationStrategyImpl
   5.256  	private boolean isReduced(QueryModelNode node) {
   5.257 @@ -606,11 +644,11 @@
   5.258  	//	}
   5.259  
   5.260  	protected abstract CloseableIteration<BindingSet, QueryEvaluationException> evaluate(GeneralDBSelectQuery qb, BindingSet b)
   5.261 -	throws UnsupportedRdbmsOperatorException, RdbmsQueryEvaluationException;
   5.262 +			throws UnsupportedRdbmsOperatorException, RdbmsQueryEvaluationException;
   5.263  
   5.264  	protected String toQueryString(GeneralDBSelectQuery qb, QueryBindingSet bindings, List<Object> parameters)
   5.265 -	throws RdbmsException, UnsupportedRdbmsOperatorException
   5.266 -	{
   5.267 +			throws RdbmsException, UnsupportedRdbmsOperatorException
   5.268 +			{
   5.269  		GeneralDBQueryBuilder query = factory.createQueryBuilder();
   5.270  		if (qb.isDistinct()) {
   5.271  			query.distinct();
   5.272 @@ -642,6 +680,8 @@
   5.273  						if(var.isSpatial())
   5.274  						{
   5.275  							this.geoNames.put(var.getIndex()+2,var.getName());
   5.276 +							//I am carrying SRID too! Therefore, shifting index one more position
   5.277 +							index++;
   5.278  						}
   5.279  						query.select(proj.getId());
   5.280  						query.select(proj.getStringValue());
   5.281 @@ -688,7 +728,7 @@
   5.282  			if(!this.thematicExpressions.contains(expr))
   5.283  			{
   5.284  				query.construct(expr);
   5.285 -
   5.286 +				boolean increaseIndex = false;
   5.287  
   5.288  				GeneralDBSpatialFuncInfo info = null;
   5.289  				switch(constructReturnType(expr))
   5.290 @@ -708,6 +748,7 @@
   5.291  				case 4: 
   5.292  					//WKB
   5.293  					info = new GeneralDBSpatialFuncInfo((String) pairs.getKey(), typeOfField.WKB);
   5.294 +					increaseIndex = true;
   5.295  					break;
   5.296  				case 5: 
   5.297  					//DOUBLE
   5.298 @@ -718,6 +759,12 @@
   5.299  
   5.300  				//constructIndexesAndNames.put((String) pairs.getKey(),index++);
   5.301  				constructIndexesAndNames.put(info,index++);
   5.302 +				if(increaseIndex)
   5.303 +				{
   5.304 +					//Increasing index by one more because of SRID!
   5.305 +					//However, only in the case when the result is some geometry (e.g. not for metrics)
   5.306 +					index++;
   5.307 +				}
   5.308  			}
   5.309  		}
   5.310  		//
   5.311 @@ -740,7 +787,7 @@
   5.312  			logger.debug(parameters.toString());
   5.313  		}
   5.314  		return query.toString();
   5.315 -	}
   5.316 +			}
   5.317  
   5.318  	/**
   5.319  	 * Function used to locate all ColumnVars from the select's spatial constructs so that they can later 
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java	Tue Mar 13 15:01:43 2012 +0200
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java	Wed Mar 14 15:27:35 2012 +0200
     6.3 @@ -17,11 +17,11 @@
     6.4  	/**
     6.5  	 * CONSTRUCTOR
     6.6  	 */
     6.7 -	public GeneralDBPolyhedron(Number id, Integer version, URI datatype, byte[] polyhedron) throws IOException, ClassNotFoundException {
     6.8 +	public GeneralDBPolyhedron(Number id, Integer version, URI datatype, byte[] polyhedron, int srid) throws IOException, ClassNotFoundException {
     6.9  		super(id, version);
    6.10  
    6.11  		try {
    6.12 -			this.polyhedron = new StrabonPolyhedron(polyhedron);
    6.13 +			this.polyhedron = new StrabonPolyhedron(polyhedron, srid);
    6.14  		} catch (ParseException e) {
    6.15  
    6.16  			e.printStackTrace();
     7.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java	Tue Mar 13 15:01:43 2012 +0200
     7.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java	Wed Mar 14 15:27:35 2012 +0200
     7.3 @@ -46,8 +46,8 @@
     7.4  		{
     7.5  			Blob labelBlob = rs.getBlob(index + 1);
     7.6      		byte[] label = labelBlob.getBytes((long)1, (int)labelBlob.length());
     7.7 -
     7.8 -			return vf.getRdbmsPolyhedron(id, StrabonPolyhedron.ogcGeometry, label);
     7.9 +    		int srid = rs.getInt(index + 2);
    7.10 +			return vf.getRdbmsPolyhedron(id, StrabonPolyhedron.ogcGeometry, label, srid);
    7.11  
    7.12  		}
    7.13  
    7.14 @@ -63,7 +63,8 @@
    7.15  		//Case of spatial constructs
    7.16  		Blob labelBlob = rs.getBlob(index + 1); 
    7.17  		byte[] label = labelBlob.getBytes((long)1, (int)labelBlob.length());
    7.18 -		return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label);
    7.19 +		int srid = rs.getInt(index + 2);
    7.20 +		return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label, srid);
    7.21  
    7.22  	}
    7.23  }
    7.24 \ No newline at end of file
     8.1 --- a/pom.xml	Tue Mar 13 15:01:43 2012 +0200
     8.2 +++ b/pom.xml	Wed Mar 14 15:27:35 2012 +0200
     8.3 @@ -1,4 +1,5 @@
     8.4 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     8.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     8.6 +	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     8.7  
     8.8  	<modelVersion>4.0.0</modelVersion>
     8.9  
    8.10 @@ -34,7 +35,7 @@
    8.11  		<aduna.appbase.version>3.5.0</aduna.appbase.version>
    8.12  		<slf4j.version>1.6.1</slf4j.version>
    8.13  		<spring.version>2.5.6</spring.version>
    8.14 -		<geotools.version>2.6.6</geotools.version>
    8.15 +		<geotools.version>2.7.4</geotools.version>
    8.16  	</properties>
    8.17  
    8.18  	<dependencyManagement>
    8.19 @@ -142,13 +143,8 @@
    8.20  				<version>${sesame.version}</version>
    8.21  			</dependency>
    8.22  
    8.23 -			<!--
    8.24 -			<dependency>
    8.25 -				<groupId>info.aduna.commons</groupId>
    8.26 -				<artifactId>aduna-commons-lang</artifactId>
    8.27 -				<version>2.10.0-SNAPSHOT</version>
    8.28 -			</dependency>
    8.29 -			-->
    8.30 +			<!-- <dependency> <groupId>info.aduna.commons</groupId> <artifactId>aduna-commons-lang</artifactId> 
    8.31 +				<version>2.10.0-SNAPSHOT</version> </dependency> -->
    8.32  
    8.33  			<!-- Aduna Commons -->
    8.34  			<!-- Note: other Aduna Commons dependencies are imported from appbase -->
    8.35 @@ -298,18 +294,25 @@
    8.36  				<artifactId>gt-referencing</artifactId>
    8.37  				<version>${geotools.version}</version>
    8.38  			</dependency>
    8.39 -			
    8.40 +
    8.41  			<dependency>
    8.42  				<groupId>org.geotools</groupId>
    8.43  				<artifactId>gt-jts-wrapper</artifactId>
    8.44  				<version>${geotools.version}</version>
    8.45 -		</dependency>
    8.46 -			
    8.47 +			</dependency>
    8.48 +
    8.49 +
    8.50  			<dependency>
    8.51 -				<groupId>org.opengis</groupId>
    8.52 -				<artifactId>geoapi</artifactId>
    8.53 -				<version>2.2.0</version>
    8.54 -  			</dependency>
    8.55 +				<groupId>org.geotools</groupId>
    8.56 +				<artifactId>gt-opengis</artifactId>
    8.57 +				<version>${geotools.version}</version>
    8.58 +			</dependency>
    8.59 +
    8.60 +			<!-- <dependency> -->
    8.61 +			<!-- <groupId>org.opengis</groupId> -->
    8.62 +			<!-- <artifactId>geoapi</artifactId> -->
    8.63 +			<!-- <version>3.0.0</version> -->
    8.64 +			<!-- </dependency> -->
    8.65  
    8.66  			<!-- Testing: JUnit -->
    8.67  			<dependency>
    8.68 @@ -331,7 +334,7 @@
    8.69  				<artifactId>slf4j-simple</artifactId>
    8.70  				<version>${slf4j.version}</version>
    8.71  			</dependency>
    8.72 -			
    8.73 +
    8.74  		</dependencies>
    8.75  	</dependencyManagement>
    8.76  
    8.77 @@ -396,19 +399,19 @@
    8.78  	</scm>
    8.79  
    8.80  	<repositories>
    8.81 -		
    8.82 -       <repository>
    8.83 -               <releases>
    8.84 -                       <enabled>true</enabled>
    8.85 -               </releases>
    8.86 -               <snapshots>
    8.87 -                       <enabled>false</enabled>
    8.88 -               </snapshots>
    8.89 -               <id>strabon.testing</id>
    8.90 -               <name>Strabon - maven repository</name>
    8.91 -               <url>http://maven.strabon.di.uoa.gr/content/repositories/testing</url>
    8.92 -       </repository>
    8.93 -		
    8.94 +
    8.95 +		<repository>
    8.96 +			<releases>
    8.97 +				<enabled>true</enabled>
    8.98 +			</releases>
    8.99 +			<snapshots>
   8.100 +				<enabled>false</enabled>
   8.101 +			</snapshots>
   8.102 +			<id>strabon.testing</id>
   8.103 +			<name>Strabon - maven repository</name>
   8.104 +			<url>http://maven.strabon.di.uoa.gr/content/repositories/testing</url>
   8.105 +		</repository>
   8.106 +
   8.107  		<repository>
   8.108  			<releases>
   8.109  				<enabled>true</enabled>
   8.110 @@ -420,17 +423,17 @@
   8.111  			<name>Strabon - maven repository</name>
   8.112  			<url>http://maven.strabon.di.uoa.gr/content/repositories/releases</url>
   8.113  		</repository>
   8.114 -                <repository>
   8.115 -                        <releases>
   8.116 -                                <enabled>false</enabled>
   8.117 -                        </releases>
   8.118 -                        <snapshots>
   8.119 -                                <enabled>true</enabled>
   8.120 -                        </snapshots>
   8.121 -                        <id>strabon.snapshot</id>
   8.122 -                        <name>Strabon - maven repository - snapshots</name>
   8.123 -                        <url>http://maven.strabon.di.uoa.gr/content/repositories/snapshots</url>
   8.124 -                </repository>
   8.125 +		<repository>
   8.126 +			<releases>
   8.127 +				<enabled>false</enabled>
   8.128 +			</releases>
   8.129 +			<snapshots>
   8.130 +				<enabled>true</enabled>
   8.131 +			</snapshots>
   8.132 +			<id>strabon.snapshot</id>
   8.133 +			<name>Strabon - maven repository - snapshots</name>
   8.134 +			<url>http://maven.strabon.di.uoa.gr/content/repositories/snapshots</url>
   8.135 +		</repository>
   8.136  
   8.137  
   8.138  		<repository>
     9.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Mar 13 15:01:43 2012 +0200
     9.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Wed Mar 14 15:27:35 2012 +0200
     9.3 @@ -228,6 +228,9 @@
     9.4  				//
     9.5  				filter.closeBracket();
     9.6  
     9.7 +				//Adding srid field explicitly for my StrabonPolyhedron constructor later on!
     9.8 +				filter.appendComma();
     9.9 +				filter.column(alias, "srid");
    9.10  			}
    9.11  			else
    9.12  			{
    9.13 @@ -284,12 +287,12 @@
    9.14  			}
    9.15  
    9.16  	//FIXME my addition from here on
    9.17 -	
    9.18 +
    9.19  	//Issue with this function: crashes when MathExpr is present in Select but does not
    9.20  	//involve spatial variables! must escape this somehow
    9.21  	@Override
    9.22  	public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException
    9.23 -			{
    9.24 +	{
    9.25  		if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 
    9.26  				&&!(expr instanceof GeneralDBSqlSpatialMetricUnary)
    9.27  				&&!(expr instanceof GeneralDBSqlMathExpr)
    9.28 @@ -309,8 +312,10 @@
    9.29  		{
    9.30  			dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select);
    9.31  		}
    9.32 +		//SRID support must be explicitly added!
    9.33 +
    9.34  		return this;
    9.35 -			}
    9.36 +	}
    9.37  
    9.38  	//Spatial Relationship Functions
    9.39  	@Override
    9.40 @@ -786,7 +791,7 @@
    9.41  				{
    9.42  					appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
    9.43  				}
    9.44 -	
    9.45 +
    9.46  				filter.closeBracket();
    9.47  			}
    9.48  			else
    9.49 @@ -797,7 +802,7 @@
    9.50  		}
    9.51  
    9.52  		filter.closeBracket();
    9.53 -	}
    9.54 +			}
    9.55  
    9.56  	@Override
    9.57  	protected void append(GeneralDBSqlGeoIsSimple expr, GeneralDBSqlExprBuilder filter)
    9.58 @@ -1016,6 +1021,8 @@
    9.59  	{
    9.60  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
    9.61  		boolean sridNeeded = true;
    9.62 +		//XXX Incorporating SRID
    9.63 +		String sridExpr = null;
    9.64  		
    9.65  		filter.openBracket();
    9.66  
    9.67 @@ -1033,8 +1040,7 @@
    9.68  		}
    9.69  		else
    9.70  		{
    9.71 -			//XXX Incorporating SRID
    9.72 -			String sridExpr = null;
    9.73 +			
    9.74  			GeneralDBSqlExpr tmp = expr;
    9.75  			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
    9.76  			{
    9.77 @@ -1175,8 +1181,14 @@
    9.78  			}
    9.79  			///
    9.80  		}
    9.81 -		//}
    9.82  		filter.closeBracket();
    9.83 +		//Used to explicitly include SRID
    9.84 +		if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
    9.85 +		{
    9.86 +			filter.appendComma();
    9.87 +			filter.append(sridExpr);
    9.88 +		}
    9.89 +		
    9.90  			}
    9.91  
    9.92  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 
    9.93 @@ -1185,6 +1197,8 @@
    9.94  			{
    9.95  		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
    9.96  		boolean sridNeeded = true;
    9.97 +		String sridExpr = null;
    9.98 +
    9.99  		filter.openBracket();
   9.100  
   9.101  		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   9.102 @@ -1207,8 +1221,7 @@
   9.103  		}
   9.104  		else
   9.105  		{
   9.106 -			//XXX Incorporating SRID
   9.107 -			String sridExpr = null;
   9.108 +
   9.109  			GeneralDBSqlExpr tmp = expr;
   9.110  
   9.111  
   9.112 @@ -1294,7 +1307,7 @@
   9.113  			}
   9.114  
   9.115  			filter.closeBracket();
   9.116 -			//SRID Support
   9.117 +//			//SRID Support
   9.118  			if(sridNeeded)
   9.119  			{
   9.120  				if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
   9.121 @@ -1309,7 +1322,13 @@
   9.122  		}
   9.123  
   9.124  		filter.closeBracket();
   9.125 -
   9.126 +		//Used to explicitly include SRID
   9.127 +		if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
   9.128 +		{
   9.129 +			filter.appendComma();
   9.130 +			filter.append(sridExpr);
   9.131 +		}
   9.132 +		
   9.133  			}
   9.134  
   9.135  
    10.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java	Tue Mar 13 15:01:43 2012 +0200
    10.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java	Wed Mar 14 15:27:35 2012 +0200
    10.3 @@ -45,8 +45,8 @@
    10.4  		if (ids.isLiteral(id))
    10.5  		{
    10.6  			byte[] label = rs.getBytes(index + 1);
    10.7 -
    10.8 -			return vf.getRdbmsPolyhedron(id, StrabonPolyhedron.ogcGeometry, label);
    10.9 +			int srid = rs.getInt(index + 2);
   10.10 +			return vf.getRdbmsPolyhedron(id, StrabonPolyhedron.ogcGeometry, label, srid);
   10.11  
   10.12  		}
   10.13  
   10.14 @@ -61,7 +61,8 @@
   10.15  
   10.16  		//Case of spatial constructs
   10.17  		byte[] label = rs.getBytes(index + 1);
   10.18 -		return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label);
   10.19 +		int srid = rs.getInt(index + 2);
   10.20 +		return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label, srid);
   10.21  
   10.22  	}
   10.23  }
   10.24 \ No newline at end of file
    11.1 --- a/runtime/pom.xml	Tue Mar 13 15:01:43 2012 +0200
    11.2 +++ b/runtime/pom.xml	Wed Mar 14 15:27:35 2012 +0200
    11.3 @@ -159,6 +159,11 @@
    11.4  				<groupId>org.geotools</groupId>
    11.5  				<artifactId>gt-shapefile</artifactId>
    11.6  			</dependency>
    11.7 +			
    11.8 +			<dependency>
    11.9 +				<groupId>org.geotools</groupId>
   11.10 +				<artifactId>gt-opengis</artifactId>
   11.11 +			</dependency>
   11.12  
   11.13  		<!-- Aduna Appbase -->
   11.14  			<dependency>
    12.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Mar 13 15:01:43 2012 +0200
    12.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Mar 14 15:27:35 2012 +0200
    12.3 @@ -91,7 +91,8 @@
    12.4  
    12.5  		//Setting up store
    12.6  
    12.7 -
    12.8 +		//Used for the conversions taking place involving JTS + WGS84 (4326)
    12.9 +		System.setProperty("org.geotools.referencing.forceXY", "true");
   12.10  		//our repository
   12.11  		repo1 = new SailRepository(db_store);
   12.12