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 / Georeferencing.java @ 1725
History | View | Annotate | Download (16.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.georeferencing.app.georeferencingclient; |
23 |
|
24 |
import java.awt.geom.Rectangle2D; |
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
27 |
|
28 |
import javax.swing.JPanel; |
29 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
32 |
import org.gvsig.app.ApplicationLocator; |
33 |
import org.gvsig.app.ApplicationManager; |
34 |
import org.gvsig.app.project.documents.Document; |
35 |
import org.gvsig.app.project.documents.view.ViewDocument; |
36 |
import org.gvsig.app.project.documents.view.gui.IView; |
37 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
38 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
39 |
import org.gvsig.fmap.geom.primitive.Envelope; |
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
41 |
import org.gvsig.i18n.Messages; |
42 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ApplicationControlsListener; |
43 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.LauncherDialogListener; |
44 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewDialogListener; |
45 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewMapRequestManager; |
46 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewRasterRequestManager; |
47 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkLocator; |
48 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkManager; |
49 |
import org.gvsig.raster.georeferencing.framework.LayoutEnvironment; |
50 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingLauncher; |
51 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingOptionsDataModel; |
52 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary; |
53 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLocator; |
54 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingManager; |
55 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel; |
56 |
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException; |
57 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
58 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GPGraphic; |
59 |
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView; |
60 |
import org.gvsig.raster.georeferencing.swing.view.IViewRequestManager; |
61 |
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews; |
62 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
63 |
|
64 |
/**
|
65 |
* Clase principal para la georreferenciaci?n. Se encarga de la inicializaci?n
|
66 |
* de la funcionalidad. Las acciones a realizar son:
|
67 |
* <UL>
|
68 |
* <LI>Lanzamiento del dialogo de inicializaci?n.</LI>
|
69 |
* <LI>Carga de la capa raster a georreferenciar.</LI>
|
70 |
* <LI>Creaci?n de las ventanas si no han sido creadas previamente.</LI>
|
71 |
* <LI>Asignaci?n de tama?os y posiciones a las ventanas.</LI>
|
72 |
* </UL>
|
73 |
* 26/12/2007
|
74 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
75 |
*/
|
76 |
public class Georeferencing { |
77 |
public static final int UNDEFINED = -1; |
78 |
//Algoritmo
|
79 |
public static final int POLYNOMIAL = 0; |
80 |
public static final int AFFINE = 1; |
81 |
|
82 |
//Tipo de georreferenciacion
|
83 |
public static final int WITH_MAP = 0; |
84 |
public static final int WITHOUT_MAP = 1; |
85 |
|
86 |
public static int DEFAULT_DEGREE = 3; |
87 |
public static int ZOOM_RATIO = 5; |
88 |
|
89 |
private GeoreferencingFrameworkManager
|
90 |
fManager = null;
|
91 |
private GeoreferencingSwingManager sManager = null; |
92 |
|
93 |
//Dialogos
|
94 |
private GeoreferencingLauncher launcher = null; |
95 |
private GeoreferencingView viewRaster = null; |
96 |
private GeoreferencingView viewMap = null; |
97 |
private GeoreferencingView zoomMap = null; |
98 |
private GeoreferencingView zoomRaster = null; |
99 |
|
100 |
private ViewRasterRequestManager zoomRasterRequestManager = null; |
101 |
private ViewMapRequestManager zoomMapRequestManager = null; |
102 |
private ViewRasterRequestManager viewRasterRequestManager = null; |
103 |
private ViewMapRequestManager viewMapRequestManager = null; |
104 |
|
105 |
private GeorefControlPanel georefControlPanel = null; |
106 |
|
107 |
private TableWrapper table = null; |
108 |
|
109 |
private MapControl mapCtrl = null; |
110 |
private GeoreferencingOptionsDataModel
|
111 |
dataModel = null;
|
112 |
private SynchronizedViews syncViews = null; |
113 |
private ViewDialogListener listener = null; |
114 |
private GeoreferencingProcessActions processActions = null; |
115 |
private ApplicationControlsListener appControlsListener = null; |
116 |
public static boolean enableTableEvent = true; |
117 |
|
118 |
public void initialize() { |
119 |
fManager = GeoreferencingFrameworkLocator.getManager(); |
120 |
sManager = GeoreferencingSwingLocator.getSwingManager(); |
121 |
listener = new ViewDialogListener(this); |
122 |
processActions = new GeoreferencingProcessActions();
|
123 |
launcher(); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Launcher of the initial dialog
|
128 |
*/
|
129 |
private void launcher() { |
130 |
ApplicationManager application = ApplicationLocator.getManager(); |
131 |
List<Document> docs = application.getProjectManager().getCurrentProject().getDocuments(); |
132 |
List<String> viewList = new ArrayList<String>(); |
133 |
for (int i = 0; i < docs.size(); i++) { |
134 |
Document doc = docs.get(i);
|
135 |
if(doc instanceof ViewDocument) { |
136 |
viewList.add(doc.getName()); |
137 |
} |
138 |
} |
139 |
|
140 |
|
141 |
launcher = sManager.createWindowLauncher(viewList, DEFAULT_DEGREE); |
142 |
LauncherDialogListener listener = new LauncherDialogListener(this, launcher); |
143 |
launcher.setButtonsListener(listener); |
144 |
fManager.showWindow(launcher.getComponent(), 400, 420, Messages.getText("georeferencing")); |
145 |
} |
146 |
|
147 |
public MapControl getMapCtrl() {
|
148 |
if(mapCtrl == null) { |
149 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
150 |
for (int i = 0; i < windowList.length; i++) { |
151 |
if(windowList[i] instanceof IView) { |
152 |
String name = ((IView)windowList[i]).getViewDocument().getName();
|
153 |
if(name.equals(dataModel.getSelectedView())) {
|
154 |
mapCtrl = ((IView)windowList[i]).getMapControl(); |
155 |
} |
156 |
} |
157 |
} |
158 |
} |
159 |
return mapCtrl;
|
160 |
} |
161 |
|
162 |
public void endLauncherDialog(GeoreferencingOptionsDataModel dataModel) { |
163 |
this.dataModel = dataModel;
|
164 |
if(dataModel.getType() == Georeferencing.WITH_MAP)
|
165 |
initWindowsWithMap(dataModel); |
166 |
if(dataModel.getType() == Georeferencing.WITHOUT_MAP)
|
167 |
initWindowsWithoutMap(dataModel); |
168 |
createAppControlsListener(); |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Builds the raster view
|
173 |
* @return
|
174 |
*/
|
175 |
public GeoreferencingView getViewRaster() {
|
176 |
if(viewRaster == null) { |
177 |
viewRaster = sManager.createView(true, false, true, listener); |
178 |
viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, dataModel.getDataStore());
|
179 |
viewRaster.setMinxMaxyUL(false);
|
180 |
viewRaster.setViewListener(listener); |
181 |
viewRaster.setRequestListener(viewRasterRequestManager); |
182 |
viewRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
183 |
} |
184 |
return viewRaster;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Builds the map view
|
189 |
* @return
|
190 |
*/
|
191 |
public GeoreferencingView getViewMap() {
|
192 |
if(viewMap == null) { |
193 |
viewMap = sManager.createView(true, false, false, listener); |
194 |
viewMap.setMinxMaxyUL(true);
|
195 |
viewMapRequestManager = new ViewMapRequestManager(viewMap, getMapCtrl());
|
196 |
viewMap.setViewListener(listener); |
197 |
viewMap.setRequestListener(viewMapRequestManager); |
198 |
viewMap.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
199 |
} |
200 |
return viewMap;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* Builds the zoom for the map view
|
205 |
* @return
|
206 |
*/
|
207 |
public GeoreferencingView getZoomMap() {
|
208 |
if(zoomMap == null) { |
209 |
zoomMap = sManager.createZoom(true, false); |
210 |
zoomMap.setMinxMaxyUL(true);
|
211 |
zoomMapRequestManager = new ViewMapRequestManager(zoomMap, getMapCtrl());
|
212 |
zoomMap.setRequestListener(zoomMapRequestManager); |
213 |
zoomMap.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
214 |
} |
215 |
return zoomMap;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* Builds the zoom for the raster view
|
220 |
* @return
|
221 |
*/
|
222 |
public GeoreferencingView getZoomRaster() {
|
223 |
if(zoomRaster == null) { |
224 |
zoomRaster = sManager.createZoom(true, false); |
225 |
zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, dataModel.getDataStore());
|
226 |
zoomRaster.setMinxMaxyUL(false);
|
227 |
zoomRaster.setRequestListener(zoomRasterRequestManager); |
228 |
zoomRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
229 |
} |
230 |
return zoomRaster;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
235 |
* de ventanas con cartograf?a de referencia.
|
236 |
*/
|
237 |
private void initWindowsWithoutMap(GeoreferencingOptionsDataModel dataModel) { |
238 |
//RasterDataStore store = dataModel.getDataStore();
|
239 |
|
240 |
getDataModel().setType(WITHOUT_MAP); |
241 |
|
242 |
viewRaster = getViewRaster(); |
243 |
zoomRaster = getZoomRaster(); |
244 |
|
245 |
PagedTable pt = getTableWrapper().getTable(); |
246 |
|
247 |
//Creamos el layout
|
248 |
LayoutEnvironment layoutEnv = fManager.createLayoutEnvironment(); |
249 |
layoutEnv.setTable((JPanel)pt.getComponent());
|
250 |
layoutEnv.setViewRasterToGeoref(viewRaster.getComponent()); |
251 |
layoutEnv.setViewZoomRasterToGeoref(zoomRaster.getComponent()); |
252 |
layoutEnv.setControlBar(getGeorefControlPanel().getComponent()); |
253 |
|
254 |
fManager.createLayout(layoutEnv); |
255 |
GeoreferencingView[] v = new GeoreferencingView[]{null, viewRaster, null, zoomRaster}; |
256 |
IViewRequestManager[] rm = new IViewRequestManager[]{null, viewRasterRequestManager, null, zoomRasterRequestManager}; |
257 |
syncViews = sManager.createSyncViews(v, rm, pt, listener); |
258 |
|
259 |
try {
|
260 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
261 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
262 |
|
263 |
//Inicializamos la vista de raster
|
264 |
viewRasterRequestManager.initRequest(dataModel.getRasterExtent()); |
265 |
|
266 |
//Inicializamos el zoom de raster
|
267 |
Rectangle2D ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
|
268 |
zoomRasterRequestManager.initRequest(dataModel.getRasterExtent()); |
269 |
zoomRasterRequestManager.request(ext); |
270 |
|
271 |
} catch (InvalidRequestException e1) {
|
272 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
273 |
fManager.closeAllWindows(); |
274 |
}catch (Exception e1) { |
275 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
276 |
fManager.closeAllWindows(); |
277 |
} |
278 |
|
279 |
buildNewPointList(); |
280 |
} |
281 |
|
282 |
public TableWrapper getTableWrapper() {
|
283 |
if(table == null) { |
284 |
table = new TableWrapper(
|
285 |
getDataModel(), |
286 |
getGeorefControlPanel()); |
287 |
} |
288 |
return table;
|
289 |
} |
290 |
|
291 |
public void createAppControlsListener() { |
292 |
if(appControlsListener == null) { |
293 |
appControlsListener = new ApplicationControlsListener(getTableWrapper(), this); |
294 |
getTableWrapper().getTable().addListener(appControlsListener); |
295 |
} |
296 |
} |
297 |
|
298 |
public void buildNewPointList() { |
299 |
GeoPointList geoPointList = getDataModel().getDataStore().getGeoPointList(); |
300 |
long id = System.currentTimeMillis(); |
301 |
|
302 |
for (int i = 0; i < geoPointList.size(); i++) { |
303 |
GeoPoint gp = geoPointList.get(i); |
304 |
gp.setNumber(i); |
305 |
|
306 |
GPGraphic graphicGCP = new GPGraphic(gp);
|
307 |
graphicGCP.setId(id); |
308 |
getDataModel().getGCPList().add(graphicGCP); |
309 |
|
310 |
getTableWrapper().getTable().addRow(new Object[] { |
311 |
true,
|
312 |
gp.getNumber(), |
313 |
gp.getMapPoint().getX(), |
314 |
gp.getMapPoint().getY(), |
315 |
gp.getPixelPoint().getX(), |
316 |
gp.getPixelPoint().getY(), |
317 |
gp.getErrorX(), |
318 |
gp.getErrorY(), |
319 |
gp.getRms(), |
320 |
id}); |
321 |
|
322 |
id += 1;
|
323 |
} |
324 |
|
325 |
getSyncViews().redrawPoints(); |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
330 |
* de ventanas con cartograf?a de referencia.
|
331 |
*/
|
332 |
private void initWindowsWithMap(GeoreferencingOptionsDataModel dataModel) { |
333 |
getDataModel().setType(WITH_MAP); |
334 |
|
335 |
viewRaster = getViewRaster(); |
336 |
zoomRaster = getZoomRaster(); |
337 |
viewMap = getViewMap(); |
338 |
zoomMap = getZoomMap(); |
339 |
|
340 |
PagedTable pt = getTableWrapper().getTable(); |
341 |
|
342 |
//Creamos el layout
|
343 |
LayoutEnvironment layoutEnv = fManager.createLayoutEnvironment(); |
344 |
layoutEnv.setTable((JPanel)pt.getComponent());
|
345 |
layoutEnv.setViewRasterToGeoref(viewRaster.getComponent()); |
346 |
layoutEnv.setViewZoomRasterToGeoref(zoomRaster.getComponent()); |
347 |
layoutEnv.setViewBaseCartography(viewMap.getComponent()); |
348 |
layoutEnv.setViewZoomBaseCartography(zoomMap.getComponent()); |
349 |
layoutEnv.setControlBar(getGeorefControlPanel().getComponent()); |
350 |
|
351 |
fManager.createLayout(layoutEnv); |
352 |
GeoreferencingView[] v = new GeoreferencingView[]{viewMap, viewRaster, zoomMap, zoomRaster}; |
353 |
IViewRequestManager[] rm = new IViewRequestManager[]{viewMapRequestManager, viewRasterRequestManager, zoomMapRequestManager, zoomRasterRequestManager}; |
354 |
syncViews = sManager.createSyncViews(v, rm, pt, listener); |
355 |
|
356 |
getDataModel().setType(WITH_MAP); |
357 |
|
358 |
try {
|
359 |
viewMap.setCursorSize(zoomMap.getCanvasWidth() / ZOOM_RATIO, zoomMap.getCanvasHeight() / ZOOM_RATIO); |
360 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
361 |
viewMap.setCursorPosition(viewMap.getCanvasWidth() / 2, viewMap.getCanvasHeight() / 2); |
362 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
363 |
|
364 |
if(getMapCtrl().getMapContext().getLayers().getFullEnvelope() == null) |
365 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null); |
366 |
|
367 |
//Inicializamos la vista de mapa
|
368 |
Envelope e = getMapCtrl().getMapContext().getLayers().getFullEnvelope(); |
369 |
Rectangle2D r = new Rectangle2D.Double(e.getMinimum(0), e.getMinimum(1), e.getLength(0), e.getLength(1)); |
370 |
viewMapRequestManager.initRequest(r); |
371 |
|
372 |
//Inicializamos la vista de raster
|
373 |
viewRasterRequestManager.initRequest(dataModel.getRasterExtent()); |
374 |
|
375 |
//Inicializamos el zoom de mapa
|
376 |
Rectangle2D ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
|
377 |
zoomMapRequestManager.initRequest(ext); |
378 |
|
379 |
//Inicializamos el zoom de raster
|
380 |
ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight()); |
381 |
zoomRasterRequestManager.initRequest(dataModel.getRasterExtent()); |
382 |
zoomRasterRequestManager.request(ext); |
383 |
|
384 |
processActions.setViewMapRequest(viewMapRequestManager); |
385 |
} catch (InvalidRequestException e1) {
|
386 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", this, e1); |
387 |
fManager.closeAllWindows(); |
388 |
}catch (Exception e1) { |
389 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", this, e1); |
390 |
fManager.closeAllWindows(); |
391 |
} |
392 |
|
393 |
buildNewPointList(); |
394 |
} |
395 |
|
396 |
public ViewRasterRequestManager getZoomRasterRequestManager() {
|
397 |
return zoomRasterRequestManager;
|
398 |
} |
399 |
|
400 |
public ViewMapRequestManager getZoomMapRequestManager() {
|
401 |
return zoomMapRequestManager;
|
402 |
} |
403 |
|
404 |
public GeorefControlPanel getGeorefControlPanel() {
|
405 |
if(georefControlPanel == null) { |
406 |
georefControlPanel = sManager.createGeorefControlPanel(); |
407 |
} |
408 |
return georefControlPanel;
|
409 |
} |
410 |
|
411 |
public SynchronizedViews getSyncViews() {
|
412 |
return syncViews;
|
413 |
} |
414 |
|
415 |
public GeoreferencingProcessActions getProcessActions() {
|
416 |
return processActions;
|
417 |
} |
418 |
|
419 |
public GeoreferencingOptionsDataModel getDataModel() {
|
420 |
return GeoreferencingSwingLocator.getSwingManager().getDataModel();
|
421 |
} |
422 |
|
423 |
} |