comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java @ 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
parents f99d8f92a640
children 203f95af5b2c
comparison
equal deleted inserted replaced
661:f99d8f92a640 876:3d0c06f99686
37 * @serial 1.0 37 * @serial 1.0
38 * @see 38 * @see
39 * @since 21.11.2007 11:00:54 39 * @since 21.11.2007 11:00:54
40 */ 40 */
41 public class Row { 41 public class Row {
42
43 /** 42 /**
44 * Default Logging instance 43 * Default Logging instance
45 */ 44 */
46 private static Logger sLogger = Logger.getLogger(Row.class); 45 private static Logger sLogger = Logger.getLogger(Row.class);
47 46
232 * @return a strongly typed Float 231 * @return a strongly typed Float
233 * @throws TechnicalException 232 * @throws TechnicalException
234 * @see #getValue(int) 233 * @see #getValue(int)
235 */ 234 */
236 public String getPosValue(int pPos)throws TechnicalException{ 235 public String getPosValue(int pPos)throws TechnicalException{
237 SeShape val;
238 ArrayList aList;
239 SDEPoint mPoint[];
240 StringBuffer returnValue = new StringBuffer(); 236 StringBuffer returnValue = new StringBuffer();
241 synchronized (returnValue) { 237 synchronized (returnValue) {
242 try { 238 try {
243 val = (SeShape) this.mObjects[pPos]; 239 SeShape val = (SeShape) this.mObjects[pPos];
244 aList = val.getAllPoints(0,false);
245 mPoint = (SDEPoint[])aList.get(0);
246 if (val.isPoint()){ 240 if (val.isPoint()){
241 // Cannot use val.asText() because the
242 // generated WKT is invalid.
243 ArrayList aList = val.getAllPoints(0,false);
244 SDEPoint[] mPoint = (SDEPoint[])aList.get(0);
247 returnValue.append("POINT(") 245 returnValue.append("POINT(")
248 .append(mPoint[0].getX()) 246 .append(mPoint[0].getX())
249 .append(" ") 247 .append(" ")
250 .append(mPoint[0].getY()); 248 .append(mPoint[0].getY());
251 if (mPoint[0].is3D()){ 249 if (mPoint[0].is3D()){
252 returnValue.append(" ") 250 returnValue.append(" ").append(mPoint[0].getZ());
253 .append(mPoint[0].getZ()); 251 }
254 } 252 returnValue.append(")");
255 returnValue.append(")");
256 }else if (val.isLine() || val.isSimpleLine()){ 253 }else if (val.isLine() || val.isSimpleLine()){
254 // Cannot use val.asText() because the
255 // generated WKT is invalid.
256 ArrayList aList = val.getAllPoints(0,false);
257 SDEPoint[] mPoint = (SDEPoint[])aList.get(0);
257 returnValue.append("LINESTRING("); 258 returnValue.append("LINESTRING(");
258 for (int i = 0; i< mPoint.length;i++){ 259 for (int i = 0; i< mPoint.length;i++){
259 returnValue.append(mPoint[i].getX()) 260 returnValue.append(mPoint[i].getX())
260 .append(" ") 261 .append(" ")
261 .append(mPoint[i].getY()); 262 .append(mPoint[i].getY());
262 if (mPoint[i].is3D()){ 263 if (mPoint[i].is3D()){
263 returnValue.append(" ") 264 returnValue.append(" ").append(mPoint[i].getZ());
264 .append(mPoint[i].getZ()); 265 }
265 }
266 if (i < mPoint.length-1){ 266 if (i < mPoint.length-1){
267 returnValue.append(" , "); 267 returnValue.append(" , ");
268 } 268 }
269 } 269 }
270 returnValue.append(")"); 270 returnValue.append(")");
271 } else if (val.isPolygon()){ 271 } else{
272 int[] offsets = (int[])aList.get(1); 272 returnValue.append(val.asText(val.getTextSize()));
273 int offsetPos = 1;
274 int length = mPoint.length;
275 int nextOffset = length;
276
277 if (val.isMultiPart()){
278 returnValue.append("MULTIPOLYGON(((");
279 nextOffset = offsets.length-1 >= offsetPos ? offsets[offsetPos++] : length;
280 }else{
281 returnValue.append("POLYGON((");
282 }
283
284 for (int i = 0; i< length ;i++){
285 SDEPoint p = mPoint[i];
286
287 if (i == nextOffset){
288 returnValue.append(")),((");
289 nextOffset = offsets.length-1 >= offsetPos ? offsets[offsetPos++] : length;
290 }
291 returnValue.append(p.getX())
292 .append(" ")
293 .append(p.getY());
294 if (p.is3D()){
295 returnValue.append(" ")
296 .append(p.getZ());
297 }
298 if (i < length-1 && i < nextOffset -1 ){
299 returnValue.append(" , ");
300 }
301 }
302 returnValue.append(")");
303 if (val.isMultiPart()){
304 returnValue.append(")");
305 }
306 // TODO How are Rings supported
307 // for (int i =1 ; i < aList.size(); i++){
308 // returnValue.append("(");
309 // mPoint = (SDEPoint[])aList.get(i);
310 // for (int j = 0; j < mPoint.length;j++){
311 // returnValue.append(mPoint[j].getX())
312 // .append(" ")
313 // .append(mPoint[j].getY())
314 // .append(" ")
315 // .append(mPoint[i].getZ());
316 // if (i < mPoint.length-1){
317 // returnValue.append(" , ");
318 // }
319 // }
320 // returnValue.append(")");
321 // }
322 returnValue.append(")");
323 } 273 }
324 } catch (SeException e) { 274 } catch (SeException e) {
325 throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName()); 275 throw new TechnicalException("Could not cast this value to the " +
276 "Float Type. Object is of value " +
277 "type: " +
278 getValue(pPos).getClass().getName());
326 } 279 }
327 } 280 }
328 return returnValue.toString(); 281 return returnValue.toString();
329 } 282 }
330 } 283 }

http://dive4elements.wald.intevation.org