Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_894 / extensions / extGeoreferencing / src / org / gvsig / georeferencing / utils / GeoLayerFactory.java @ 10309

History | View | Annotate | Download (6.97 KB)

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
package org.gvsig.georeferencing.utils;
20

    
21
import java.awt.geom.Point2D;
22
import java.io.File;
23

    
24
import org.cresques.cts.IProjection;
25
import org.gvsig.georeferencing.GeoreferencingToolsModule;
26
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog;
27

    
28
import com.iver.andami.PluginServices;
29
import com.iver.cit.gvsig.fmap.DriverException;
30
import com.iver.cit.gvsig.fmap.ViewPort;
31
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
32
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
33
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
34
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
35
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
36
import com.iver.cit.gvsig.fmap.layers.RasterAdapter;
37
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter;
38
import com.iver.cit.gvsig.project.documents.view.gui.View;
39

    
40

    
41
/**
42
 * Clase para la creaci?n de capas de georreferenciaci?n y capas de puntos
43
 *
44
 * @author Nacho Brodin (brodin_ign@gva.es)
45
 */
46
public class GeoLayerFactory{
47
        
48
        //**********************Params********************************
49
        
50
        //**********************End Params****************************
51
        
52
        //**********************Vars**********************************
53
        
54
        //**********************End Vars**********************************
55
        
56
        //**********************Classes***********************************
57
        
58
        //**********************End Classes*******************************
59

    
60
        //**********************Methods***********************************
61
        
62
        
63
        /**
64
         * Crea una capa FLyrPoints a partir de los par?metros de entrada.
65
         * @param lyGeoRaster        Capa a georreferenciar
66
         * @param pixel                        Coordenadas relativas a la imagen a georreferenciar en pixels
67
         * @param map                        Coordenadas de destino
68
         * @param active                True o false si el punto est? activo o no
69
         * @param leftCenter        Punto central del viewport de la miniimagen de coordenadas reales
70
         * @param rightCenter        Punto central del viewport de la miniimagen de coordenadas en pixels
71
         * @param leftViewPort        ViewPort de la miniimagen de coordenadas reales
72
         * @param rightViewPort        ViewPort de la miniimagen de coordenadas en pixels
73
         * @return Capa de puntos creada.
74
         */
75
        public static FLyrPoints createFLyrPoints(        FLyrGeoRaster lyGeoRaster, 
76
                                                                                                Point2D[] pixel, 
77
                                                                                                Point2D[] map, 
78
                                                                                                boolean[] active,
79
                                                                                                Point2D[] leftCenter, 
80
                                                                                                Point2D[] rightCenter,
81
                                                                                                ViewPort[] leftViewPort,
82
                                                                                                ViewPort[] rightViewPort){
83
                GeoPointPersistence        geoPointPersistence = new GeoPointPersistence();
84
                FLyrPoints lyrPoints = new FLyrPoints(lyGeoRaster, geoPointPersistence);
85
                geoPointPersistence.setLyrPoints(lyrPoints);
86
                
87
                lyrPoints.getPointManager().newEmptyPoint();
88
                GeoreferencingToolsModule.setEnabled(true);
89
                View theView = null;
90
                try{
91
                        theView = (View)PluginServices.getMDIManager().getActiveWindow();
92
                }catch(ClassCastException exc){
93
                        return null;
94
                }
95
                int pos = lyrPoints.getCountPoints() -1;
96
                for(int i = 0;i < pixel.length;i++){
97
                        lyrPoints.setPointActive(pos, active[i]);
98
                        lyrPoints.setLeftCenterPoint(pos,leftCenter[i]);
99
                        lyrPoints.setRightCenterPoint(pos, rightCenter[i]);
100
                        lyrPoints.setLeftViewPort(pos, leftViewPort[i]);
101
                        lyrPoints.setRightViewPort(pos, rightViewPort[i]);
102
                        lyrPoints.getPointManager().updateData(pos + 1, pixel[i], map[i], lyrPoints.getPointManager().getDialog(), theView);
103
                }
104
                
105
                if(lyrPoints.getCountPoints() > 0){
106
                        GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog();
107
                        grd.getConectorPanel().getDataPointsTabPanel().
108
                                getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
109
                        grd.getConectorPanel().getDataPointsTabPanel().
110
                                getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints());
111
                        lyrPoints.getPointManager().selectPoint(0, grd);
112
                }
113
                
114
                return lyrPoints;
115
        }
116

    
117
        /**
118
         * Crea una capa Raster de georreferenciaci?n a partir del nombre driver, fichero y proyecci?n y 
119
         * coordenadas de georeferenciaci?n. Esta funci?n es para georeferenciar 
120
         * capas raster. Para imagenes que no tienen georeferenciaci?n hay que asignarle
121
         * una temporal, normalmente a partir de la vista activa.
122
         *
123
         * @param layerName Nombre de la capa.
124
         * @param d RasterDriver.
125
         * @param f Fichero.
126
         * @param proj Proyecci?n.
127
         * @param widthPxImg Ancho en pixeles de la imagen
128
         * @param heightPxImg Alto en pixeles de la imagen
129
         *
130
         * @return Nueva capa de tipo raster.
131
         *
132
         * @throws DriverIOException
133
         */
134
        public static FLyrGeoRaster createLayer(String layerName, RasterDriver d,
135
                File f, IProjection proj, double widthPxImg, double heightPxImg) throws DriverException {
136
                RasterAdapter adapter = new RasterFileAdapter(f);
137
                adapter.setDriver(d);
138
                GeoPointPersistence        geoPointPersistence = new GeoPointPersistence();
139
                StackZoom zoom = new StackZoom();
140
                FLyrGeoRaster lyrGeoRaster = new FLyrGeoRaster(geoPointPersistence, zoom);
141
                geoPointPersistence.setLyrPoints(lyrGeoRaster.getFLyrPoints());
142
                
143
                if (lyrGeoRaster != null) {
144
                        lyrGeoRaster.setName(layerName);
145
                        lyrGeoRaster.setSource(adapter);
146
                        lyrGeoRaster.setProjection(proj);
147
                        lyrGeoRaster.setImageDimension(widthPxImg, heightPxImg);
148
                        try {
149
                                lyrGeoRaster.load();
150
                        } catch (DriverIOException e) {
151
                                throw new DriverException(e);
152
                        }
153
                
154
                        lyrGeoRaster.setVisible(true);
155
                }else 
156
                        return null;
157
                return lyrGeoRaster;
158
        }
159
        
160
        /**
161
         * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n.
162
         *
163
         * @param layerName Nombre de la capa.
164
         * @param d RasterDriver.
165
         * @param f Fichero.
166
         * @param proj Proyecci?n.
167
         *
168
         * @return Nueva capa de tipo raster.
169
         *
170
         * @throws DriverIOException
171
         */
172
        public static FLyrRaster createLayer(String layerName, RasterDriver d,
173
                File f, IProjection proj) throws DriverException {
174
                RasterAdapter adapter = new RasterFileAdapter(f);
175
                adapter.setDriver(d);
176

    
177
                FLyrRaster capa = new FLyrRaster();
178
                capa.setName(layerName);
179

    
180
                capa.setSource(adapter);
181
                capa.setProjection(proj);
182
                try {
183
                        capa.load();
184
                } catch (DriverIOException e) {
185
                        throw new DriverException(e);
186
                }
187
                
188
                return capa;
189
        }
190
        //**********************End Methods********************************
191
        
192
        //**********************Setters & Getters**************************
193
        
194
        //**********************End Setters & Getters*********************
195
}