gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.extension / src / main / java / org / gvsig / geoprocess / core / gvRasterLayerRead.java @ 172
History | View | Annotate | Download (4.51 KB)
1 |
package org.gvsig.geoprocess.core; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
|
5 |
import es.unex.sextante.core.AnalysisExtent; |
6 |
import es.unex.sextante.core.Sextante; |
7 |
import es.unex.sextante.dataObjects.AbstractRasterLayer; |
8 |
import es.unex.sextante.outputs.IOutputChannel; |
9 |
|
10 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
11 |
import org.gvsig.fmap.dal.coverage.exception.GridException; |
12 |
import org.gvsig.fmap.dal.coverage.grid.Grid; |
13 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
14 |
|
15 |
/**
|
16 |
* A wrapper for a gvSIG Raster layer. Allows only reading, but not writing to
|
17 |
* it
|
18 |
*
|
19 |
* @author volaya, nacho brodin (nachobrodin@gmail.com)
|
20 |
*
|
21 |
*/
|
22 |
public class gvRasterLayerRead extends AbstractRasterLayer { |
23 |
|
24 |
private Grid m_LayerGrid = null; |
25 |
private FLyrRaster m_Layer;
|
26 |
private Buffer m_Buffer; |
27 |
private int m_iDataType; |
28 |
private double m_dNoDataValue; |
29 |
|
30 |
public void create(final FLyrRaster obj) { |
31 |
|
32 |
m_Layer = obj; |
33 |
} |
34 |
|
35 |
public int getDataType() { |
36 |
|
37 |
return m_Layer.getDataStore().getDataType()[0]; |
38 |
|
39 |
} |
40 |
|
41 |
public void setCellValue(final int x, final int y, final int iBand, |
42 |
final double dValue) { |
43 |
|
44 |
} |
45 |
|
46 |
public void setNoDataValue(final double dNoDataValue) { |
47 |
|
48 |
m_Layer.getNoDataValue().setValue(Double.valueOf(dNoDataValue));
|
49 |
|
50 |
} |
51 |
|
52 |
@Override
|
53 |
public void setNoData(final int x, final int y) { |
54 |
|
55 |
} |
56 |
|
57 |
public double getNoDataValue() { |
58 |
|
59 |
// TODO: Hablar con NACHO
|
60 |
return m_Layer.getNoDataValue().getValue().doubleValue();
|
61 |
|
62 |
} |
63 |
|
64 |
public double getCellValueInLayerCoords(final int x, final int y, |
65 |
final int iBand) { |
66 |
|
67 |
if (m_Buffer.isInside(x, y)) {
|
68 |
switch (m_iDataType) {
|
69 |
case Buffer.TYPE_BYTE: |
70 |
return m_Buffer.getElemByte(y, x, iBand);
|
71 |
case Buffer.TYPE_SHORT: |
72 |
return m_Buffer.getElemShort(y, x, iBand);
|
73 |
case Buffer.TYPE_INT: |
74 |
return m_Buffer.getElemInt(y, x, iBand);
|
75 |
case Buffer.TYPE_FLOAT: |
76 |
return m_Buffer.getElemFloat(y, x, iBand);
|
77 |
case Buffer.TYPE_DOUBLE: |
78 |
default:
|
79 |
return m_Buffer.getElemDouble(y, x, iBand);
|
80 |
} |
81 |
} else {
|
82 |
return m_dNoDataValue;
|
83 |
} |
84 |
|
85 |
} |
86 |
|
87 |
public int getBandsCount() { |
88 |
|
89 |
return m_Layer.getDataStore().getBandCount();
|
90 |
|
91 |
} |
92 |
|
93 |
public String getName() { |
94 |
|
95 |
return m_Layer.getName();
|
96 |
|
97 |
} |
98 |
|
99 |
public void postProcess() { |
100 |
|
101 |
} |
102 |
|
103 |
public void open() { |
104 |
|
105 |
try {
|
106 |
m_LayerGrid = m_Layer.getReadOnlyFullGrid(false);
|
107 |
m_Buffer = m_LayerGrid.getRasterBuf(); |
108 |
m_iDataType = m_LayerGrid.getDataType(); |
109 |
// TODO: Hablar con NACHO
|
110 |
m_dNoDataValue = |
111 |
m_LayerGrid.getNoDataValue().getValue().doubleValue(); |
112 |
} catch (final GridException e) { |
113 |
Sextante.addErrorToLog(e); |
114 |
} catch (final InterruptedException e) { |
115 |
Sextante.addErrorToLog(e); |
116 |
} |
117 |
|
118 |
} |
119 |
|
120 |
public void close() { |
121 |
|
122 |
// if (m_LayerGrid != null) {
|
123 |
// m_LayerGrid.free();
|
124 |
// }
|
125 |
m_LayerGrid = null;
|
126 |
|
127 |
} |
128 |
|
129 |
public Rectangle2D getFullExtent() { |
130 |
|
131 |
return new Rectangle2D.Double(m_Layer.getMinX(), m_Layer.getMaxY(), |
132 |
m_Layer.getPxWidth(), m_Layer.getPxHeight()); |
133 |
|
134 |
} |
135 |
|
136 |
public AnalysisExtent getLayerGridExtent() {
|
137 |
|
138 |
try {
|
139 |
final AnalysisExtent extent = new AnalysisExtent(); |
140 |
extent.setCellSize(m_Layer.getDataStore().getCellSize()); |
141 |
extent.setXRange(m_Layer.getMinX(), m_Layer.getMaxX(), true);
|
142 |
extent.setYRange(m_Layer.getMinY(), m_Layer.getMaxY(), true);
|
143 |
return extent;
|
144 |
} catch (final Exception e) { |
145 |
return null; |
146 |
} |
147 |
} |
148 |
|
149 |
public double getLayerCellSize() { |
150 |
|
151 |
return m_Layer.getDataStore().getCellSize();
|
152 |
|
153 |
} |
154 |
|
155 |
public Object getCRS() { |
156 |
|
157 |
return m_Layer.getProjection();
|
158 |
|
159 |
} |
160 |
|
161 |
public void setName(final String name) { |
162 |
|
163 |
m_Layer.setName(name); |
164 |
|
165 |
} |
166 |
|
167 |
public void free() { |
168 |
m_Layer.dispose(); |
169 |
m_Layer = null;
|
170 |
m_LayerGrid = null;
|
171 |
} |
172 |
|
173 |
public Object getBaseDataObject() { |
174 |
return m_Layer;
|
175 |
} |
176 |
|
177 |
public IOutputChannel getOutputChannel() {
|
178 |
return new IOutputChannel() { |
179 |
|
180 |
public String getAsCommandLineParameter() { |
181 |
return m_Layer.getName();
|
182 |
} |
183 |
}; |
184 |
} |
185 |
|
186 |
} |