Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src-test / org / gvsig / fmap / raster / grid / roi / TestVectorialROIsReader.java @ 25986

History | View | Annotate | Download (3.04 KB)

1
package org.gvsig.fmap.raster.grid.roi;
2

    
3
import java.io.File;
4
import java.util.ArrayList;
5

    
6
import junit.framework.TestCase;
7

    
8
import org.gvsig.raster.buffer.RasterBufferInvalidException;
9
import org.gvsig.raster.dataset.FileNotExistsException;
10
import org.gvsig.raster.dataset.IBuffer;
11
import org.gvsig.raster.grid.Grid;
12
import org.gvsig.raster.grid.GridExtent;
13
import org.gvsig.raster.grid.OutOfGridException;
14

    
15
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
16
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
17
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
18
import com.iver.cit.gvsig.fmap.core.IGeometry;
19
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
20
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
21

    
22
public class TestVectorialROIsReader extends TestCase {
23
        
24
        Grid grid = null;
25
        GridExtent extent = null;
26
        int cellSize = 1;
27
        double xMin = 0;
28
        double xMax = 10;
29
        double yMin = 0;
30
        double yMax = 10;
31
        ArrayList rois = null;
32
        GeneralPathX path = null;
33
        IGeometry geometry = null;
34
        
35
        public static final String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers";
36
        private static File baseDriversPath;
37
        
38
        public void setUp() {
39
                int bands[] = {0};
40
                extent = new GridExtent();
41
                extent.setCellSize(cellSize);
42
                extent.setXRange(xMin, xMax);
43
                extent.setYRange(yMin, yMax);
44
                try {
45
                        grid = new Grid(extent, extent, IBuffer.TYPE_DOUBLE, bands);
46
                        for (int x = 0; x<5; x++)
47
                                for (int y = 0; y<5; y++){
48
                                        grid.setCellValue(x, y, 0.0);
49
                                }
50
                        for (int x = 5; x<xMax; x++)
51
                                for (int y = 0; y<5; y++){
52
                                        grid.setCellValue(x, y, 1.0);
53
                                }
54
                        for (int x = 0; x<5; x++)
55
                                for (int y = 5; y<10; y++){
56
                                        grid.setCellValue(x, y, 2.0);
57
                                }
58
                        for (int x = 5; x<10; x++)
59
                                for (int y = 5; y<10; y++){
60
                                        grid.setCellValue(x, y, 3.0);
61
                                }
62
                } catch (RasterBufferInvalidException e) {
63
                        // TODO Auto-generated catch block
64
                        e.printStackTrace();
65
                } catch (OutOfGridException e) {
66
                        // TODO Auto-generated catch block
67
                        e.printStackTrace();
68
                }
69
                
70
                setUpDrivers();
71
        }
72

    
73
        public static void setUpDrivers() {
74
                try {
75
                        baseDriversPath = new File(fwAndamiDriverPath);
76
                        if (!baseDriversPath.exists())
77
                                throw new Exception("Can't find drivers path: " + fwAndamiDriverPath);
78

    
79
                        LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath());
80
                        if (LayerFactory.getDM().getDriverNames().length < 1)
81
                                throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath);
82
                } catch (Exception e) {
83
                        throw new RuntimeException(e);
84
                }
85
        }
86
        
87
        public void start() {
88
                this.setUp();
89
                this.testStack();
90
        }
91

    
92
        public void testStack() {
93
                String path = "./test-images/rois_polygons.shp";
94
                try {
95
                        VectorialROIsReader reader = new VectorialROIsReader(path, grid, CRSFactory.getCRS("EPSG:23030"));
96
                        rois = reader.read(null);
97
                } catch (LoadLayerException e) {
98
                        // TODO Auto-generated catch block
99
                        e.printStackTrace();
100
                } catch (ReadDriverException e) {
101
                        // TODO Auto-generated catch block
102
                        e.printStackTrace();
103
                } catch (FileNotExistsException e) {
104
                        // TODO Auto-generated catch block
105
                        e.printStackTrace();
106
                }
107
                
108
        }
109

    
110
}