Revision 382 org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.lib/org.gvsig.geoprocess.lib.sextante/src/main/java/org/gvsig/geoprocess/lib/sextante/dataObjects/FLyrRasterReadOnlyIRasterLayer.java
FLyrRasterReadOnlyIRasterLayer.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.geom.Rectangle2D; |
27 | 27 |
|
28 |
import es.unex.sextante.core.AnalysisExtent; |
|
29 |
import es.unex.sextante.core.Sextante; |
|
30 |
import es.unex.sextante.dataObjects.AbstractRasterLayer; |
|
31 |
import es.unex.sextante.outputs.IOutputChannel; |
|
32 |
|
|
28 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
29 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
33 | 30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
34 | 32 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
35 | 33 |
import org.gvsig.fmap.dal.coverage.exception.GridException; |
34 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
36 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
36 | 37 |
import org.gvsig.fmap.dal.coverage.grid.Grid; |
38 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
39 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
37 | 40 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
38 | 41 |
|
42 |
import es.unex.sextante.core.AnalysisExtent; |
|
43 |
import es.unex.sextante.core.Sextante; |
|
44 |
import es.unex.sextante.dataObjects.AbstractRasterLayer; |
|
45 |
import es.unex.sextante.outputs.IOutputChannel; |
|
46 |
|
|
39 | 47 |
/** |
40 | 48 |
* A wrapper for a gvSIG Raster layer. Allows only reading, but not writing to |
41 | 49 |
* it |
... | ... | |
45 | 53 |
*/ |
46 | 54 |
public class FLyrRasterReadOnlyIRasterLayer extends AbstractRasterLayer { |
47 | 55 |
|
48 |
private Grid m_LayerGrid = null; |
|
49 |
private FLyrRaster m_Layer; |
|
50 |
private Buffer m_Buffer; |
|
51 |
private int m_iDataType; |
|
52 |
private double m_dNoDataValue; |
|
56 |
private Grid m_LayerGrid = null; |
|
57 |
private FLyrRaster m_Layer = null; |
|
58 |
private Buffer m_Buffer = null; |
|
59 |
private int m_iDataType = 0; |
|
60 |
private double m_dNoDataValue = 0; |
|
61 |
private int xTranslate = 0; |
|
62 |
private int yTranslate = 0; |
|
63 |
private AnalysisExtent layerExtent = null; |
|
53 | 64 |
|
54 | 65 |
public void create(final FLyrRaster obj) { |
55 |
|
|
56 | 66 |
m_Layer = obj; |
57 | 67 |
} |
58 | 68 |
|
59 | 69 |
public int getDataType() { |
60 |
|
|
61 | 70 |
return m_Layer.getDataStore().getDataType()[0]; |
62 |
|
|
63 | 71 |
} |
64 | 72 |
|
65 | 73 |
public void setCellValue(final int x, final int y, final int iBand, |
66 | 74 |
final double dValue) { |
67 |
|
|
68 | 75 |
} |
69 | 76 |
|
70 | 77 |
public void setNoDataValue(final double dNoDataValue) { |
71 |
|
|
72 | 78 |
m_Layer.getNoDataValue().setValue(Double.valueOf(dNoDataValue)); |
73 |
|
|
74 | 79 |
} |
75 | 80 |
|
76 | 81 |
@Override |
... | ... | |
84 | 89 |
|
85 | 90 |
public double getCellValueInLayerCoords(final int x, final int y, |
86 | 91 |
final int iBand) { |
87 |
|
|
88 |
if (m_Buffer.isInside(x, y)) { |
|
92 |
int newx = x - xTranslate; |
|
93 |
int newy = y - yTranslate; |
|
94 |
if (m_Buffer.isInside(newx, newy)) { |
|
89 | 95 |
switch (m_iDataType) { |
90 | 96 |
case Buffer.TYPE_BYTE: |
91 |
return m_Buffer.getElemByte(y, x, iBand);
|
|
97 |
return m_Buffer.getElemByte(newy, newx, iBand);
|
|
92 | 98 |
case Buffer.TYPE_SHORT: |
93 |
return m_Buffer.getElemShort(y, x, iBand);
|
|
99 |
return m_Buffer.getElemShort(newy, newx, iBand);
|
|
94 | 100 |
case Buffer.TYPE_INT: |
95 |
return m_Buffer.getElemInt(y, x, iBand);
|
|
101 |
return m_Buffer.getElemInt(newy, newx, iBand);
|
|
96 | 102 |
case Buffer.TYPE_FLOAT: |
97 |
return m_Buffer.getElemFloat(y, x, iBand);
|
|
103 |
return m_Buffer.getElemFloat(newy, newx, iBand);
|
|
98 | 104 |
case Buffer.TYPE_DOUBLE: |
99 | 105 |
default: |
100 |
return m_Buffer.getElemDouble(y, x, iBand);
|
|
106 |
return m_Buffer.getElemDouble(newy, newx, iBand);
|
|
101 | 107 |
} |
102 | 108 |
} else { |
103 | 109 |
return m_dNoDataValue; |
... | ... | |
106 | 112 |
} |
107 | 113 |
|
108 | 114 |
public int getBandsCount() { |
109 |
|
|
110 | 115 |
return m_Layer.getDataStore().getBandCount(); |
111 |
|
|
112 | 116 |
} |
113 | 117 |
|
114 | 118 |
public String getName() { |
115 |
|
|
116 | 119 |
return m_Layer.getName(); |
117 |
|
|
118 | 120 |
} |
119 | 121 |
|
120 | 122 |
public void postProcess() { |
... | ... | |
122 | 124 |
} |
123 | 125 |
|
124 | 126 |
public void open() { |
125 |
|
|
126 | 127 |
try { |
127 | 128 |
m_LayerGrid = m_Layer.getReadOnlyFullGrid(false); |
128 | 129 |
m_Buffer = m_LayerGrid.getRasterBuf(); |
129 | 130 |
m_iDataType = m_LayerGrid.getDataType(); |
130 |
// TODO: Hablar con NACHO |
|
131 | 131 |
NoData nodata = m_LayerGrid.getNoDataValue(); |
132 |
m_dNoDataValue = |
|
133 |
nodata != null ? (nodata.getValue() != null ? nodata.getValue()
|
|
134 |
.doubleValue() : 0.0d) : 0.0d;
|
|
135 |
} catch (final GridException e) {
|
|
132 |
m_dNoDataValue = nodata != null ?
|
|
133 |
(nodata.getValue() != null ? nodata.getValue().doubleValue() : 0.0d) :
|
|
134 |
0.0d;
|
|
135 |
} catch (GridException e) { |
|
136 | 136 |
Sextante.addErrorToLog(e); |
137 |
} catch (final InterruptedException e) {
|
|
137 |
} catch (InterruptedException e) { |
|
138 | 138 |
Sextante.addErrorToLog(e); |
139 | 139 |
} |
140 |
|
|
141 | 140 |
} |
142 | 141 |
|
143 | 142 |
public void close() { |
144 |
|
|
145 |
// if (m_LayerGrid != null) { |
|
146 |
// m_LayerGrid.free(); |
|
147 |
// } |
|
148 | 143 |
m_LayerGrid = null; |
149 |
|
|
150 | 144 |
} |
151 | 145 |
|
152 | 146 |
public Rectangle2D getFullExtent() { |
153 |
|
|
154 | 147 |
return m_Layer.getFullRasterExtent().toRectangle2D(); |
155 |
|
|
156 | 148 |
} |
157 | 149 |
|
158 | 150 |
public AnalysisExtent getLayerGridExtent() { |
151 |
if(layerExtent == null) { |
|
152 |
try { |
|
153 |
layerExtent = new AnalysisExtent(); |
|
154 |
layerExtent.setCellSize(m_Layer.getDataStore().getCellSize()); |
|
155 |
layerExtent.setXRange(m_Layer.getMinX(), m_Layer.getMaxX(), true); |
|
156 |
layerExtent.setYRange(m_Layer.getMinY(), m_Layer.getMaxY(), true); |
|
157 |
} catch (final Exception e) { |
|
158 |
return null; |
|
159 |
} |
|
160 |
} |
|
161 |
return layerExtent; |
|
162 |
} |
|
163 |
|
|
164 |
public void setWindowExtent(final AnalysisExtent extent) { |
|
165 |
super.setWindowExtent(extent); |
|
159 | 166 |
|
167 |
RasterManager rManager = RasterLocator.getManager(); |
|
168 |
RasterDataStore store = m_Layer.getDataStore(); |
|
169 |
RasterQuery query = rManager.createQuery(); |
|
170 |
query.setReadOnly(true); |
|
171 |
int[] bands = new int[store.getBandCount()]; |
|
172 |
for (int i = 0; i < store.getBandCount(); i++) { |
|
173 |
bands[i] = i; |
|
174 |
} |
|
175 |
query.setDrawableBands(bands); |
|
176 |
Extent ext = RasterLocator.getManager().getDataStructFactory().createExtent( |
|
177 |
extent.getXMin(), |
|
178 |
extent.getYMax(), |
|
179 |
extent.getXMax(), |
|
180 |
extent.getYMin()); |
|
181 |
query.setAreaOfInterest(ext, extent.getNX(), extent.getNY()); |
|
182 |
Buffer entireBuf = m_Buffer; |
|
160 | 183 |
try { |
161 |
final AnalysisExtent extent = new AnalysisExtent(); |
|
162 |
extent.setCellSize(m_Layer.getDataStore().getCellSize()); |
|
163 |
extent.setXRange(m_Layer.getMinX(), m_Layer.getMaxX(), true); |
|
164 |
extent.setYRange(m_Layer.getMinY(), m_Layer.getMaxY(), true); |
|
165 |
return extent; |
|
166 |
} catch (final Exception e) { |
|
167 |
return null; |
|
168 |
} |
|
169 |
} |
|
184 |
m_Buffer = store.query(query); |
|
185 |
//Calculamos la traslaci?n respecto a la ventana recortada pq Sextante pedir? |
|
186 |
//p?xeles en relaci?n a la imagen completa |
|
187 |
double distx = extent.getXMin() - m_Layer.getMinX(); |
|
188 |
double disty = m_Layer.getMaxY() - extent.getYMax(); |
|
189 |
xTranslate = (int)Math.round((distx * extent.getNX()) / (extent.getXMax() - extent.getXMin())); |
|
190 |
yTranslate = (int)Math.round((disty * extent.getNY()) / (extent.getYMax() - extent.getYMin())); |
|
191 |
} catch (RasterDriverException e) { |
|
192 |
m_Buffer = entireBuf; |
|
193 |
} catch (ProcessInterruptedException e) { |
|
194 |
} catch (InvalidSetViewException e) { |
|
195 |
m_Buffer = entireBuf; |
|
196 |
} |
|
197 |
} |
|
170 | 198 |
|
171 | 199 |
public double getLayerCellSize() { |
172 |
|
|
173 | 200 |
return m_Layer.getDataStore().getCellSize(); |
174 |
|
|
175 | 201 |
} |
176 | 202 |
|
177 | 203 |
public Object getCRS() { |
178 |
|
|
179 | 204 |
return m_Layer.getProjection(); |
180 |
|
|
181 | 205 |
} |
182 | 206 |
|
183 | 207 |
public void setName(final String name) { |
184 |
|
|
185 | 208 |
m_Layer.setName(name); |
186 |
|
|
187 | 209 |
} |
188 | 210 |
|
189 | 211 |
public void free() { |
... | ... | |
198 | 220 |
|
199 | 221 |
public IOutputChannel getOutputChannel() { |
200 | 222 |
return new IOutputChannel() { |
201 |
|
|
202 | 223 |
public String getAsCommandLineParameter() { |
203 | 224 |
return m_Layer.getName(); |
204 | 225 |
} |
Also available in: Unified diff