gvsig-geoprocess / 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 @ 1054
History | View | Annotate | Download (9.79 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geoprocess.lib.sextante.dataObjects; |
25 |
|
26 |
import java.awt.geom.Rectangle2D; |
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;
|
38 |
|
39 |
import es.unex.sextante.core.AnalysisExtent; |
40 |
import es.unex.sextante.dataObjects.AbstractRasterLayer; |
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; |
58 |
|
59 |
/**
|
60 |
* A wrapper for a gvSIG Raster layer. Allows only reading, but not writing to
|
61 |
* it
|
62 |
*
|
63 |
* @author volaya, nacho brodin (nachobrodin@gmail.com)
|
64 |
* @deprecated Use FLyrRasterIRasterLayer
|
65 |
*/
|
66 |
public class FLyrRasterReadOnlyIRasterLayer_deprecated extends AbstractRasterLayer { |
67 |
|
68 |
private Grid m_LayerGrid = null; |
69 |
private RasterLayer m_Layer = null; |
70 |
private Buffer m_Buffer = null; |
71 |
private int m_iDataType = 0; |
72 |
private double m_dNoDataValue = 0; |
73 |
private int xTranslate = 0; |
74 |
private int yTranslate = 0; |
75 |
private AnalysisExtent layerExtent = null; |
76 |
|
77 |
public void create(final RasterLayer obj) { |
78 |
m_Layer = obj; |
79 |
} |
80 |
|
81 |
@Override
|
82 |
public int getDataType() { |
83 |
return m_Layer.getRasterStore().getBandDescriptor(0).getDataType(); |
84 |
} |
85 |
|
86 |
@Override
|
87 |
public void setCellValue(final int x, final int y, final int iBand, |
88 |
final double dValue) { |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void setNoDataValue(final double 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 |
} |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void setNoData(final int x, final int y) { |
106 |
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public double getNoDataValue() { |
111 |
return m_dNoDataValue;
|
112 |
} |
113 |
|
114 |
@Override
|
115 |
public double getCellValueInLayerCoords(final int x, final int y, |
116 |
final int iBand) { |
117 |
int newx = x - xTranslate;
|
118 |
int newy = y - yTranslate;
|
119 |
if (m_Buffer.isInside(newx, newy)) {
|
120 |
switch (m_iDataType) {
|
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:
|
130 |
default:
|
131 |
return m_Buffer.getBandDouble(iBand).getValue(newy, newx);
|
132 |
} |
133 |
} else {
|
134 |
return m_dNoDataValue;
|
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
@Override
|
140 |
public int getBandsCount() { |
141 |
return m_Layer.getRasterStore().getBands();
|
142 |
} |
143 |
|
144 |
@Override
|
145 |
public String getName() { |
146 |
return m_Layer.getName();
|
147 |
} |
148 |
|
149 |
|
150 |
@Override
|
151 |
public void postProcess() { |
152 |
|
153 |
} |
154 |
|
155 |
@Override
|
156 |
public void open() { |
157 |
/*try {
|
158 |
m_LayerGrid = m_Layer.getReadOnlyFullGrid(false);
|
159 |
m_Buffer = m_LayerGrid.getRasterBuf();
|
160 |
m_iDataType = m_LayerGrid.getDataType();
|
161 |
NoData nodata = m_LayerGrid.getNoDataValue();
|
162 |
m_dNoDataValue = nodata != null ?
|
163 |
(nodata.getValue() != null ? nodata.getValue().doubleValue() : 0.0d) :
|
164 |
0.0d;
|
165 |
} catch (GridException e) {
|
166 |
Sextante.addErrorToLog(e);
|
167 |
} catch (InterruptedException e) {
|
168 |
Sextante.addErrorToLog(e);
|
169 |
}*/
|
170 |
} |
171 |
|
172 |
@Override
|
173 |
public void close() { |
174 |
m_LayerGrid = null;
|
175 |
} |
176 |
|
177 |
@Override
|
178 |
public Rectangle2D getFullExtent() { |
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; |
185 |
} |
186 |
|
187 |
@Override
|
188 |
public AnalysisExtent getLayerGridExtent() {
|
189 |
if(layerExtent == null) { |
190 |
try {
|
191 |
layerExtent = new AnalysisExtent();
|
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) { |
197 |
return null; |
198 |
} |
199 |
} |
200 |
return layerExtent;
|
201 |
} |
202 |
|
203 |
@Override
|
204 |
public void setWindowExtent(final AnalysisExtent extent) { |
205 |
super.setWindowExtent(extent);
|
206 |
|
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); |
229 |
Buffer entireBuf = m_Buffer;
|
230 |
try {
|
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();
|
237 |
xTranslate = (int)Math.round((distx * extent.getNX()) / (extent.getXMax() - extent.getXMin())); |
238 |
yTranslate = (int)Math.round((disty * extent.getNY()) / (extent.getYMax() - extent.getYMin())); |
239 |
} catch (DataException ex) {
|
240 |
m_Buffer = entireBuf; |
241 |
} |
242 |
} |
243 |
|
244 |
@Override
|
245 |
public double getLayerCellSize() { |
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; |
252 |
} |
253 |
|
254 |
@Override
|
255 |
public Object getCRS() { |
256 |
return m_Layer.getProjection();
|
257 |
} |
258 |
|
259 |
@Override
|
260 |
public void setName(final String name) { |
261 |
m_Layer.setName(name); |
262 |
} |
263 |
|
264 |
@Override
|
265 |
public void free() { |
266 |
m_Layer.dispose(); |
267 |
m_Layer = null;
|
268 |
m_LayerGrid = null;
|
269 |
} |
270 |
|
271 |
@Override
|
272 |
public Object getBaseDataObject() { |
273 |
return m_Layer;
|
274 |
} |
275 |
|
276 |
@Override
|
277 |
public IOutputChannel getOutputChannel() {
|
278 |
return new IOutputChannel() { |
279 |
@Override
|
280 |
public String getAsCommandLineParameter() { |
281 |
return m_Layer.getName();
|
282 |
} |
283 |
}; |
284 |
} |
285 |
|
286 |
} |