root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorize / rasterToPoints / RasterToPointsAlgorithm.java @ 59
History | View | Annotate | Download (2.7 KB)
1 |
package es.unex.sextante.vectorize.rasterToPoints; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
|
5 |
import com.vividsolutions.jts.geom.Coordinate; |
6 |
import com.vividsolutions.jts.geom.Geometry; |
7 |
import com.vividsolutions.jts.geom.GeometryFactory; |
8 |
|
9 |
import es.unex.sextante.core.GeoAlgorithm; |
10 |
import es.unex.sextante.core.Sextante; |
11 |
import es.unex.sextante.dataObjects.IRasterLayer; |
12 |
import es.unex.sextante.dataObjects.IVectorLayer; |
13 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
14 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
15 |
import es.unex.sextante.outputs.OutputVectorLayer; |
16 |
|
17 |
public class RasterToPointsAlgorithm |
18 |
extends
|
19 |
GeoAlgorithm { |
20 |
|
21 |
public static final String RESULT = "RESULT"; |
22 |
public static final String LAYER = "LAYER"; |
23 |
|
24 |
private IRasterLayer m_Window;
|
25 |
private IVectorLayer m_Points;
|
26 |
private int m_iNX, m_iNY; |
27 |
|
28 |
|
29 |
@Override
|
30 |
public void defineCharacteristics() { |
31 |
|
32 |
setName(Sextante.getText("Raster_layer_to_points_layer"));
|
33 |
setGroup(Sextante.getText("Vectorization"));
|
34 |
setUserCanDefineAnalysisExtent(true);
|
35 |
|
36 |
try {
|
37 |
m_Parameters.addInputRasterLayer(LAYER, Sextante.getText("Input_layer"), true); |
38 |
addOutputVectorLayer(RESULT, Sextante.getText("Result"), OutputVectorLayer.SHAPE_TYPE_POINT);
|
39 |
} |
40 |
catch (final RepeatedParameterNameException e) { |
41 |
Sextante.addErrorToLog(e); |
42 |
} |
43 |
|
44 |
} |
45 |
|
46 |
|
47 |
@Override
|
48 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
49 |
|
50 |
int x, y;
|
51 |
double dValue;
|
52 |
Point2D pt;
|
53 |
Geometry point; |
54 |
final Object[] value = new Object[1]; |
55 |
|
56 |
m_Window = m_Parameters.getParameterValueAsRasterLayer(LAYER); |
57 |
|
58 |
final String sFields[] = new String[] { m_Window.getName() }; |
59 |
final Class types[] = { Double.class }; |
60 |
|
61 |
m_Window.setWindowExtent(m_AnalysisExtent); |
62 |
m_Points = getNewVectorLayer(RESULT, Sextante.getText("Points"), IVectorLayer.SHAPE_TYPE_POINT, types, sFields);
|
63 |
|
64 |
|
65 |
m_iNX = m_Window.getNX(); |
66 |
m_iNY = m_Window.getNY(); |
67 |
|
68 |
final GeometryFactory gf = new GeometryFactory(); |
69 |
for (y = 0; (y < m_iNY) && setProgress(y, m_iNY); y++) { |
70 |
for (x = 0; x < m_iNX; x++) { |
71 |
dValue = m_Window.getCellValueAsDouble(x, y); |
72 |
if (!m_Window.isNoDataValue(dValue)) {
|
73 |
pt = m_Window.getWindowGridExtent().getWorldCoordsFromGridCoords(x, y); |
74 |
point = gf.createPoint(new Coordinate(pt.getX(), pt.getY()));
|
75 |
value[0] = new Double(dValue); |
76 |
m_Points.addFeature(point, value); |
77 |
} |
78 |
} |
79 |
} |
80 |
|
81 |
return !m_Task.isCanceled();
|
82 |
|
83 |
} |
84 |
|
85 |
|
86 |
} |