root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / roi / ROI.java @ 12664
History | View | Annotate | Download (7.12 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package org.gvsig.raster.grid.roi; |
21 |
|
22 |
import java.awt.Color; |
23 |
import java.util.Arrays; |
24 |
|
25 |
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException; |
26 |
import org.gvsig.raster.dataset.IBuffer; |
27 |
import org.gvsig.raster.grid.Grid; |
28 |
import org.gvsig.raster.grid.GridCell; |
29 |
import org.gvsig.raster.grid.GridExtent; |
30 |
import org.gvsig.raster.grid.IQueryableGrid; |
31 |
|
32 |
/**
|
33 |
* Clase que representa las Regiones de Interes.
|
34 |
*
|
35 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
36 |
*
|
37 |
*/
|
38 |
public abstract class ROI implements IQueryableGrid { |
39 |
|
40 |
private String name = ""; |
41 |
private Color color = null; |
42 |
private Grid grid = null; // Grid asociado a la ROI y que le proporciona los datos. |
43 |
private ROIStatistic statistic = null; |
44 |
private GridExtent roiExtent = null; // M?nimo extent que contiene al ROI. |
45 |
protected int xOffset = 0; // Coord. x del grid donde est? la esquina sup. iz. del roi (coords. pixel) |
46 |
protected int yOffset = 0; // Coord. y del grid donde est? la esquina sup. iz. del roi (coords. pixel) |
47 |
|
48 |
|
49 |
public ROI(Grid grid) {
|
50 |
this.grid = grid;
|
51 |
roiExtent = new GridExtent();
|
52 |
roiExtent.setCellSize(grid.getCellSize()); |
53 |
statistic = new ROIStatistic(this); |
54 |
} |
55 |
|
56 |
public ROI add(ROI roi){
|
57 |
return null; |
58 |
} |
59 |
|
60 |
public ROI intersect(ROI roi){
|
61 |
return null; |
62 |
} |
63 |
|
64 |
public ROI subtract(ROI roi){
|
65 |
return null; |
66 |
} |
67 |
|
68 |
public ROI exclusiveOr(ROI roi){
|
69 |
return null; |
70 |
} |
71 |
|
72 |
public double getAspect(int x, int y) |
73 |
throws RasterBufferInvalidAccessException {
|
74 |
if (isInGrid(x, y))
|
75 |
return grid.getAspect(x, y);
|
76 |
else return getNoDataValue(); |
77 |
} |
78 |
|
79 |
public double getCellSize() { |
80 |
return grid.getCellSize();
|
81 |
} |
82 |
|
83 |
public byte getCellValueAsByte(int x, int y) |
84 |
throws RasterBufferInvalidAccessException {
|
85 |
if (isInGrid(x, y))
|
86 |
return grid.getCellValueAsByte(xOffset+x, yOffset+y);
|
87 |
else
|
88 |
return (byte) grid.getNoDataValue(); |
89 |
} |
90 |
|
91 |
public double getCellValueAsDouble(int x, int y) |
92 |
throws RasterBufferInvalidAccessException {
|
93 |
if (isInGrid(x, y))
|
94 |
return grid.getCellValueAsDouble(xOffset+x, yOffset+y);
|
95 |
else
|
96 |
return grid.getNoDataValue();
|
97 |
} |
98 |
|
99 |
public float getCellValueAsFloat(int x, int y) |
100 |
throws RasterBufferInvalidAccessException {
|
101 |
if (isInGrid(x, y))
|
102 |
return grid.getCellValueAsFloat(xOffset+x, yOffset+y);
|
103 |
else
|
104 |
return (float) grid.getNoDataValue(); |
105 |
} |
106 |
|
107 |
public int getCellValueAsInt(int x, int y) |
108 |
throws RasterBufferInvalidAccessException {
|
109 |
if (isInGrid(x, y))
|
110 |
return grid.getCellValueAsInt(xOffset+x, yOffset+y);
|
111 |
else
|
112 |
return (int) grid.getNoDataValue(); |
113 |
} |
114 |
|
115 |
public short getCellValueAsShort(int x, int y) |
116 |
throws RasterBufferInvalidAccessException {
|
117 |
if (isInGrid(x, y))
|
118 |
return grid.getCellValueAsShort(xOffset+x, yOffset+y);
|
119 |
else
|
120 |
return (short) grid.getNoDataValue(); |
121 |
} |
122 |
|
123 |
public int getDirToNextDownslopeCell(int x, int y) throws RasterBufferInvalidAccessException { |
124 |
return getDirToNextDownslopeCell(x, y, true); |
125 |
} |
126 |
|
127 |
public int getDirToNextDownslopeCell(int x, int y,boolean bForceDirToNoDataCell) |
128 |
throws RasterBufferInvalidAccessException {
|
129 |
if (isInGrid(x, y))
|
130 |
return grid.getDirToNextDownslopeCell(x, y, bForceDirToNoDataCell);
|
131 |
else
|
132 |
return -1; |
133 |
} |
134 |
|
135 |
public double getDistToNeighborInDir(int iDir) { |
136 |
return grid.getDistToNeighborInDir(iDir);
|
137 |
} |
138 |
|
139 |
public GridExtent getGridExtent() {
|
140 |
return roiExtent;
|
141 |
} |
142 |
|
143 |
public int getLayerNX() { |
144 |
return grid.getLayerNX();
|
145 |
} |
146 |
|
147 |
public int getLayerNY() { |
148 |
return grid.getLayerNY();
|
149 |
} |
150 |
|
151 |
public double getMaxValue() { |
152 |
if (!statistic.isStatisticsCalculated())
|
153 |
try {
|
154 |
statistic.calculateStatistics(); |
155 |
} catch (RasterBufferInvalidAccessException e) {
|
156 |
//No se calculan las estad?sticas. No hacemos nada
|
157 |
e.printStackTrace(); |
158 |
} |
159 |
return statistic.getMax();
|
160 |
} |
161 |
|
162 |
public double getMeanValue() { |
163 |
if (!statistic.isStatisticsCalculated())
|
164 |
try {
|
165 |
statistic.calculateStatistics(); |
166 |
} catch (RasterBufferInvalidAccessException e) {
|
167 |
//No se calculan las estad?sticas. No hacemos nada
|
168 |
e.printStackTrace(); |
169 |
} |
170 |
return statistic.getMean();
|
171 |
} |
172 |
|
173 |
public double getMinValue() { |
174 |
if (!statistic.isStatisticsCalculated())
|
175 |
try {
|
176 |
statistic.calculateStatistics(); |
177 |
} catch (RasterBufferInvalidAccessException e) {
|
178 |
//No se calculan las estad?sticas. No hacemos nada
|
179 |
e.printStackTrace(); |
180 |
} |
181 |
return statistic.getMin();
|
182 |
} |
183 |
|
184 |
public int getNX() { |
185 |
return roiExtent.getNX();
|
186 |
} |
187 |
|
188 |
public int getNY() { |
189 |
return roiExtent.getNY();
|
190 |
} |
191 |
|
192 |
public double getNoDataValue() { |
193 |
// TODO Ver si usar un nodatavalue especifico del roi.
|
194 |
return grid.getNoDataValue();
|
195 |
} |
196 |
|
197 |
public double getSlope(int x, int y) throws RasterBufferInvalidAccessException { |
198 |
if (isInGrid(x, y))
|
199 |
return grid.getSlope(x, y);
|
200 |
else
|
201 |
return getNoDataValue();
|
202 |
} |
203 |
|
204 |
public GridCell[] getSortedArrayOfCells() throws RasterBufferInvalidAccessException { |
205 |
int i;
|
206 |
int iX,iY;
|
207 |
int iNX = getNX();
|
208 |
int iCells = getNX() * getNY();
|
209 |
GridCell [] cells = null; |
210 |
GridCell cell = null;
|
211 |
|
212 |
cells = new GridCell[iCells];
|
213 |
|
214 |
for (i = 0; i < iCells; i++){ |
215 |
iX = i % iNX; |
216 |
iY = i / iNX; |
217 |
switch(grid.getDataType()){
|
218 |
case IBuffer.TYPE_BYTE: cell = new GridCell(iX, iY, getCellValueAsByte(iX, iY)); break; |
219 |
case IBuffer.TYPE_SHORT: cell = new GridCell(iX, iY, getCellValueAsShort(iX, iY)); break; |
220 |
case IBuffer.TYPE_INT: cell = new GridCell(iX, iY, getCellValueAsInt(iX, iY)); break; |
221 |
case IBuffer.TYPE_FLOAT: cell = new GridCell(iX, iY, getCellValueAsFloat(iX, iY)); break; |
222 |
case IBuffer.TYPE_DOUBLE: cell = new GridCell(iX, iY, getCellValueAsDouble(iX, iY)); break; |
223 |
} |
224 |
|
225 |
cells[i] = cell; |
226 |
} |
227 |
|
228 |
Arrays.sort(cells);
|
229 |
|
230 |
return cells;
|
231 |
} |
232 |
|
233 |
public double getVariance() { |
234 |
if (!statistic.isStatisticsCalculated())
|
235 |
try {
|
236 |
statistic.calculateStatistics(); |
237 |
} catch (RasterBufferInvalidAccessException e) {
|
238 |
//No se calculan las estad?sticas. No hacemos nada
|
239 |
e.printStackTrace(); |
240 |
} |
241 |
return statistic.getVariance();
|
242 |
} |
243 |
|
244 |
public abstract boolean isInGrid(int x, int y); |
245 |
|
246 |
public boolean isNoDataValue(double dValue) { |
247 |
return grid.isNoDataValue(dValue);
|
248 |
} |
249 |
|
250 |
public void setInterpolationMethod(int iMethod) { |
251 |
grid.setInterpolationMethod(iMethod); |
252 |
} |
253 |
|
254 |
public Grid getGrid() {
|
255 |
return grid;
|
256 |
} |
257 |
|
258 |
public Color getColor() { |
259 |
return color;
|
260 |
} |
261 |
|
262 |
public void setColor(Color color) { |
263 |
this.color = color;
|
264 |
} |
265 |
|
266 |
public String getName() { |
267 |
return name;
|
268 |
} |
269 |
|
270 |
public void setName(String name) { |
271 |
this.name = name;
|
272 |
} |
273 |
|
274 |
} |