Revision 12664
trunk/libraries/libRaster/src-test/org/gvsig/raster/grid/roi/TestRoiStatistics.java | ||
---|---|---|
1 |
package org.gvsig.raster.grid.roi; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
|
|
5 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
|
6 |
import org.gvsig.raster.dataset.IBuffer; |
|
7 |
import org.gvsig.raster.grid.Grid; |
|
8 |
import org.gvsig.raster.grid.GridExtent; |
|
9 |
import org.gvsig.raster.grid.OutOfGridException; |
|
10 |
|
|
11 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
12 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
13 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
14 |
|
|
15 |
/** |
|
16 |
* Test sobre la obtenci?n de estad?sticas de regiones de inter?s. |
|
17 |
* |
|
18 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class TestRoiStatistics extends TestCase { |
|
22 |
Grid grid = null; |
|
23 |
GridExtent extent = null; |
|
24 |
int cellSize = 1; |
|
25 |
double xMin = 0; |
|
26 |
double xMax = 10; |
|
27 |
double yMin = 0; |
|
28 |
double yMax = 10; |
|
29 |
VectorialROI roi = null; |
|
30 |
GeneralPathX path = null; |
|
31 |
IGeometry geometry = null; |
|
32 |
|
|
33 |
public void setUp() { |
|
34 |
int bands[] = {0}; |
|
35 |
extent = new GridExtent(); |
|
36 |
extent.setCellSize(cellSize); |
|
37 |
extent.setXRange(xMin, xMax); |
|
38 |
extent.setYRange(yMin, yMax); |
|
39 |
try { |
|
40 |
grid = new Grid(extent, extent, IBuffer.TYPE_DOUBLE, bands); |
|
41 |
for (int x = 0; x<5; x++) |
|
42 |
for (int y = 0; y<5; y++){ |
|
43 |
grid.setCellValue(x, y, 0.0); |
|
44 |
} |
|
45 |
for (int x = 5; x<xMax; x++) |
|
46 |
for (int y = 0; y<5; y++){ |
|
47 |
grid.setCellValue(x, y, 1.0); |
|
48 |
} |
|
49 |
for (int x = 0; x<5; x++) |
|
50 |
for (int y = 5; y<10; y++){ |
|
51 |
grid.setCellValue(x, y, 2.0); |
|
52 |
} |
|
53 |
for (int x = 5; x<9; x++) |
|
54 |
for (int y = 5; y<10; y++){ |
|
55 |
grid.setCellValue(x, y, 3.0); |
|
56 |
} |
|
57 |
} catch (RasterBufferInvalidException e) { |
|
58 |
// TODO Auto-generated catch block |
|
59 |
e.printStackTrace(); |
|
60 |
} catch (OutOfGridException e) { |
|
61 |
// TODO Auto-generated catch block |
|
62 |
e.printStackTrace(); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
66 |
|
|
67 |
public void start() { |
|
68 |
this.setUp(); |
|
69 |
this.testStack(); |
|
70 |
} |
|
71 |
|
|
72 |
public void testStack() { |
|
73 |
|
|
74 |
path = new GeneralPathX(); |
|
75 |
|
|
76 |
|
|
77 |
path.moveTo(4,4); |
|
78 |
path.lineTo(4,0); |
|
79 |
path.lineTo(0,0); |
|
80 |
path.lineTo(0,4); |
|
81 |
path.closePath(); |
|
82 |
|
|
83 |
geometry=ShapeFactory.createPolygon2D(path); |
|
84 |
|
|
85 |
roi = new VectorialROI(grid); |
|
86 |
roi.addGeometry(geometry); |
|
87 |
assertEquals(2.0,roi.getMaxValue(),0.0); |
|
88 |
assertEquals(2.0,roi.getMeanValue(),0.0); |
|
89 |
assertEquals(2.0,roi.getMinValue(),0.0); |
|
90 |
|
|
91 |
|
|
92 |
path = new GeneralPathX(); |
|
93 |
|
|
94 |
path.moveTo(9,4); |
|
95 |
path.lineTo(9,2); |
|
96 |
path.lineTo(6,2); |
|
97 |
path.lineTo(6,4); |
|
98 |
path.closePath(); |
|
99 |
|
|
100 |
geometry=ShapeFactory.createPolygon2D(path); |
|
101 |
|
|
102 |
roi = new VectorialROI(grid); |
|
103 |
roi.addGeometry(geometry); |
|
104 |
assertEquals(3.0,roi.getMaxValue(),0.0); |
|
105 |
assertEquals(3.0,roi.getMeanValue(),0.0); |
|
106 |
assertEquals(3.0,roi.getMinValue(),0.0); |
|
107 |
} |
|
108 |
} |
|
0 | 109 |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/roi/ROIStatistic.java | ||
---|---|---|
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 org.gvsig.raster.buffer.RasterBufferInvalidAccessException; |
|
23 |
import org.gvsig.raster.dataset.IBuffer; |
|
24 |
|
|
25 |
/** |
|
26 |
* Estad?sticas asociadas a una ROI. |
|
27 |
* |
|
28 |
* Diego Guerrero Sevilla (diego.guerrero@uclm.es) |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class ROIStatistic { |
|
32 |
private ROI roi = null; |
|
33 |
private double[] max = null; |
|
34 |
private double[] min = null; |
|
35 |
private double[] mean = null; |
|
36 |
private double[] variance = null; |
|
37 |
private boolean statisticsCalculated = false; |
|
38 |
protected int bandToOperate = 0; |
|
39 |
|
|
40 |
public ROIStatistic(ROI roi) { |
|
41 |
this.roi = roi; |
|
42 |
} |
|
43 |
|
|
44 |
public void calculateStatistics() throws RasterBufferInvalidAccessException{ |
|
45 |
int x, y; |
|
46 |
double z; |
|
47 |
int[] iValues = new int[roi.getGrid().getBandCount()]; |
|
48 |
mean = new double[roi.getGrid().getBandCount()]; |
|
49 |
min = new double[roi.getGrid().getBandCount()]; |
|
50 |
max = new double[roi.getGrid().getBandCount()]; |
|
51 |
variance = new double[roi.getGrid().getBandCount()]; |
|
52 |
|
|
53 |
for (int iBand = 0; iBand < roi.getGrid().getBandCount(); iBand++) { |
|
54 |
mean[iBand] = 0.0; |
|
55 |
variance[iBand] = 0.0; |
|
56 |
iValues[iBand] = 0; |
|
57 |
} |
|
58 |
int oldBandToOperate = bandToOperate; |
|
59 |
statisticsCalculated = true; |
|
60 |
|
|
61 |
for (int iBand = 0; iBand < roi.getGrid().getBandCount(); iBand++) { |
|
62 |
roi.getGrid().setBandToOperate(iBand); |
|
63 |
for (y = 0; y <= roi.getNY(); y++){ //TODO: Consultar con Nacho. Creo que NY y NX se calculan mal. |
|
64 |
for (x = 0; x <= roi.getNX(); x++){ |
|
65 |
if(roi.isInGrid(x, y)){ //TODO: comprobarlo solo una vez, no para cada banda.... |
|
66 |
z = getValue(x, y); |
|
67 |
if(!roi.isNoDataValue(z)) { |
|
68 |
if( iValues[iBand] == 0 ) |
|
69 |
min[iBand] = max[iBand] = z; |
|
70 |
else if( min[iBand] > z ) |
|
71 |
min[iBand] = z; |
|
72 |
else if( max[iBand] < z ) |
|
73 |
max[iBand] = z; |
|
74 |
|
|
75 |
mean[iBand] += z; |
|
76 |
variance[iBand] += z * z; |
|
77 |
iValues[iBand]++; |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
if( iValues[iBand] > 0 ){ |
|
84 |
mean[iBand] /= (double) iValues[iBand]; |
|
85 |
variance[iBand] = variance[iBand] / (double) iValues[iBand] - mean[iBand] * mean[iBand]; |
|
86 |
} |
|
87 |
} |
|
88 |
bandToOperate = oldBandToOperate; |
|
89 |
statisticsCalculated = true; |
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Obtiene un valor de una celda del grid independientemente del tipo de dato. |
|
95 |
* @param x Posici?n en X |
|
96 |
* @param y Posici?n en Y |
|
97 |
* @return Valor de la celda en formato double |
|
98 |
* @throws RasterBufferInvalidAccessException |
|
99 |
* @throws RasterBufferInvalidAccessException |
|
100 |
*/ |
|
101 |
private double getValue(int x, int y) throws RasterBufferInvalidAccessException { |
|
102 |
switch(roi.getGrid().getDataType()) { |
|
103 |
case IBuffer.TYPE_BYTE:return (double)(roi.getCellValueAsByte(x, y) & 0xff); |
|
104 |
case IBuffer.TYPE_SHORT:return (double)(roi.getCellValueAsShort(x, y) & 0xffff); |
|
105 |
case IBuffer.TYPE_INT:return (double)(roi.getCellValueAsInt(x, y) & 0xffffffff); |
|
106 |
case IBuffer.TYPE_FLOAT:return (double)roi.getCellValueAsFloat(x, y); |
|
107 |
case IBuffer.TYPE_DOUBLE:return (double)roi.getCellValueAsDouble(x, y); |
|
108 |
} |
|
109 |
return 0; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Obtiene el valor m?ximo del grid |
|
114 |
* @return Valor m?ximo |
|
115 |
*/ |
|
116 |
public double getMax() { |
|
117 |
return max[bandToOperate]; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Obtiene el valor m?dio del grid |
|
122 |
* @return Valor medio |
|
123 |
*/ |
|
124 |
public double getMean() { |
|
125 |
return mean[bandToOperate]; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Obtiene el valor m?ximo del grid |
|
130 |
* @return Valor m?nimo |
|
131 |
*/ |
|
132 |
public double getMin() { |
|
133 |
return min[bandToOperate]; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Consulta si las estadisticas han sido calculadas o no. |
|
138 |
* @return true si las estadisticas del grid est?n calculadas y false si no lo est?n |
|
139 |
*/ |
|
140 |
public boolean isStatisticsCalculated() { |
|
141 |
return statisticsCalculated; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Asigna el flag que informa si las estadisticas est?n calculadas para un grid concreto |
|
146 |
* @param calc true si est?n calculadas y false si no lo est?n |
|
147 |
*/ |
|
148 |
public void setStatisticsCalculated(boolean calc){ |
|
149 |
this.statisticsCalculated = calc; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Obtiene la varianza |
|
154 |
* @return Varianza |
|
155 |
*/ |
|
156 |
public double getVariance() { |
|
157 |
return variance[bandToOperate]; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Asigna la banda sobre la que se realizan las operaciones. Por defecto es la banda 0 |
|
162 |
* con lo que para el uso de MDTs no habr? que modificar este valor. |
|
163 |
* @param band Banda sobre la que se realizan las operaciones. |
|
164 |
*/ |
|
165 |
public void setBandToOperate(int band){ |
|
166 |
this.bandToOperate = band; |
|
167 |
} |
|
168 |
} |
|
0 | 169 |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/roi/VectorialROI.java | ||
---|---|---|
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.util.ArrayList; |
|
23 |
|
|
24 |
import org.gvsig.raster.grid.Grid; |
|
25 |
|
|
26 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
27 |
|
|
28 |
/** |
|
29 |
* Clase que representa una regi?n de interes conformada por |
|
30 |
* elementos vectoriales. |
|
31 |
* |
|
32 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class VectorialROI extends ROI { |
|
36 |
|
|
37 |
private ArrayList geometries = null; // Array de geometr?as (IGeometry) que definen el ROI. |
|
38 |
|
|
39 |
public VectorialROI(Grid grid) { |
|
40 |
super(grid); |
|
41 |
geometries = new ArrayList(); |
|
42 |
} |
|
43 |
|
|
44 |
public boolean isInGrid(int x, int y) { |
|
45 |
boolean inRoi = false; |
|
46 |
if (x>=0 && x<getNX() && y >=0 && y<getNY()){ |
|
47 |
double mapX = this.getGridExtent().getMin().getX() + x*getCellSize(); |
|
48 |
double mapY = this.getGridExtent().getMax().getY() - y*getCellSize(); |
|
49 |
for (int i = 0; i < geometries.size(); i++) |
|
50 |
if (((IGeometry)geometries.get(i)).contains(mapX,mapY)){ //TODO:Ver como est? funcionando contains y si me vale. |
|
51 |
inRoi=true; |
|
52 |
break; |
|
53 |
} |
|
54 |
} |
|
55 |
return inRoi; |
|
56 |
} |
|
57 |
|
|
58 |
public void addGeometry(IGeometry geometry){ |
|
59 |
geometries.add(geometry); |
|
60 |
|
|
61 |
double minX = Math.min(geometry.getBounds2D().getMinX(),getGridExtent().getMin().getX()); |
|
62 |
double minY = Math.min(geometry.getBounds2D().getMinY(),getGridExtent().getMin().getY()); |
|
63 |
double maxX = Math.max(geometry.getBounds2D().getMaxX(),getGridExtent().getMax().getX()); |
|
64 |
double maxY = Math.max(geometry.getBounds2D().getMaxY(),getGridExtent().getMax().getY()); |
|
65 |
|
|
66 |
getGridExtent().setXRange(minX, maxX); |
|
67 |
getGridExtent().setYRange(minY, maxY); |
|
68 |
|
|
69 |
xOffset = (int)((minX - getGrid().getGridExtent().getMin().getX())/getCellSize()); |
|
70 |
yOffset = (int)((getGrid().getGridExtent().getMax().getY()- maxY)/getCellSize()); |
|
71 |
} |
|
72 |
|
|
73 |
public void deleteGeometry(int index){ |
|
74 |
geometries.remove(index); |
|
75 |
//TODO: Reajustar el Extent. |
|
76 |
} |
|
77 |
} |
|
0 | 78 |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/roi/ROI.java | ||
---|---|---|
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 |
} |
|
0 | 275 |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/roi/RasterROI.java | ||
---|---|---|
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 org.gvsig.raster.grid.Grid; |
|
23 |
|
|
24 |
/** |
|
25 |
* Clase que representa una regi?n de interes conformada por |
|
26 |
* un raster. |
|
27 |
* |
|
28 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class RasterROI extends ROI { |
|
32 |
|
|
33 |
public RasterROI(Grid grid) { |
|
34 |
super(grid); |
|
35 |
} |
|
36 |
|
|
37 |
public boolean isInGrid(int x, int y) { |
|
38 |
// TODO Auto-generated method stub |
|
39 |
return false; |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
0 | 43 |
Also available in: Unified diff