Mercurial > dive4elements > gnv-client
view geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java @ 879:9bcc423d8d76
Added Support for SpatialQueries using LineString as Geometry of Interest.
geo-backend/trunk@790 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 16 Mar 2010 14:07:18 +0000 |
parents | 203f95af5b2c |
children | 12f88239fb33 |
line wrap: on
line source
/** * Title: Row, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/Row.java,v 1.4 2008/01/30 12:38:34 blume Exp $ * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/Row.java,v $ * created by: Stefan Blume (blume) * erstellt am: 21.11.2007 * Copyright: con terra GmbH, 2005 * * modified by: $Author: blume $ * modified on: $Date: 2008/01/30 12:38:34 $ * Version: $Revision: 1.4 $ * TAG: $Name: $ * locked from: $Locker: $ * CVS State: $State: Exp $ * Project: $ProjectName$ */ package de.intevation.gnv.geobackend.sde.datasources; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import org.apache.log4j.Logger; import com.esri.sde.sdk.client.SDEPoint; import com.esri.sde.sdk.client.SeException; import com.esri.sde.sdk.client.SeShape; import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException; import de.intevation.gnv.geobackend.util.DateUtils; /** * A Row represents a set of values. * In a technical manner (e.g. database manner) a row contains all attributes of a single "hit". * * @author blume * @version 1.0 * @serial 1.0 * @see * @since 21.11.2007 11:00:54 */ public class Row { /** * Default Logging instance */ private static Logger sLogger = Logger.getLogger(Row.class); /** * Data container. */ private Object[] mObjects; /** * Constructor. * * @param pRowSize the number of attributes contained by this row. */ public Row(int pRowSize) { mObjects = new Object[pRowSize]; } /** * Constructor. * * @param ArrayStr a line from CSV-File. */ public Row (String[] ArrayStr){ this (ArrayStr.length); int nLength = ArrayStr.length; for (int i=0; i < nLength; i++){ addObject(ArrayStr[i], i); } } /** * Adds an attribute value to a specific position of this row. * * @param pObject the object to be stored. * @param pPos the postion the value to be saved */ public void addObject(Object pObject, int pPos) { mObjects[pPos] = pObject; } /** * Returns a Value out of the Row. * * @param pPos the position of the value to be returned. * @return an Object! (not strongly typed) * @throws TechnicalException */ public Object getValue(int pPos) throws TechnicalException { if (pPos < mObjects.length) { Object o = mObjects[pPos]; if (o instanceof SeShape){ return this.getPosValue(pPos); }else{ return o; } } else { throw new TechnicalException("Cannot access this field position. Size is: " + mObjects.length); } } /** * This is a covenient method for getting strongly typed objects out of the row. * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). * In fact, this method executes a simple cast to the desired type. * * @param pPos the position of the object to be resolved. * @return a strongly typed Date * @throws TechnicalException * @see #getValue(int) */ public Date getDateValue(int pPos) throws TechnicalException { Date date = null; try { Calendar lCalendar = (Calendar) getValue(pPos); date = lCalendar.getTime(); } catch (ClassCastException e) { try{ //SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); date = DateUtils.getDateFromString ((String)getValue(pPos)); //(Date)formatter.parse((String)getValue(pPos)); } catch (Exception ex){ sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex); throw new TechnicalException("Could not cast this value to the Date Type. Object is of value type: " + getValue(pPos).getClass().getName()); } } return date; } /** * This is a covenient method for getting strongly typed objects out of the row. * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). * In fact, this method executes a simple cast to the desired type. * * @param pPos the position of the object to be resolved. * @return a strongly typed String * @throws TechnicalException * @see #getValue(int) */ public String getStringValue(int pPos) throws TechnicalException { try { Object o = this.getValue(pPos); String returnValue = null; if (o instanceof SeShape){ returnValue = this.getPosValue(pPos); }else{ returnValue = (String)o; } return returnValue; } catch (ClassCastException e) { throw new TechnicalException("Could not cast this value to the String Type. Object is of value type: " + getValue(pPos).getClass().getName()); } } /** * This is a covenient method for getting strongly typed objects out of the row. * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). * In fact, this method executes a simple cast to the desired type. * * @param pPos the position of the object to be resolved. * @throws TechnicalException * @see #getValue(int) * * @return a strongly typed int */ public int getIntValue(int pPos) throws TechnicalException { try { return (Integer) getValue(pPos); } catch (ClassCastException e) { throw new TechnicalException("Could not cast this value to the Integer Type. Object is of value type: " + getValue(pPos).getClass().getName()); } } /** * This is a covenient method for getting strongly typed objects out of the row. * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). * In fact, this method executes a simple cast to the desired type. * * @param pPos the position of the object to be resolved. * @throws TechnicalException * @see #getValue(int) * * @return a strongly typed Double */ public Double getDoubleValue(int pPos) throws TechnicalException { try { return (Double) getValue(pPos); } catch (ClassCastException e) { try{ return new Double ((String)getValue(pPos)); } catch(Exception ex){ sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex); throw new TechnicalException("Could not cast this value to the Double Type. Object is of value type: " + getValue(pPos).getClass().getName()); } } } /** * This is a covenient method for getting strongly typed objects out of the row. * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). * In fact, this method executes a simple cast to the desired type. * * @param pPos the position of the object to be resolved. * @return a strongly typed Float * @throws TechnicalException * @see #getValue(int) */ public Float getFloatValue(int pPos) throws TechnicalException { try { return (Float) getValue(pPos); } catch (ClassCastException e) { throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName()); } } /** * This is a covenient method for getting strongly typed objects out of the row. * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}). * In fact, this method executes a simple cast to the desired type. * * @param pPos the position of the object to be resolved. * @return a strongly typed Float * @throws TechnicalException * @see #getValue(int) */ public String getPosValue(int pPos)throws TechnicalException{ StringBuffer returnValue = new StringBuffer(); synchronized (returnValue) { try { 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(")"); }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); boolean isMultiLineString = val.isMultiPart(); int length = mPoint.length; int nextOffset = length; int[] offsets = (int[])aList.get(1); int offsetPos = 1; if(isMultiLineString){ returnValue.append("MULTILINESTRING(("); nextOffset = offsets.length-1 >= offsetPos ? offsets[offsetPos++] : length; }else{ returnValue.append("LINESTRING("); } for (int i = 0; i< length;i++){ if (i == nextOffset){ returnValue.append("),("); nextOffset = offsets.length-1 >= offsetPos ? offsets[offsetPos++] : length; } returnValue.append(mPoint[i].getX()) .append(" ") .append(mPoint[i].getY()); if (mPoint[i].is3D()){ returnValue.append(" ").append(mPoint[i].getZ()); } if (i < length-1 && i < nextOffset -1){ returnValue.append(" , "); } } if(isMultiLineString){ returnValue.append("))"); }else{ 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()); } } return returnValue.toString(); } }