Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src-test / org / gvsig / rastertools / memorydrivertest / TestMemoryDriverWizard.java @ 11174

History | View | Annotate | Download (5.92 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.rastertools.memorydrivertest;
42

    
43
import java.awt.Dimension;
44
import java.awt.FlowLayout;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47

    
48
import javax.swing.JButton;
49
import javax.swing.JLabel;
50

    
51
import org.cresques.cts.IProjection;
52
import org.gvsig.fmap.drivers.raster.RasterSEDriver;
53
import org.gvsig.fmap.layers.FLyrRasterSE;
54
import org.gvsig.fmap.layers.RasterSEAdapter;
55
import org.gvsig.fmap.layers.RasterSEFileAdapter;
56
import org.gvsig.raster.buffer.BufferFactory;
57
import org.gvsig.raster.dataset.IBuffer;
58
import org.gvsig.raster.dataset.NotSupportedExtensionException;
59
import org.gvsig.raster.dataset.RasterDataset;
60
import org.gvsig.raster.dataset.RasterDriverException;
61
import org.gvsig.raster.dataset.io.MemoryRasterDriverParam;
62

    
63
import com.hardcode.driverManager.Driver;
64
import com.hardcode.driverManager.DriverLoadException;
65
import com.hardcode.gdbms.engine.data.driver.DriverException;
66
import com.iver.andami.PluginServices;
67
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
68
import com.iver.cit.gvsig.fmap.MapContext;
69
import com.iver.cit.gvsig.fmap.layers.FLayer;
70
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
71
import com.iver.cit.gvsig.gui.WizardPanel;
72
import com.iver.cit.gvsig.project.documents.view.gui.View;
73

    
74

    
75
public class TestMemoryDriverWizard extends WizardPanel implements ActionListener {
76

    
77
        private JButton but = null;
78
        private String path = "/home/nacho/images/03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
79
        //private String path = "/home/nacho/images/wcs16bits.tif";
80
        //private String path = "/mnt/hdd/imagenes/bugRaster/Red_drenaje.asc";
81
        private RasterDataset f = null;
82
        private BufferFactory bf = null;
83
        private MapContext m_MapContext;
84
        
85
        public TestMemoryDriverWizard (){
86
                super();
87
                initialize() ;
88
        }
89
        /**
90
         * This method initializes this
91
         */
92
        private void initialize() {
93
                this.setTabName("Test Memory Driver");
94
                this.setLayout(new FlowLayout());
95
                JLabel label = new JLabel("En TestMemoryDriverWizard debe haber una ruta a una imagen.");
96
                but = new JButton("Test MemoryDriver");
97
                but.setPreferredSize(new Dimension(180,35));
98
                this.add(label, null);
99
                this.add(but, null);
100
                but.addActionListener(this);
101
        }
102

    
103
        public void execute() {
104

    
105
                
106
        }
107

    
108
        public FLayer getLayer() {
109
                return null;
110
        }
111

    
112
        public void initWizard() {
113
        
114
                
115
        }
116
        
117
        private IBuffer createBuffer(){
118
                try {
119
                        f = RasterDataset.open(null, path);
120
                } catch (NotSupportedExtensionException e) {
121
                        e.printStackTrace();
122
                        return null;
123
                } catch (RasterDriverException e) {
124
                        e.printStackTrace();
125
                        return null;
126
                }
127
                bf = new BufferFactory(f);
128
                int[] drawableBands = {0, 1, 2};
129
                int x = 150;//0;//406;//150;
130
                int y = 150;//0;//350;//150;
131
                int w = 100;//601;//100;
132
                int h = 100;//410;//100;
133
                
134
                bf.addDrawableBands(drawableBands);
135
                bf.setAreaOfInterest(x, y, w, h);        
136
                return bf.getRasterBuf();
137
        }
138
        
139
        public void actionPerformed(ActionEvent e) {
140
                //Carga de una capa con datos de memoria
141
                IBuffer raster = createBuffer();
142
                Driver driver = null;
143
                try {
144
                        driver = LayerFactory.getDM().getDriver("gvSIG Raster Driver");
145
                } catch (DriverLoadException e2) {
146
                        e2.printStackTrace();
147
                }
148
                View theView = (View) PluginServices.getMDIManager().getActiveWindow();
149
                this.m_MapContext = theView.getModel().getMapContext();
150
                FLyrRasterSE layer = null;
151
                try {
152
                        layer = createLayer("test-memoryDriver", (RasterSEDriver)driver,
153
                                        new MemoryRasterDriverParam(raster, bf.getDataExtent()),  m_MapContext.getProjection());
154
                        m_MapContext.getLayers().addLayer(layer);
155
                } catch (LoadLayerException e1) {
156
                        return;
157
                }
158
                
159
                //Acceso a datos de la capa de memoria
160
                /*if(layer != null){
161
                        Grid g = layer.getGrid();
162
                        int[] drawableBands = {0, 1, 2};
163
                        g.addDrawableBands(drawableBands);
164
                        g.setAreaOfInterest(0, 0, g.getWidth(), g.getHeight());        
165
                        RasterBuf b = g.getRasterBuf();
166
                        for(int i = 0; i < b.getWidth(); i++){
167
                                for(int j = 0; j < b.getHeight(); j++)
168
                                        System.out.print(b.getElemByte(j, i, 0) + " ");
169
                                System.out.println("");
170
                        }
171
                }*/
172
                
173
        }
174
        
175
        /**
176
         * Creates a new raster layer in memory. To create this layer type we have to set a data
177
         * buffer and a bounding box instead of a file.
178
         * @param layerName Layer name
179
         * @param d raster driver
180
         * @param buf data buffer
181
         * @param ext bounding box 
182
         * @param proj projection 
183
         * @return raster layer
184
         * @throws DriverException
185
         */
186
        public static FLyrRasterSE createLayer(String layerName, RasterSEDriver d,
187
                        Object param, IProjection proj)  throws LoadLayerException{
188
                RasterSEAdapter adapter = new RasterSEFileAdapter(null);
189
                adapter.setDriver(d);
190

    
191
                FLyrRasterSE capa = new FLyrRasterSE();
192
                capa.setName(layerName);
193
                
194
                capa.setSource(adapter);
195
                capa.setProjection(proj);
196
                capa.setLoadParams(param);
197
                capa.load();
198
        
199
                return capa;
200
        }
201

    
202
}  //  @jve:decl-index=0:visual-constraint="10,10"