gvsig-geoprocess / 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_deprecated.java @ 469
History | View | Annotate | Download (7.41 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 |
|
43 |
/**
|
44 |
* A wrapper for a gvSIG Raster layer. Allows only reading, but not writing to
|
45 |
* it
|
46 |
*
|
47 |
* @author volaya, nacho brodin (nachobrodin@gmail.com)
|
48 |
* @deprecated Use FLyrRasterIRasterLayer
|
49 |
*/
|
50 |
public class FLyrRasterReadOnlyIRasterLayer_deprecated extends AbstractRasterLayer { |
51 |
|
52 |
private Grid m_LayerGrid = null; |
53 |
private FLyrRaster m_Layer = null; |
54 |
private Buffer m_Buffer = null; |
55 |
private int m_iDataType = 0; |
56 |
private double m_dNoDataValue = 0; |
57 |
private int xTranslate = 0; |
58 |
private int yTranslate = 0; |
59 |
private AnalysisExtent layerExtent = null; |
60 |
|
61 |
public void create(final FLyrRaster obj) { |
62 |
m_Layer = obj; |
63 |
} |
64 |
|
65 |
public int getDataType() { |
66 |
return m_Layer.getDataStore().getDataType()[0]; |
67 |
} |
68 |
|
69 |
public void setCellValue(final int x, final int y, final int iBand, |
70 |
final double dValue) { |
71 |
} |
72 |
|
73 |
public void setNoDataValue(final double dNoDataValue) { |
74 |
m_Layer.getNoDataValue().setValue(Double.valueOf(dNoDataValue));
|
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void setNoData(final int x, final int y) { |
79 |
|
80 |
} |
81 |
|
82 |
public double getNoDataValue() { |
83 |
return m_dNoDataValue;
|
84 |
} |
85 |
|
86 |
public double getCellValueInLayerCoords(final int x, final int y, |
87 |
final int iBand) { |
88 |
int newx = x - xTranslate;
|
89 |
int newy = y - yTranslate;
|
90 |
if (m_Buffer.isInside(newx, newy)) {
|
91 |
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: |
101 |
default:
|
102 |
return m_Buffer.getElemDouble(newy, newx, iBand);
|
103 |
} |
104 |
} else {
|
105 |
return m_dNoDataValue;
|
106 |
} |
107 |
|
108 |
} |
109 |
|
110 |
public int getBandsCount() { |
111 |
return m_Layer.getDataStore().getBandCount();
|
112 |
} |
113 |
|
114 |
public String getName() { |
115 |
return m_Layer.getName();
|
116 |
} |
117 |
|
118 |
public void postProcess() { |
119 |
|
120 |
} |
121 |
|
122 |
public void open() { |
123 |
/*try {
|
124 |
m_LayerGrid = m_Layer.getReadOnlyFullGrid(false);
|
125 |
m_Buffer = m_LayerGrid.getRasterBuf();
|
126 |
m_iDataType = m_LayerGrid.getDataType();
|
127 |
NoData nodata = m_LayerGrid.getNoDataValue();
|
128 |
m_dNoDataValue = nodata != null ?
|
129 |
(nodata.getValue() != null ? nodata.getValue().doubleValue() : 0.0d) :
|
130 |
0.0d;
|
131 |
} catch (GridException e) {
|
132 |
Sextante.addErrorToLog(e);
|
133 |
} catch (InterruptedException e) {
|
134 |
Sextante.addErrorToLog(e);
|
135 |
}*/
|
136 |
} |
137 |
|
138 |
public void close() { |
139 |
m_LayerGrid = null;
|
140 |
} |
141 |
|
142 |
public Rectangle2D getFullExtent() { |
143 |
return m_Layer.getFullRasterExtent().toRectangle2D();
|
144 |
} |
145 |
|
146 |
public AnalysisExtent getLayerGridExtent() {
|
147 |
if(layerExtent == null) { |
148 |
try {
|
149 |
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) { |
155 |
return null; |
156 |
} |
157 |
} |
158 |
return layerExtent;
|
159 |
} |
160 |
|
161 |
public void setWindowExtent(final AnalysisExtent extent) { |
162 |
super.setWindowExtent(extent);
|
163 |
|
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()); |
179 |
Buffer entireBuf = m_Buffer;
|
180 |
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();
|
187 |
xTranslate = (int)Math.round((distx * extent.getNX()) / (extent.getXMax() - extent.getXMin())); |
188 |
yTranslate = (int)Math.round((disty * extent.getNY()) / (extent.getYMax() - extent.getYMin())); |
189 |
} catch (QueryException e) {
|
190 |
m_Buffer = entireBuf; |
191 |
} catch (ProcessInterruptedException e) {
|
192 |
} |
193 |
} |
194 |
|
195 |
public double getLayerCellSize() { |
196 |
return m_Layer.getDataStore().getCellSize();
|
197 |
} |
198 |
|
199 |
public Object getCRS() { |
200 |
return m_Layer.getProjection();
|
201 |
} |
202 |
|
203 |
public void setName(final String name) { |
204 |
m_Layer.setName(name); |
205 |
} |
206 |
|
207 |
public void free() { |
208 |
m_Layer.dispose(); |
209 |
m_Layer = null;
|
210 |
m_LayerGrid = null;
|
211 |
} |
212 |
|
213 |
public Object getBaseDataObject() { |
214 |
return m_Layer;
|
215 |
} |
216 |
|
217 |
public IOutputChannel getOutputChannel() {
|
218 |
return new IOutputChannel() { |
219 |
public String getAsCommandLineParameter() { |
220 |
return m_Layer.getName();
|
221 |
} |
222 |
}; |
223 |
} |
224 |
|
225 |
} |