svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src-test / org / gvsig / fmap / raster / grid / roi / TestVectorialROIsWriter.java @ 25770
History | View | Annotate | Download (3.25 KB)
1 |
package org.gvsig.fmap.raster.grid.roi; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import junit.framework.TestCase; |
6 |
|
7 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
8 |
import org.gvsig.raster.dataset.IBuffer; |
9 |
import org.gvsig.raster.grid.Grid; |
10 |
import org.gvsig.raster.grid.GridExtent; |
11 |
import org.gvsig.raster.grid.OutOfGridException; |
12 |
|
13 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
14 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
15 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
16 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
17 |
|
18 |
public class TestVectorialROIsWriter extends TestCase { |
19 |
|
20 |
Grid grid = null;
|
21 |
GridExtent extent = null;
|
22 |
int cellSize = 1; |
23 |
double xMin = 0; |
24 |
double xMax = 10; |
25 |
double yMin = 0; |
26 |
double yMax = 10; |
27 |
VectorialROI rois[] = null; |
28 |
GeneralPathX path = null;
|
29 |
IGeometry geometry = null;
|
30 |
|
31 |
public void setUp() { |
32 |
int bands[] = {0}; |
33 |
extent = new GridExtent();
|
34 |
extent.setCellSize(cellSize); |
35 |
extent.setXRange(xMin, xMax); |
36 |
extent.setYRange(yMin, yMax); |
37 |
rois = new VectorialROI[3]; |
38 |
try {
|
39 |
grid = new Grid(extent, extent, IBuffer.TYPE_DOUBLE, bands);
|
40 |
for (int x = 0; x<5; x++) |
41 |
for (int y = 0; y<5; y++){ |
42 |
grid.setCellValue(x, y, 0.0);
|
43 |
} |
44 |
for (int x = 5; x<xMax; x++) |
45 |
for (int y = 0; y<5; y++){ |
46 |
grid.setCellValue(x, y, 1.0);
|
47 |
} |
48 |
for (int x = 0; x<5; x++) |
49 |
for (int y = 5; y<10; y++){ |
50 |
grid.setCellValue(x, y, 2.0);
|
51 |
} |
52 |
for (int x = 5; x<10; x++) |
53 |
for (int y = 5; y<10; y++){ |
54 |
grid.setCellValue(x, y, 3.0);
|
55 |
} |
56 |
} catch (RasterBufferInvalidException e) {
|
57 |
// TODO Auto-generated catch block
|
58 |
e.printStackTrace(); |
59 |
} catch (OutOfGridException e) {
|
60 |
// TODO Auto-generated catch block
|
61 |
e.printStackTrace(); |
62 |
} |
63 |
|
64 |
} |
65 |
|
66 |
public void start() { |
67 |
this.setUp();
|
68 |
this.testStack();
|
69 |
} |
70 |
|
71 |
public void testStack() { |
72 |
|
73 |
|
74 |
path = new GeneralPathX();
|
75 |
|
76 |
path.moveTo(4,4); |
77 |
path.lineTo(4,0); |
78 |
path.lineTo(0,0); |
79 |
path.lineTo(0,4); |
80 |
path.closePath(); |
81 |
|
82 |
geometry=ShapeFactory.createPolygon2D(path); |
83 |
|
84 |
rois[0] = new VectorialROI(grid); |
85 |
rois[0].addGeometry(geometry);
|
86 |
rois[0].setColor(Color.RED); |
87 |
rois[0].setName("PoligonsROI"); |
88 |
|
89 |
path = new GeneralPathX();
|
90 |
|
91 |
path.moveTo(9,4); |
92 |
path.lineTo(9,2); |
93 |
path.lineTo(6,2); |
94 |
path.lineTo(6,4); |
95 |
path.closePath(); |
96 |
|
97 |
geometry=ShapeFactory.createPolygon2D(path); |
98 |
rois[0].addGeometry(geometry);
|
99 |
|
100 |
//ROI tipo linea:
|
101 |
path = new GeneralPathX();
|
102 |
|
103 |
path.moveTo(14,14); |
104 |
path.lineTo(14,10); |
105 |
path.lineTo(10,10); |
106 |
path.lineTo(10,14); |
107 |
|
108 |
geometry=ShapeFactory.createPolyline2D(path); |
109 |
|
110 |
rois[1] = new VectorialROI(grid); |
111 |
rois[1].addGeometry(geometry);
|
112 |
rois[1].setColor(Color.GREEN); |
113 |
rois[1].setName("LinesROI"); |
114 |
|
115 |
path = new GeneralPathX();
|
116 |
|
117 |
path.moveTo(24,24); |
118 |
path.lineTo(24,20); |
119 |
path.lineTo(20,20); |
120 |
path.lineTo(20,24); |
121 |
|
122 |
geometry=ShapeFactory.createPolyline2D(path); |
123 |
|
124 |
rois[1].addGeometry(geometry);
|
125 |
|
126 |
//ROI tipo puntos:
|
127 |
geometry=ShapeFactory.createPoint2D(30, 30); |
128 |
|
129 |
rois[2] = new VectorialROI(grid); |
130 |
rois[2].addGeometry(geometry);
|
131 |
rois[2].setColor(Color.BLUE); |
132 |
rois[2].setName("PointsROI"); |
133 |
|
134 |
geometry=ShapeFactory.createPoint2D(35, 35); |
135 |
|
136 |
rois[2].addGeometry(geometry);
|
137 |
|
138 |
VectorialROIsWriter roisWriter = new VectorialROIsWriter("./test-images/rois",CRSFactory.getCRS("EPSG:23030")); |
139 |
roisWriter.write(rois); |
140 |
} |
141 |
|
142 |
} |