Strabon
changeset 47:59d921de8db6
Added support for CRS in cases evaluated in Java. SRID is now fetched along with each geometry and stored in StrabonPolyhedron
line diff
1.1 --- a/evaluation/pom.xml Tue Mar 13 18:39:36 2012 +0200 1.2 +++ b/evaluation/pom.xml Wed Mar 14 15:07:27 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 18:39:36 2012 +0200 2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Wed Mar 14 15:07:27 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 18:39:36 2012 +0200 3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java Wed Mar 14 15:07:27 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 18:39:36 2012 +0200 4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java Wed Mar 14 15:07:27 2012 +0200 4.3 @@ -369,11 +369,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 18:39:36 2012 +0200 5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Wed Mar 14 15:07:27 2012 +0200 5.3 @@ -373,56 +373,95 @@ 5.4 5.5 if(function instanceof AboveFunc) 5.6 { 5.7 - funcResult = leftGeom.getEnvelopeInternal().getMinY() > rightGeom.getEnvelopeInternal().getMaxY(); 5.8 + int targetSRID = leftGeom.getSRID(); 5.9 + int sourceSRID = rightGeom.getSRID(); 5.10 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.11 + funcResult = leftGeom.getEnvelopeInternal().getMinY() > rightConverted.getEnvelopeInternal().getMaxY(); 5.12 } 5.13 else if(function instanceof AnyInteractFunc) 5.14 { 5.15 - funcResult = leftGeom.intersects(rightGeom); 5.16 + int targetSRID = leftGeom.getSRID(); 5.17 + int sourceSRID = rightGeom.getSRID(); 5.18 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.19 + funcResult = leftGeom.intersects(rightConverted); 5.20 } 5.21 else if(function instanceof BelowFunc) 5.22 { 5.23 - funcResult = leftGeom.getEnvelopeInternal().getMaxY() < rightGeom.getEnvelopeInternal().getMinY(); 5.24 + int targetSRID = leftGeom.getSRID(); 5.25 + int sourceSRID = rightGeom.getSRID(); 5.26 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.27 + funcResult = leftGeom.getEnvelopeInternal().getMaxY() < rightConverted.getEnvelopeInternal().getMinY(); 5.28 } 5.29 else if(function instanceof ContainsFunc) 5.30 { 5.31 - funcResult = leftGeom.contains(rightGeom); 5.32 + int targetSRID = leftGeom.getSRID(); 5.33 + int sourceSRID = rightGeom.getSRID(); 5.34 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.35 + funcResult = leftGeom.contains(rightConverted); 5.36 } 5.37 else if(function instanceof CoveredByFunc) 5.38 { 5.39 - funcResult = leftGeom.coveredBy(rightGeom); 5.40 + int targetSRID = leftGeom.getSRID(); 5.41 + int sourceSRID = rightGeom.getSRID(); 5.42 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.43 + funcResult = leftGeom.coveredBy(rightConverted); 5.44 } 5.45 else if(function instanceof CoversFunc) 5.46 { 5.47 - funcResult = leftGeom.covers(rightGeom); 5.48 + int targetSRID = leftGeom.getSRID(); 5.49 + int sourceSRID = rightGeom.getSRID(); 5.50 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.51 + funcResult = leftGeom.covers(rightConverted); 5.52 } 5.53 else if(function instanceof DisjointFunc) 5.54 { 5.55 - funcResult = leftGeom.disjoint(rightGeom); 5.56 + int targetSRID = leftGeom.getSRID(); 5.57 + int sourceSRID = rightGeom.getSRID(); 5.58 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.59 + funcResult = leftGeom.disjoint(rightConverted); 5.60 } 5.61 else if(function instanceof EqualsFunc) 5.62 { 5.63 - funcResult = leftGeom.equals(rightGeom); 5.64 + int targetSRID = leftGeom.getSRID(); 5.65 + int sourceSRID = rightGeom.getSRID(); 5.66 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.67 + funcResult = leftGeom.equals(rightConverted); 5.68 } 5.69 else if(function instanceof InsideFunc) 5.70 { 5.71 - funcResult = leftGeom.within(rightGeom); 5.72 + int targetSRID = leftGeom.getSRID(); 5.73 + int sourceSRID = rightGeom.getSRID(); 5.74 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.75 + funcResult = leftGeom.within(rightConverted); 5.76 } 5.77 else if(function instanceof LeftFunc) 5.78 { 5.79 - funcResult = leftGeom.getEnvelopeInternal().getMaxX() < rightGeom.getEnvelopeInternal().getMinX(); 5.80 + int targetSRID = leftGeom.getSRID(); 5.81 + int sourceSRID = rightGeom.getSRID(); 5.82 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.83 + funcResult = leftGeom.getEnvelopeInternal().getMaxX() < rightConverted.getEnvelopeInternal().getMinX(); 5.84 } 5.85 else if(function instanceof OverlapFunc) 5.86 { 5.87 - funcResult = leftGeom.overlaps(rightGeom); 5.88 + int targetSRID = leftGeom.getSRID(); 5.89 + int sourceSRID = rightGeom.getSRID(); 5.90 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.91 + //System.out.println(rightConverted.toString()); 5.92 + funcResult = leftGeom.overlaps(rightConverted); 5.93 } 5.94 else if(function instanceof RightFunc) 5.95 { 5.96 - funcResult = leftGeom.getEnvelopeInternal().getMinX() > rightGeom.getEnvelopeInternal().getMaxX(); 5.97 - 5.98 + int targetSRID = leftGeom.getSRID(); 5.99 + int sourceSRID = rightGeom.getSRID(); 5.100 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.101 + funcResult = leftGeom.getEnvelopeInternal().getMinX() > rightConverted.getEnvelopeInternal().getMaxX(); 5.102 } 5.103 else if(function instanceof TouchFunc) 5.104 { 5.105 - funcResult = leftGeom.touches(rightGeom); 5.106 + int targetSRID = leftGeom.getSRID(); 5.107 + int sourceSRID = rightGeom.getSRID(); 5.108 + Geometry rightConverted = StrabonPolyhedron.convertSRID(rightGeom, sourceSRID, targetSRID); 5.109 + funcResult = leftGeom.touches(rightConverted); 5.110 } 5.111 5.112 return funcResult ? BooleanLiteralImpl.TRUE : BooleanLiteralImpl.FALSE; 5.113 @@ -451,49 +490,48 @@ 5.114 if(function.getURI().equals(StrabonPolyhedron.union)) 5.115 { 5.116 StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron(); 5.117 - 5.118 - return new StrabonPolyhedron(leftArg.getGeometry().union(rightArg.getGeometry())); 5.119 + return StrabonPolyhedron.union(leftArg, rightArg); 5.120 } 5.121 else if(function.getURI().equals(StrabonPolyhedron.buffer)) 5.122 { 5.123 if(right instanceof LiteralImpl) 5.124 { 5.125 LiteralImpl radius = (LiteralImpl) right; 5.126 - return new StrabonPolyhedron(leftArg.getGeometry().buffer(radius.doubleValue())); 5.127 + return StrabonPolyhedron.buffer(leftArg,radius.doubleValue()); 5.128 } 5.129 else if(right instanceof RdbmsLiteral) 5.130 { 5.131 RdbmsLiteral radius = (RdbmsLiteral) right; 5.132 - return new StrabonPolyhedron(leftArg.getGeometry().buffer(radius.doubleValue())); 5.133 + return StrabonPolyhedron.buffer(leftArg,radius.doubleValue()); 5.134 } 5.135 5.136 } 5.137 else if(function.getURI().equals(StrabonPolyhedron.envelope)) 5.138 { 5.139 - return new StrabonPolyhedron(leftArg.getGeometry().getEnvelope()); 5.140 + return StrabonPolyhedron.envelope(leftArg); 5.141 } 5.142 else if(function.getURI().equals(StrabonPolyhedron.convexHull)) 5.143 { 5.144 - return new StrabonPolyhedron(leftArg.getGeometry().convexHull()); 5.145 + return StrabonPolyhedron.convexHull(leftArg); 5.146 } 5.147 else if(function.getURI().equals(StrabonPolyhedron.boundary)) 5.148 { 5.149 - return new StrabonPolyhedron(leftArg.getGeometry().getBoundary()); 5.150 + return StrabonPolyhedron.boundary(leftArg); 5.151 } 5.152 else if(function.getURI().equals(StrabonPolyhedron.intersection)) 5.153 { 5.154 StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron(); 5.155 - return new StrabonPolyhedron(leftArg.getGeometry().intersection(rightArg.getGeometry())); 5.156 + return StrabonPolyhedron.intersection(leftArg, rightArg); 5.157 } 5.158 else if(function.getURI().equals(StrabonPolyhedron.difference)) 5.159 { 5.160 StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron(); 5.161 - return new StrabonPolyhedron(leftArg.getGeometry().difference(rightArg.getGeometry())); 5.162 + return StrabonPolyhedron.difference(leftArg, rightArg); 5.163 } 5.164 else if(function.getURI().equals(StrabonPolyhedron.symDifference)) 5.165 { 5.166 StrabonPolyhedron rightArg = ((GeneralDBPolyhedron) right).getPolyhedron(); 5.167 - return new StrabonPolyhedron(leftArg.getGeometry().symDifference(rightArg.getGeometry())); 5.168 + return StrabonPolyhedron.symDifference(leftArg, rightArg); 5.169 } 5.170 return null; 5.171
6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java Tue Mar 13 18:39:36 2012 +0200 6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java Wed Mar 14 15:07:27 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 18:39:36 2012 +0200 7.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java Wed Mar 14 15:07:27 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/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java Tue Mar 13 18:39:36 2012 +0200 8.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java Wed Mar 14 15:07:27 2012 +0200 8.3 @@ -45,8 +45,8 @@ 8.4 if (ids.isLiteral(id)) 8.5 { 8.6 byte[] label = rs.getBytes(index + 1); 8.7 - 8.8 - return vf.getRdbmsPolyhedron(id, StrabonPolyhedron.ogcGeometry, label); 8.9 + int srid = rs.getInt(index + 2); 8.10 + return vf.getRdbmsPolyhedron(id, StrabonPolyhedron.ogcGeometry, label, srid); 8.11 8.12 } 8.13 8.14 @@ -61,7 +61,8 @@ 8.15 8.16 //Case of spatial constructs 8.17 byte[] label = rs.getBytes(index + 1); 8.18 - return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label); 8.19 + int srid = rs.getInt(index + 2); 8.20 + return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label, srid); 8.21 8.22 } 8.23 } 8.24 \ No newline at end of file
9.1 --- a/runtime/pom.xml Tue Mar 13 18:39:36 2012 +0200 9.2 +++ b/runtime/pom.xml Wed Mar 14 15:07:27 2012 +0200 9.3 @@ -159,6 +159,11 @@ 9.4 <groupId>org.geotools</groupId> 9.5 <artifactId>gt-shapefile</artifactId> 9.6 </dependency> 9.7 + 9.8 + <dependency> 9.9 + <groupId>org.geotools</groupId> 9.10 + <artifactId>gt-opengis</artifactId> 9.11 + </dependency> 9.12 9.13 <!-- Aduna Appbase --> 9.14 <dependency>
10.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Tue Mar 13 18:39:36 2012 +0200 10.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Wed Mar 14 15:07:27 2012 +0200 10.3 @@ -91,7 +91,8 @@ 10.4 10.5 //Setting up store 10.6 10.7 - 10.8 + //Used for the conversions taking place involving JTS + WGS84 (4326) 10.9 + System.setProperty("org.geotools.referencing.forceXY", "true"); 10.10 //our repository 10.11 repo1 = new SailRepository(db_store); 10.12