gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.app / org.gvsig.raster.georeferencing.app.georeferencingclient / src / main / java / org / gvsig / raster / georeferencing / app / georeferencingclient / GeoreferencingProcessActions.java @ 1740
History | View | Annotate | Download (7.23 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.raster.georeferencing.app.georeferencingclient; |
20 |
|
21 |
import java.awt.geom.AffineTransform; |
22 |
import java.io.File; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
25 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
26 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
27 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
28 |
import org.gvsig.i18n.Messages; |
29 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
30 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
31 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewMapRequestManager; |
32 |
import org.gvsig.raster.georeferencing.lib.impl.GeoTransformDataResult; |
33 |
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException; |
34 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
35 |
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary; |
36 |
import org.gvsig.raster.tools.algorithm.base.process.IProcessActions; |
37 |
import org.gvsig.raster.tools.algorithm.base.process.ProcessException; |
38 |
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess; |
39 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
40 |
|
41 |
/**
|
42 |
* Gestor para operaciones con las vistas y zooms
|
43 |
*
|
44 |
* 04/02/2008
|
45 |
* @author Nacho Brodin nachobrodin@gmail.com
|
46 |
*/
|
47 |
public class GeoreferencingProcessActions implements IProcessActions { |
48 |
private ViewMapRequestManager viewMapRequestManager = null; |
49 |
private String fileName = null; |
50 |
|
51 |
//?ltima capa procesada con los puntos de control. Al cerrar la aplicaci?n
|
52 |
//esta ser? la que se use como resultado
|
53 |
private FLyrRaster lastTestLyr = null; |
54 |
|
55 |
public void setViewMapRequest(ViewMapRequestManager vMap) { |
56 |
viewMapRequestManager = vMap; |
57 |
} |
58 |
|
59 |
/**
|
60 |
* Asigna el panel con la tabla
|
61 |
* @param tablePanel
|
62 |
*/
|
63 |
/*public void setGeoPointList(GeoPointList gpList) {
|
64 |
this.gpList = gpList;
|
65 |
}*/
|
66 |
|
67 |
/**
|
68 |
* A?ade una capa en la vista del mapa para previsualizar el resultado
|
69 |
* @param lyr
|
70 |
* @param algorithm Algoritmo con el que se realiza la transformaci?n
|
71 |
* @throws LoadLayerException
|
72 |
*/
|
73 |
public void addTestRasterLayer( RasterDataStore store, |
74 |
int algorithm,
|
75 |
int method,
|
76 |
int order,
|
77 |
String file,
|
78 |
double cellsizeX,
|
79 |
double cellsizeY,
|
80 |
GeoTransformDataResult result) throws LoadLayerException {
|
81 |
if(!testNumberOfPoints(order, result.getGpcs()))
|
82 |
return;
|
83 |
|
84 |
fileName = file; |
85 |
RasterDataStore storeClon = null;
|
86 |
try {
|
87 |
storeClon = store.cloneDataStore(); |
88 |
} catch (Exception e1) { |
89 |
RasterToolsUtil.messageBoxError("error_clone_layer", this, e1); |
90 |
return;
|
91 |
} |
92 |
|
93 |
if(algorithm == Georeferencing.AFFINE) {
|
94 |
if(result == null) { |
95 |
RasterToolsUtil.messageBoxInfo("error_georef", this); |
96 |
return;
|
97 |
} |
98 |
|
99 |
AffineTransform at = new AffineTransform( |
100 |
result.getPixelToMapCoefX()[1],
|
101 |
result.getPixelToMapCoefY()[1],
|
102 |
result.getPixelToMapCoefX()[2],
|
103 |
result.getPixelToMapCoefY()[2],
|
104 |
result.getPixelToMapCoefX()[0],
|
105 |
result.getPixelToMapCoefY()[0]);
|
106 |
storeClon.setAffineTransform(at); |
107 |
|
108 |
} |
109 |
|
110 |
DefaultFLyrRaster lyr = new DefaultFLyrRaster();
|
111 |
lyr.setDataStore(storeClon); |
112 |
lastTestLyr = lyr; |
113 |
|
114 |
if(algorithm == Georeferencing.POLYNOMIAL) {
|
115 |
RasterProcess process; |
116 |
try {
|
117 |
process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("GeoreferencingProcess");
|
118 |
process.addParam("RasterStore", lyr.getDataStore());
|
119 |
process.addParam("FileName", file);
|
120 |
process.addParam("Interpolation", new Integer(method)); |
121 |
process.addParam("gcps", result.getGpcs());
|
122 |
process.addParam("Order", new Integer(order)); |
123 |
process.addParam("xCellSize", new Double(cellsizeX)); |
124 |
process.addParam("yCellSize", new Double(cellsizeY)); |
125 |
process.setActions(this);
|
126 |
process.start(); |
127 |
} catch (ProcessException e) {
|
128 |
GeoreferencingSwingImplLibrary.messageBoxError("error_georef_process", null, e); |
129 |
} |
130 |
} |
131 |
|
132 |
//Con vista de de referencia cargamos la preview en esta
|
133 |
if(viewMapRequestManager != null) { |
134 |
if(algorithm == Georeferencing.AFFINE) {
|
135 |
try {
|
136 |
viewMapRequestManager.addTestRasterLayer(lyr); |
137 |
} catch (InvalidRequestException e) {
|
138 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e); |
139 |
} |
140 |
} |
141 |
} |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Consulta si hay suficientes puntos de control en la lista para los calculos
|
146 |
* @param order Orden del polinomio a utilizar
|
147 |
* @return true si hay suficientes puntos de control y false si no los hay
|
148 |
*/
|
149 |
private boolean testNumberOfPoints(int order, GeoPointList gpList) { |
150 |
if (gpList != null) { |
151 |
if(gpList.size() <= 0) { |
152 |
GeoreferencingSwingImplLibrary.messageBoxError("no_selected_points", null); |
153 |
return false; |
154 |
} |
155 |
|
156 |
// Obtenemos el n?mero de puntos activos
|
157 |
int nPointsActive = 0; |
158 |
for (int i = 0; i < gpList.size(); i++) { |
159 |
if (gpList.get(i).isActive())
|
160 |
nPointsActive++; |
161 |
} |
162 |
int nPoints = (order + 1) * (order + 2) / 2; |
163 |
if (nPointsActive < nPoints) {
|
164 |
GeoreferencingSwingImplLibrary.messageBoxError(Messages.getText("more_points") + ((int) Math.ceil(nPoints)), null); |
165 |
return false; |
166 |
} |
167 |
} |
168 |
return true; |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Elimina la capa de test de la vista de mapa
|
173 |
* @throws InvalidRequestException
|
174 |
*/
|
175 |
public void removeTestRasterLayer() { |
176 |
if(viewMapRequestManager != null) { |
177 |
try {
|
178 |
viewMapRequestManager.removeTestRasterLayer(); |
179 |
} catch (InvalidRequestException e) {
|
180 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null); |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Cuando termina el proceso de georreferenciaci?n carga la capa en la
|
187 |
* vista con cartograf?a de referencia si esta existe.
|
188 |
*/
|
189 |
public void end(Object param) { |
190 |
if(viewMapRequestManager != null) { |
191 |
try {
|
192 |
String f = RasterLocator.getManager().getFileUtils().getLastPart(fileName, File.separator); |
193 |
FLyrRaster lyr = DefaultFLyrRaster.createLayer(f, new File(fileName)); |
194 |
viewMapRequestManager.addTestRasterLayer(lyr); |
195 |
lastTestLyr = lyr; |
196 |
} catch (InvalidRequestException e) {
|
197 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e); |
198 |
} catch (LoadLayerException e) {
|
199 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e); |
200 |
} |
201 |
} |
202 |
} |
203 |
|
204 |
public void interrupted() { |
205 |
} |
206 |
|
207 |
/**
|
208 |
* Obtiene la ?ltima capa procesada con los puntos de control
|
209 |
* @return FLyrRaterSE
|
210 |
*/
|
211 |
public FLyrRaster getLastTestLayer() {
|
212 |
return lastTestLyr;
|
213 |
} |
214 |
|
215 |
} |