Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / pointCoordinates / pointCoordinatesAlgorithm.java @ 59

History | View | Annotate | Download (3.23 KB)

1

    
2

    
3
package es.unex.sextante.vectorTools.pointCoordinates;
4

    
5
import com.vividsolutions.jts.geom.Coordinate;
6
import com.vividsolutions.jts.geom.Geometry;
7

    
8
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer;
9
import es.unex.sextante.core.GeoAlgorithm;
10
import es.unex.sextante.core.Sextante;
11
import es.unex.sextante.dataObjects.IFeature;
12
import es.unex.sextante.dataObjects.IFeatureIterator;
13
import es.unex.sextante.dataObjects.IVectorLayer;
14
import es.unex.sextante.dataObjects.vectorFilters.BoundingBoxFilter;
15
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
16
import es.unex.sextante.exceptions.RepeatedParameterNameException;
17
import es.unex.sextante.outputs.IOutputChannel;
18
import es.unex.sextante.outputs.OutputVectorLayer;
19
import es.unex.sextante.shapesTools.ShapesTools;
20

    
21

    
22
public class pointCoordinatesAlgorithm
23
         extends
24
            GeoAlgorithm {
25

    
26
   public static final String LAYER       = "LAYER";
27
   public static final String GRIDS       = "GRIDS";
28
   public static final String INTERPOLATE = "INTERPOLATE";
29
   public static final String RESULT      = "RESULT";
30

    
31
   private IVectorLayer       m_Layer;
32

    
33

    
34
   @Override
35
   public void defineCharacteristics() {
36

    
37
      setName(Sextante.getText("Add_coordinates_to_points"));
38
      setGroup(Sextante.getText("Tools_for_point_layers"));
39
      setUserCanDefineAnalysisExtent(true);
40

    
41
      try {
42
         m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Points_layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_POINT,
43
                  true);
44
         addOutputVectorLayer(RESULT, Sextante.getText("Points"), OutputVectorLayer.SHAPE_TYPE_POINT, LAYER);
45
      }
46
      catch (final RepeatedParameterNameException e) {
47
         Sextante.addErrorToLog(e);
48
      }
49

    
50
   }
51

    
52

    
53
   @Override
54
   public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
55

    
56
      int iProgress = 0;
57
      int iShapeCount;
58
      Double[][] values;
59

    
60
      m_Layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
61

    
62
      if (!m_bIsAutoExtent) {
63
         m_Layer.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
64
      }
65

    
66
      iShapeCount = m_Layer.getShapesCount();
67
      values = new Double[2][iShapeCount];
68
      final IFeatureIterator iter = m_Layer.iterator();
69

    
70
      while (iter.hasNext() && setProgress(iProgress, iShapeCount)) {
71
         final IFeature feature = iter.next();
72
         final Geometry geom = feature.getGeometry();
73
         final Coordinate[] coords = geom.getCoordinates();
74
         values[0][iProgress] = new Double(coords[0].x);
75
         values[1][iProgress] = new Double(coords[0].y);
76
         iProgress++;
77
      }
78

    
79
      if (m_Task.isCanceled()) {
80
         return false;
81
      }
82

    
83
      final String[] sNames = { "X", "Y" };
84
      final Class[] types = { Double.class, Double.class };
85

    
86
      final IOutputChannel channel = getOutputChannel(RESULT);
87
      final OutputVectorLayer out = new OutputVectorLayer();
88
      out.setName(RESULT);
89
      out.setOutputChannel(channel);
90
      out.setDescription(m_Layer.getName());
91
      out.setOutputObject(ShapesTools.addFields(m_OutputFactory, m_Layer, channel, sNames, values, types));
92
      addOutputObject(out);
93

    
94
      return !m_Task.isCanceled();
95

    
96
   }
97

    
98
}