Revision 423 org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.algorithm/src/main/java/es/unex/sextante/vectorTools/InPolygonSpatialJoin/InPolygonSpatialJoinAlgorithm.java

View differences:

InPolygonSpatialJoinAlgorithm.java
13 13
import es.unex.sextante.exceptions.RepeatedParameterNameException;
14 14
import es.unex.sextante.math.simpleStats.SimpleStats;
15 15
import es.unex.sextante.outputs.OutputVectorLayer;
16
import java.util.Objects;
17
import org.gvsig.tools.ToolsLocator;
18
import org.gvsig.tools.dataTypes.Coercion;
19
import org.gvsig.tools.dataTypes.DataTypes;
20
import org.gvsig.tools.logger.FilteredLogger;
16 21

  
17 22

  
23
@SuppressWarnings("UseSpecificCatch")
18 24
public class InPolygonSpatialJoinAlgorithm
19 25
         extends
20 26
            GeoAlgorithm {
......
122 128
         stats[i] = new SimpleStats();
123 129
      }
124 130

  
131
      FilteredLogger logger = new FilteredLogger(LOGGER, "InPolygonSpatialJoinAlgorithm", 10);
132
      Coercion toDouble = ToolsLocator.getDataTypesManager().get(DataTypes.DOUBLE).getCoercion();
125 133
      for (final IFeature element : pts) {
126 134
         if (polygon.contains(element.getGeometry())) {
127 135
            for (int j = 0; j < stats.length; j++) {
128
               final String sValue = element.getRecord().getValue(j).toString();
136
               final Object value = element.getRecord().getValue(j);
129 137
               try {
130
                  final double dValue = Double.parseDouble(sValue);
138
                  final double dValue = (double) toDouble.coerce(value);
131 139
                  stats[j].addValue(dValue);
140
               } catch (final Exception e) {                  
141
                  stats[j].addValue();
142
                  logger.warn("Can't convert to double '"+Objects.toString(value)+"'.", e);
132 143
               }
133
               catch (final Exception e) {
134
                  e.printStackTrace();
135
               }
136 144
            }
137 145
         }
138 146
      }
139

  
140 147
      m_Output.addFeature(polygon, calculateRecord(stats, feature.getRecord().getValues()));
141

  
142 148
   }
143 149

  
144 150

  

Also available in: Unified diff