Multipolygons are not supported in gt-jdbc-oracle when not using prepared
statements
------------------------------------------------------------------------------------
Key: GEOT-2771
URL: http://jira.codehaus.org/browse/GEOT-2771
Project: GeoTools
Issue Type: Bug
Components: data jdbc-ng
Affects Versions: 2.6-RC1
Environment: Mac OSX, Java 1.6
Reporter: Ariel Núñez
in src/main/java/org/geotools/data/oracle/sdo/SDOSqlDumper.java:
{code}
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)");
}
{code}
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
{code}
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.
{code}
[1] http://jira.codehaus.org/secure/attachment/16923/SQLEncoderOracle.java
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel