root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / nearestNeighbour / NNInterpolationAlgorithm.java @ 59
History | View | Annotate | Download (3.14 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.nearestNeighbour; |
4 |
|
5 |
import java.awt.geom.Point2D; |
6 |
|
7 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
8 |
import es.unex.sextante.closestpts.Point3D; |
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.OptionalParentParameterException; |
15 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
16 |
import es.unex.sextante.exceptions.UndefinedParentParameterNameException; |
17 |
import es.unex.sextante.rTree.SextanteRTree; |
18 |
import es.unex.sextante.rasterWrappers.GridCell; |
19 |
|
20 |
|
21 |
public class NNInterpolationAlgorithm |
22 |
extends
|
23 |
GeoAlgorithm { |
24 |
|
25 |
public static final String LAYER = "LAYER"; |
26 |
public static final String FIELD = "FIELD"; |
27 |
public static final String RESULT = "RESULT"; |
28 |
|
29 |
protected int m_iField; |
30 |
|
31 |
protected IVectorLayer m_Layer;
|
32 |
|
33 |
private SextanteRTree m_SearchEngine;
|
34 |
|
35 |
|
36 |
@Override
|
37 |
public void defineCharacteristics() { |
38 |
|
39 |
setUserCanDefineAnalysisExtent(true);
|
40 |
setGroup(Sextante.getText("Rasterization_and_interpolation"));
|
41 |
setName(Sextante.getText("Nearest_neighbour"));
|
42 |
|
43 |
try {
|
44 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Point_layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_POINT,
|
45 |
true);
|
46 |
m_Parameters.addTableField(FIELD, Sextante.getText("Field"), LAYER);
|
47 |
addOutputRasterLayer(RESULT, Sextante.getText("Result"));
|
48 |
} |
49 |
catch (final UndefinedParentParameterNameException e) { |
50 |
Sextante.addErrorToLog(e); |
51 |
} |
52 |
catch (final OptionalParentParameterException e) { |
53 |
Sextante.addErrorToLog(e); |
54 |
} |
55 |
catch (final RepeatedParameterNameException e) { |
56 |
Sextante.addErrorToLog(e); |
57 |
} |
58 |
|
59 |
} |
60 |
|
61 |
|
62 |
@Override
|
63 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
64 |
|
65 |
int x, y;
|
66 |
int iNX, iNY;
|
67 |
|
68 |
m_Layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
69 |
m_iField = m_Parameters.getParameterValueAsInt(FIELD); |
70 |
|
71 |
m_SearchEngine = new SextanteRTree(m_Layer, m_iField, m_Task);
|
72 |
final IRasterLayer result = getNewRasterLayer(RESULT, m_Layer.getName() + Sextante.getText("[interpolated]"), |
73 |
IRasterLayer.RASTER_DATA_TYPE_DOUBLE); |
74 |
|
75 |
iNX = m_AnalysisExtent.getNX(); |
76 |
iNY = m_AnalysisExtent.getNY(); |
77 |
|
78 |
setProgressText(Sextante.getText("Interpolating"));
|
79 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
80 |
for (x = 0; x < iNX; x++) { |
81 |
result.setCellValue(x, y, getValueAt(x, y)); |
82 |
} |
83 |
} |
84 |
|
85 |
return !m_Task.isCanceled();
|
86 |
|
87 |
} |
88 |
|
89 |
|
90 |
protected double getValueAt(final int x, |
91 |
final int y) { |
92 |
|
93 |
final Point2D pt = m_AnalysisExtent.getWorldCoordsFromGridCoords(new GridCell(x, y, 0)); |
94 |
final Point3D closestPt = m_SearchEngine.getClosestPoint(pt.getX(), pt.getY());
|
95 |
return closestPt.getZ();
|
96 |
|
97 |
} |
98 |
|
99 |
} |