Revision 1054
org.gvsig.geoprocess/branches/refactor-2018/org.gvsig.geoprocess/org.gvsig.geoprocess.lib/org.gvsig.geoprocess.lib.sextante/src/main/java/org/gvsig/geoprocess/lib/sextante/dataObjects/FLyrRasterReadOnlyIRasterLayer_deprecated.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.geom.Rectangle2D; |
27 | 27 |
|
28 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
29 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
32 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
33 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
34 |
import org.gvsig.fmap.dal.coverage.grid.Grid; |
|
35 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
36 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
37 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
28 |
//import org.gvsig.fmap.dal.coverage.RasterLocator;
|
|
29 |
//import org.gvsig.fmap.dal.coverage.RasterManager;
|
|
30 |
//import org.gvsig.fmap.dal.coverage.dataset.Buffer;
|
|
31 |
//import org.gvsig.fmap.dal.coverage.datastruct.Extent;
|
|
32 |
//import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
|
|
33 |
//import org.gvsig.fmap.dal.coverage.exception.QueryException;
|
|
34 |
//import org.gvsig.fmap.dal.coverage.grid.Grid;
|
|
35 |
//import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
|
|
36 |
//import org.gvsig.fmap.dal.coverage.store.RasterQuery;
|
|
37 |
//import org.gvsig.raster.fmap.layers.FLyrRaster;
|
|
38 | 38 |
|
39 | 39 |
import es.unex.sextante.core.AnalysisExtent; |
40 | 40 |
import es.unex.sextante.dataObjects.AbstractRasterLayer; |
41 | 41 |
import es.unex.sextante.outputs.IOutputChannel; |
42 |
import java.util.logging.Level; |
|
43 |
import java.util.logging.Logger; |
|
44 |
import org.gvsig.fmap.dal.exception.DataException; |
|
45 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
46 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
47 |
import org.gvsig.fmap.dal.raster.api.RasterQuery; |
|
48 |
import org.gvsig.fmap.dal.raster.api.RasterStore; |
|
49 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
50 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
51 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
52 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer; |
|
53 |
import org.gvsig.fmap.mapcontrol.tools.grid.Grid; |
|
54 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
|
55 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
|
56 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
|
57 |
import org.gvsig.raster.lib.buffer.api.NoData; |
|
42 | 58 |
|
43 | 59 |
/** |
44 | 60 |
* A wrapper for a gvSIG Raster layer. Allows only reading, but not writing to |
... | ... | |
50 | 66 |
public class FLyrRasterReadOnlyIRasterLayer_deprecated extends AbstractRasterLayer { |
51 | 67 |
|
52 | 68 |
private Grid m_LayerGrid = null; |
53 |
private FLyrRaster m_Layer = null;
|
|
69 |
private RasterLayer m_Layer = null;
|
|
54 | 70 |
private Buffer m_Buffer = null; |
55 | 71 |
private int m_iDataType = 0; |
56 | 72 |
private double m_dNoDataValue = 0; |
... | ... | |
58 | 74 |
private int yTranslate = 0; |
59 | 75 |
private AnalysisExtent layerExtent = null; |
60 | 76 |
|
61 |
public void create(final FLyrRaster obj) {
|
|
77 |
public void create(final RasterLayer obj) {
|
|
62 | 78 |
m_Layer = obj; |
63 | 79 |
} |
64 | 80 |
|
81 |
@Override |
|
65 | 82 |
public int getDataType() { |
66 |
return m_Layer.getDataStore().getDataType()[0];
|
|
83 |
return m_Layer.getRasterStore().getBandDescriptor(0).getDataType();
|
|
67 | 84 |
} |
68 | 85 |
|
86 |
@Override |
|
69 | 87 |
public void setCellValue(final int x, final int y, final int iBand, |
70 | 88 |
final double dValue) { |
71 | 89 |
} |
72 | 90 |
|
91 |
@Override |
|
73 | 92 |
public void setNoDataValue(final double dNoDataValue) { |
74 |
m_Layer.getNoDataValue().setValue(Double.valueOf(dNoDataValue)); |
|
93 |
|
|
94 |
for (int i = 0; i < m_Layer.getRasterStore().getBands(); i++) { |
|
95 |
if (m_Layer.getRasterStore().getBandDescriptor(i).getNoData()== null) { |
|
96 |
NoData nodata = BufferLocator.getBufferManager().createNoData(dNoDataValue, null); |
|
97 |
m_Layer.getRasterStore().getBandDescriptor(i).getNoData().setValue(nodata.getValue()); |
|
98 |
} else { |
|
99 |
m_Layer.getRasterStore().getBandDescriptor(i).getNoData().setValue(dNoDataValue); |
|
100 |
} |
|
101 |
} |
|
75 | 102 |
} |
76 | 103 |
|
77 | 104 |
@Override |
... | ... | |
79 | 106 |
|
80 | 107 |
} |
81 | 108 |
|
109 |
@Override |
|
82 | 110 |
public double getNoDataValue() { |
83 | 111 |
return m_dNoDataValue; |
84 | 112 |
} |
85 | 113 |
|
114 |
@Override |
|
86 | 115 |
public double getCellValueInLayerCoords(final int x, final int y, |
87 | 116 |
final int iBand) { |
88 | 117 |
int newx = x - xTranslate; |
89 | 118 |
int newy = y - yTranslate; |
90 | 119 |
if (m_Buffer.isInside(newx, newy)) { |
91 | 120 |
switch (m_iDataType) { |
92 |
case Buffer.TYPE_BYTE: |
|
93 |
return m_Buffer.getElemByte(newy, newx, iBand);
|
|
94 |
case Buffer.TYPE_SHORT: |
|
95 |
return m_Buffer.getElemShort(newy, newx, iBand);
|
|
96 |
case Buffer.TYPE_INT: |
|
97 |
return m_Buffer.getElemInt(newy, newx, iBand);
|
|
98 |
case Buffer.TYPE_FLOAT: |
|
99 |
return m_Buffer.getElemFloat(newy, newx, iBand);
|
|
100 |
case Buffer.TYPE_DOUBLE: |
|
121 |
case BufferManager.TYPE_BYTE:
|
|
122 |
return m_Buffer.getBandByte(iBand).getValue(newy, newx);
|
|
123 |
case BufferManager.TYPE_SHORT:
|
|
124 |
return m_Buffer.getBandShort(iBand).getValue(newy, newx);
|
|
125 |
case BufferManager.TYPE_INT:
|
|
126 |
return m_Buffer.getBandInt(iBand).getValue(newy, newx);
|
|
127 |
case BufferManager.TYPE_FLOAT:
|
|
128 |
return m_Buffer.getBandFloat(iBand).getValue(newy, newx);
|
|
129 |
case BufferManager.TYPE_DOUBLE:
|
|
101 | 130 |
default: |
102 |
return m_Buffer.getElemDouble(newy, newx, iBand);
|
|
131 |
return m_Buffer.getBandDouble(iBand).getValue(newy, newx);
|
|
103 | 132 |
} |
104 | 133 |
} else { |
105 | 134 |
return m_dNoDataValue; |
... | ... | |
107 | 136 |
|
108 | 137 |
} |
109 | 138 |
|
139 |
@Override |
|
110 | 140 |
public int getBandsCount() { |
111 |
return m_Layer.getDataStore().getBandCount();
|
|
141 |
return m_Layer.getRasterStore().getBands();
|
|
112 | 142 |
} |
113 | 143 |
|
144 |
@Override |
|
114 | 145 |
public String getName() { |
115 | 146 |
return m_Layer.getName(); |
116 | 147 |
} |
117 | 148 |
|
149 |
|
|
150 |
@Override |
|
118 | 151 |
public void postProcess() { |
119 | 152 |
|
120 | 153 |
} |
121 | 154 |
|
155 |
@Override |
|
122 | 156 |
public void open() { |
123 | 157 |
/*try { |
124 | 158 |
m_LayerGrid = m_Layer.getReadOnlyFullGrid(false); |
... | ... | |
135 | 169 |
}*/ |
136 | 170 |
} |
137 | 171 |
|
172 |
@Override |
|
138 | 173 |
public void close() { |
139 | 174 |
m_LayerGrid = null; |
140 | 175 |
} |
141 | 176 |
|
177 |
@Override |
|
142 | 178 |
public Rectangle2D getFullExtent() { |
143 |
return m_Layer.getFullRasterExtent().toRectangle2D(); |
|
179 |
try { |
|
180 |
return m_Layer.getFullEnvelope().getGeometry().getBounds().getBounds2D(); |
|
181 |
} catch (ReadException ex) { |
|
182 |
Logger.getLogger(FLyrRasterReadOnlyIRasterLayer_deprecated.class.getName()).log(Level.SEVERE, null, ex); |
|
183 |
} |
|
184 |
return null; |
|
144 | 185 |
} |
145 | 186 |
|
187 |
@Override |
|
146 | 188 |
public AnalysisExtent getLayerGridExtent() { |
147 | 189 |
if(layerExtent == null) { |
148 | 190 |
try { |
149 | 191 |
layerExtent = new AnalysisExtent(); |
150 |
layerExtent.setCellSize(m_Layer.getDataStore().getCellSize());
|
|
151 |
Extent ext = m_Layer.getFullRasterExtent();
|
|
152 |
layerExtent.setXRange(ext.minX(), ext.maxX(), true);
|
|
153 |
layerExtent.setYRange(ext.minY(), ext.maxY(), true);
|
|
154 |
} catch (final Exception e) { |
|
192 |
layerExtent.setCellSize(m_Layer.getRasterStore().getDimensions().getPixelSizeX());
|
|
193 |
Rectangle2D ext = getFullExtent();
|
|
194 |
layerExtent.setXRange(ext.getMinX(), ext.getMaxX(), true);
|
|
195 |
layerExtent.setYRange(ext.getMinY(), ext.getMaxY(), true);
|
|
196 |
} catch (final InitializeException e) {
|
|
155 | 197 |
return null; |
156 | 198 |
} |
157 | 199 |
} |
158 | 200 |
return layerExtent; |
159 | 201 |
} |
160 | 202 |
|
203 |
@Override |
|
161 | 204 |
public void setWindowExtent(final AnalysisExtent extent) { |
162 | 205 |
super.setWindowExtent(extent); |
163 | 206 |
|
164 |
RasterManager rManager = RasterLocator.getManager(); |
|
165 |
RasterDataStore store = m_Layer.getDataStore(); |
|
166 |
RasterQuery query = rManager.createQuery(); |
|
167 |
query.setReadOnly(true); |
|
168 |
int[] bands = new int[store.getBandCount()]; |
|
169 |
for (int i = 0; i < store.getBandCount(); i++) { |
|
170 |
bands[i] = i; |
|
171 |
} |
|
172 |
query.setDrawableBands(bands); |
|
173 |
Extent ext = RasterLocator.getManager().getDataStructFactory().createExtent( |
|
174 |
extent.getXMin(), |
|
175 |
extent.getYMax(), |
|
176 |
extent.getXMax(), |
|
177 |
extent.getYMin()); |
|
178 |
query.setAreaOfInterest(ext, extent.getNX(), extent.getNY()); |
|
207 |
BufferManager rManager = BufferLocator.getBufferManager(); |
|
208 |
RasterStore store = m_Layer.getRasterStore(); |
|
209 |
RasterQuery query = store.createRasterQuery(); |
|
210 |
//query.setReadOnly(true); |
|
211 |
// int[] bands = new int[store.getBands()]; |
|
212 |
// for (int i = 0; i < store.getBands(); i++) { |
|
213 |
// bands[i] = i; |
|
214 |
// } |
|
215 |
// query.setDrawableBands(bands); |
|
216 |
Envelope ext; |
|
217 |
try { |
|
218 |
ext = GeometryLocator.getGeometryManager().createEnvelope( |
|
219 |
extent.getXMin(), |
|
220 |
extent.getYMax(), |
|
221 |
extent.getXMax(), |
|
222 |
extent.getYMin(), |
|
223 |
2); |
|
224 |
} catch (CreateEnvelopeException ex) { |
|
225 |
ext = null; |
|
226 |
} |
|
227 |
|
|
228 |
query.setClip(ext); |
|
179 | 229 |
Buffer entireBuf = m_Buffer; |
180 | 230 |
try { |
181 |
m_Buffer = store.query(query);
|
|
182 |
//Calculamos la traslaci?n respecto a la ventana recortada pq Sextante pedir?
|
|
183 |
//p?xeles en relaci?n a la imagen completa
|
|
184 |
Extent lyrExt = m_Layer.getFullRasterExtent();
|
|
185 |
double distx = extent.getXMin() - lyrExt.minX();
|
|
186 |
double disty = lyrExt.maxY() - extent.getYMax();
|
|
231 |
m_Buffer = store.getRasterSet(query);
|
|
232 |
//Calculamos la traslaci?n respecto a la ventana recortada pq Sextante pedir?
|
|
233 |
//p?xeles en relaci?n a la imagen completa
|
|
234 |
Rectangle2D lyrExt = m_Layer.getFullEnvelope().getGeometry().getBounds().getBounds2D();
|
|
235 |
double distx = extent.getXMin() - lyrExt.getMinX();
|
|
236 |
double disty = lyrExt.getMaxY() - extent.getYMax();
|
|
187 | 237 |
xTranslate = (int)Math.round((distx * extent.getNX()) / (extent.getXMax() - extent.getXMin())); |
188 | 238 |
yTranslate = (int)Math.round((disty * extent.getNY()) / (extent.getYMax() - extent.getYMin())); |
189 |
} catch (QueryException e) {
|
|
239 |
} catch (DataException ex) {
|
|
190 | 240 |
m_Buffer = entireBuf; |
191 |
} catch (ProcessInterruptedException e) { |
|
192 |
} |
|
241 |
} |
|
193 | 242 |
} |
194 | 243 |
|
244 |
@Override |
|
195 | 245 |
public double getLayerCellSize() { |
196 |
return m_Layer.getDataStore().getCellSize(); |
|
246 |
try { |
|
247 |
return m_Layer.getRasterStore().getDimensions().getPixelSizeX(); |
|
248 |
} catch (InitializeException ex) { |
|
249 |
Logger.getLogger(FLyrRasterReadOnlyIRasterLayer_deprecated.class.getName()).log(Level.SEVERE, null, ex); |
|
250 |
} |
|
251 |
return 0; |
|
197 | 252 |
} |
198 | 253 |
|
254 |
@Override |
|
199 | 255 |
public Object getCRS() { |
200 | 256 |
return m_Layer.getProjection(); |
201 | 257 |
} |
202 | 258 |
|
259 |
@Override |
|
203 | 260 |
public void setName(final String name) { |
204 | 261 |
m_Layer.setName(name); |
205 | 262 |
} |
206 | 263 |
|
264 |
@Override |
|
207 | 265 |
public void free() { |
208 | 266 |
m_Layer.dispose(); |
209 | 267 |
m_Layer = null; |
210 | 268 |
m_LayerGrid = null; |
211 | 269 |
} |
212 | 270 |
|
271 |
@Override |
|
213 | 272 |
public Object getBaseDataObject() { |
214 | 273 |
return m_Layer; |
215 | 274 |
} |
216 | 275 |
|
276 |
@Override |
|
217 | 277 |
public IOutputChannel getOutputChannel() { |
218 | 278 |
return new IOutputChannel() { |
279 |
@Override |
|
219 | 280 |
public String getAsCommandLineParameter() { |
220 | 281 |
return m_Layer.getName(); |
221 | 282 |
} |
Also available in: Unified diff