Details
Description
in src/main/java/org/geotools/data/oracle/sdo/SDOSqlDumper.java:
private static String toSDOGeom(MultiPolygon multiPolygon, int srid) { if( multiPolygon.getNumGeometries() == 1 ){ return toSDOGeom(multiPolygon.getGeometryN(0), srid); } throw new UnsupportedOperationException("Cannot encode MultiPolygon (yet)"); }
To overcome this limitation I used the code here [1] as a guide to implement MultiPolygon support.
~/work/geoserver/src/geotools/modules/plugin/jdbc/jdbc-oracle: svn diff
Index: src/main/java/org/geotools/data/oracle/sdo/SDOSqlDumper.java
===================================================================
--- src/main/java/org/geotools/data/oracle/sdo/SDOSqlDumper.java (revision 33780)
+++ src/main/java/org/geotools/data/oracle/sdo/SDOSqlDumper.java (working copy)
@@ -92,12 +92,43 @@
* @param line
* @param srid
*/
- private static String toSDOGeom(MultiPolygon polygon, int srid) {
- if( polygon.getNumGeometries() == 1 ){
- return toSDOGeom( polygon.getGeometryN(0), srid);
+ private static String toSDOGeom(MultiPolygon multiPolygon, int srid) {
+ if( multiPolygon.getNumGeometries() == 1 ){
+ return toSDOGeom( multiPolygon.getGeometryN(0), srid);
}
- throw new UnsupportedOperationException("Cannot encode MultiPolygon (yet)");
- }
+
+ String SDOAppendStmnt = "MDSYS.SDO_UTIL.APPEND(";
+ StringBuffer buffer = new StringBuffer(SDOAppendStmnt);
+ int i = 1;
+ int polygons = multiPolygon.getNumGeometries();
+
+ while (i <= polygons) {
+ Polygon polygon = (Polygon) multiPolygon.getGeometryN(i - 1);
+ String SDOPolygonGeomStmnt = toSDOGeom(polygon, srid);
+
+ if (i == polygons) {
+ // This is the last polygon, iterating through a collection of polygons.
+ buffer.append(SDOPolygonGeomStmnt);
+
+ for (int j = 0; j < (polygons - 1); j++) {
+ buffer.append(")");
+ }
+ } else if ((polygons - i) >= 2) {
+ // At least 2 polygons remain in the iteration a collection of polygons
+ buffer.append(SDOPolygonGeomStmnt);
+ buffer.append(",");
+ buffer.append(SDOAppendStmnt);
+ } else {
+ // 2 polygons left in the iteration of multipolygon collection.
+ buffer.append(SDOPolygonGeomStmnt);
+ buffer.append(",");
+ }
+
+ i++;
+ }
+
+ return buffer.toString();
+ }
/**
* Converts a LineString Geometry in an SDO SQL geometry construction
* statement.
[1] http://jira.codehaus.org/secure/attachment/16923/SQLEncoderOracle.java
However, in the Oracle driver the code path that does not use prepared statements is simply not available, only H2 and PostGIS datastore have both as far as I know.
How did you notice this problem?