Revision 13340
trunk/extensions/extRasterTools-SE/src-test/org/gvsig/fmap/raster/grid/roi/TestRoiStatistics.java | ||
---|---|---|
1 |
package org.gvsig.fmap.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/extensions/extRasterTools-SE/src/org/gvsig/fmap/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.fmap.raster.grid.roi; |
|
21 |
|
|
22 |
import java.util.ArrayList; |
|
23 |
|
|
24 |
import org.gvsig.raster.grid.Grid; |
|
25 |
import org.gvsig.raster.grid.roi.ROI; |
|
26 |
|
|
27 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
28 |
|
|
29 |
/** |
|
30 |
* Clase que representa una regi?n de interes conformada por |
|
31 |
* elementos vectoriales. |
|
32 |
* |
|
33 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class VectorialROI extends ROI { |
|
37 |
|
|
38 |
private ArrayList geometries = null; // Array de geometr?as (IGeometry) que definen el ROI. |
|
39 |
|
|
40 |
public VectorialROI(Grid grid) { |
|
41 |
super(grid); |
|
42 |
geometries = new ArrayList(); |
|
43 |
} |
|
44 |
|
|
45 |
public boolean isInGrid(int x, int y) { |
|
46 |
boolean inRoi = false; |
|
47 |
if (x>=0 && x<getNX() && y >=0 && y<getNY()){ |
|
48 |
|
|
49 |
//Cooordendas pixel a coordenadas "reales". |
|
50 |
double mapX = this.getGridExtent().getMin().getX() + x*getCellSize(); |
|
51 |
double mapY = this.getGridExtent().getMax().getY() - y*getCellSize(); |
|
52 |
|
|
53 |
/*for (int i = 0; i < geometries.size(); i++) |
|
54 |
if (((IGeometry)geometries.get(i)).contains(mapX,mapY)){ //TODO:Ver como est? funcionando contains y si me vale. |
|
55 |
inRoi=true; |
|
56 |
break; |
|
57 |
}*/ |
|
58 |
} |
|
59 |
return inRoi; |
|
60 |
} |
|
61 |
|
|
62 |
public void addGeometry(IGeometry geometry){ |
|
63 |
geometries.add(geometry); |
|
64 |
|
|
65 |
double minX = Math.min(geometry.getBounds2D().getMinX(),getGridExtent().getMin().getX()); |
|
66 |
double minY = Math.min(geometry.getBounds2D().getMinY(),getGridExtent().getMin().getY()); |
|
67 |
double maxX = Math.max(geometry.getBounds2D().getMaxX(),getGridExtent().getMax().getX()); |
|
68 |
double maxY = Math.max(geometry.getBounds2D().getMaxY(),getGridExtent().getMax().getY()); |
|
69 |
|
|
70 |
getGridExtent().setXRange(minX, maxX); |
|
71 |
getGridExtent().setYRange(minY, maxY); |
|
72 |
|
|
73 |
xOffset = (int)((minX - getGrid().getGridExtent().getMin().getX())/getCellSize()); |
|
74 |
yOffset = (int)((getGrid().getGridExtent().getMax().getY()- maxY)/getCellSize()); |
|
75 |
} |
|
76 |
|
|
77 |
public void deleteGeometry(int index){ |
|
78 |
geometries.remove(index); |
|
79 |
//TODO: Reajustar el Extent. |
|
80 |
} |
|
81 |
} |
|
0 | 82 |
Also available in: Unified diff