changeset 876:3d0c06f99686

Switched to using asText(...)-Function of SeShapes-Objects for generating an WKT-String for Polygons. geo-backend/trunk@752 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 09 Mar 2010 11:02:53 +0000 (2010-03-09)
parents f99d8f92a640
children 485566786089
files geo-backend/ChangeLog geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java
diffstat 2 files changed, 36 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/geo-backend/ChangeLog	Mon Mar 08 15:39:58 2010 +0000
+++ b/geo-backend/ChangeLog	Tue Mar 09 11:02:53 2010 +0000
@@ -1,3 +1,17 @@
+2010-03-09  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java (getPosValue): 
+	  Switched to using asText(...)-Function of SeShapes-Objects for generating 
+	  an WKT-String for Polygons. Going this way we are able to produce valid 
+	  WKT for all kinds of Polygons deliverd by the ArcSDE.
+	  We cannot use this Method for Points and LineStrings because the WKT 
+	  which will be produced is invalid e.g. Point Z (...) LineString m (...)
+	  I didn't find Invalid WKTs for Polygons which in Database-Rables we are 
+	  using right now. 
+	  
+	  It has to be monitored if there are Polygons in the  Database which will 
+	  produce invalid WKT-Strings.
+
 2010-03-08  Tim Englich  <tim.englich@intevation.de>
 
 	* src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java (getPosValue): 
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java	Mon Mar 08 15:39:58 2010 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java	Tue Mar 09 11:02:53 2010 +0000
@@ -39,7 +39,6 @@
  * @since 21.11.2007 11:00:54
  */
 public class Row {
-
     /**
      * Default Logging instance
      */
@@ -234,95 +233,49 @@
      * @see #getValue(int)
      */    
     public String getPosValue(int pPos)throws TechnicalException{
-        SeShape val;
-        ArrayList aList;
-        SDEPoint mPoint[];
         StringBuffer returnValue = new StringBuffer();
         synchronized (returnValue) {
             try {
-                val = (SeShape) this.mObjects[pPos];
-                aList = val.getAllPoints(0,false);
-                mPoint = (SDEPoint[])aList.get(0);
+                SeShape val = (SeShape) this.mObjects[pPos];
                 if (val.isPoint()){
+                    // Cannot use val.asText() because the 
+                    // generated WKT is invalid.
+                    ArrayList aList = val.getAllPoints(0,false);
+                    SDEPoint[] mPoint = (SDEPoint[])aList.get(0);
                     returnValue.append("POINT(")
                                .append(mPoint[0].getX())
                                .append(" ")
                                .append(mPoint[0].getY());
-                                if (mPoint[0].is3D()){
-                                   returnValue.append(" ")
-                                   .append(mPoint[0].getZ());
-                               }
-                                returnValue.append(")");
+                    if (mPoint[0].is3D()){
+                       returnValue.append(" ").append(mPoint[0].getZ());
+                    }
+                    returnValue.append(")");
                 }else if (val.isLine() || val.isSimpleLine()){
+                    // Cannot use val.asText() because the 
+                    // generated WKT is invalid.
+                    ArrayList aList = val.getAllPoints(0,false);
+                    SDEPoint[] mPoint = (SDEPoint[])aList.get(0);
                     returnValue.append("LINESTRING(");
                     for (int i = 0; i< mPoint.length;i++){
                         returnValue.append(mPoint[i].getX())
                                    .append(" ")
                                    .append(mPoint[i].getY());
-                                    if (mPoint[i].is3D()){
-                                        returnValue.append(" ")
-                                        .append(mPoint[i].getZ());
-                                    }
+                        if (mPoint[i].is3D()){
+                            returnValue.append(" ").append(mPoint[i].getZ());
+                        }
                         if (i < mPoint.length-1){
                             returnValue.append(" , ");
                         }
                     }
                     returnValue.append(")");
-                } else if (val.isPolygon()){
-                    int[] offsets = (int[])aList.get(1);
-                    int offsetPos = 1;
-                    int length = mPoint.length;
-                    int nextOffset = length;
-                    
-                    if (val.isMultiPart()){
-                        returnValue.append("MULTIPOLYGON(((");
-                        nextOffset = offsets.length-1 >= offsetPos ? offsets[offsetPos++] : length;
-                    }else{
-                        returnValue.append("POLYGON((");
-                    }
-                    
-                    for (int i = 0; i< length ;i++){
-                       SDEPoint p = mPoint[i];
-                       
-                       if (i == nextOffset){
-                           returnValue.append(")),((");
-                           nextOffset = offsets.length-1 >= offsetPos ? offsets[offsetPos++] : length;
-                       }
-                       returnValue.append(p.getX())
-                                   .append(" ")
-                                   .append(p.getY());
-                       if (p.is3D()){
-                           returnValue.append(" ")
-                                      .append(p.getZ());
-                       }
-                       if (i < length-1 && i < nextOffset -1 ){
-                           returnValue.append(" , ");
-                       }
-                    }
-                    returnValue.append(")");
-                    if (val.isMultiPart()){
-                        returnValue.append(")");
-                    }
-                    // TODO How are Rings supported
-//                    for (int i =1 ; i < aList.size(); i++){
-//                        returnValue.append("(");
-//                        mPoint = (SDEPoint[])aList.get(i);
-//                        for (int j = 0; j < mPoint.length;j++){
-//                            returnValue.append(mPoint[j].getX())
-//                                       .append(" ")
-//                                       .append(mPoint[j].getY())
-//                                       .append(" ")
-//                                       .append(mPoint[i].getZ());
-//                            if (i < mPoint.length-1){
-//                                returnValue.append(" , ");
-//                            }
-//                        }
-//                        returnValue.append(")");
-//                    }
-                    returnValue.append(")");
+                } else{
+                    returnValue.append(val.asText(val.getTextSize()));
                 }
             } catch (SeException e) {
-                throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName());   
+                throw new TechnicalException("Could not cast this value to the " +
+                                             "Float Type. Object is of value " +
+                                             "type: " + 
+                                             getValue(pPos).getClass().getName());
             }
         }
         return returnValue.toString();

http://dive4elements.wald.intevation.org