Revision 4840
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/dialogs/GeoreferencingDialog.java | ||
---|---|---|
7 | 7 |
import java.awt.event.ActionListener; |
8 | 8 |
import java.awt.event.ComponentEvent; |
9 | 9 |
import java.awt.event.ComponentListener; |
10 |
import java.awt.geom.Point2D; |
|
11 |
import java.awt.geom.Rectangle2D; |
|
10 | 12 |
import java.beans.PropertyVetoException; |
11 | 13 |
import java.io.File; |
12 | 14 |
|
... | ... | |
25 | 27 |
import com.iver.cit.gvsig.GeoOperations; |
26 | 28 |
import com.iver.cit.gvsig.fmap.DriverException; |
27 | 29 |
import com.iver.cit.gvsig.fmap.MapControl; |
30 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
28 | 31 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
29 | 32 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
30 | 33 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
... | ... | |
285 | 288 |
}catch(ClassCastException exc){ |
286 | 289 |
return; |
287 | 290 |
} |
288 |
|
|
289 |
//ACEPTAR |
|
290 |
if(e.getSource() == bAceptar){ |
|
291 |
if(getLyrPoints() == null) |
|
292 |
return; |
|
293 |
|
|
294 |
if(lyrGeoRaster != null){ |
|
295 |
getLyrPoints().setVisible(false); |
|
296 |
lyrGeoRaster.setName(lyrGeoRaster.getName().substring(1, lyrGeoRaster.getName().length())); |
|
297 |
lyrGeoRaster.setActive(false); |
|
298 |
theView.getMapControl().getMapContext().invalidate(); |
|
291 |
|
|
292 |
try{ |
|
293 |
//ACEPTAR |
|
294 |
if(e.getSource() == bAceptar){ |
|
295 |
accept(theView); |
|
299 | 296 |
} |
300 | 297 |
|
301 |
try{ |
|
302 |
frame.setClosed(true); |
|
303 |
}catch(PropertyVetoException exc){} |
|
298 |
//CANCELAR |
|
299 |
if(e.getSource() == bCancelar){ |
|
300 |
cancel(theView); |
|
301 |
} |
|
302 |
}catch(Exception exc){ |
|
303 |
return; |
|
304 | 304 |
} |
305 | 305 |
|
306 |
//CANCELAR |
|
307 |
if(e.getSource() == bCancelar){ |
|
308 |
if(getLyrPoints() == null) |
|
309 |
return; |
|
310 |
|
|
311 |
//Cerramos la ventana |
|
312 |
//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener) |
|
313 |
try{ |
|
314 |
frame.setClosed(true); |
|
315 |
}catch(PropertyVetoException exc){} |
|
316 |
} |
|
317 |
|
|
318 | 306 |
//CARGAR PUNTOS |
319 | 307 |
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBLoad()){ |
320 | 308 |
JFileChooser chooser = new JFileChooser(lastPathLoad); |
... | ... | |
402 | 390 |
//PROCESAR |
403 | 391 |
if(e.getSource() == this.getBProcesar()){ |
404 | 392 |
if(this.getLyrPoints().getCountPoints() > 0){ |
405 |
GeoOperations go = new GeoOperations(getLyrPoints(), |
|
406 |
(int)getLyrGeoRaster().getWidth(), |
|
407 |
(int)getLyrGeoRaster().getHeight(), |
|
408 |
getLyrGeoRaster().getSource().getFiles()[0].getName()); |
|
409 |
try{ |
|
410 |
frame.setClosed(true); |
|
411 |
}catch(PropertyVetoException exc){ |
|
412 | 393 |
|
413 |
} |
|
414 |
//View view = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView(); |
|
415 |
//FLayers lyrs = view.getMapControl().getMapContext().getLayers(); |
|
394 |
//Creamos el fichero de georreferenciaci?n |
|
395 |
GeoOperations go = new GeoOperations(getLyrPoints()); |
|
396 |
go.createWorldFile( (int)getLyrGeoRaster().getWidth(), |
|
397 |
(int)getLyrGeoRaster().getHeight(), |
|
398 |
getLyrGeoRaster().getSource().getFiles()[0].getName()); |
|
399 |
|
|
416 | 400 |
FLayers lyrs = this.getLyrGeoRaster().getParentLayer(); |
417 | 401 |
for(int i = 0; i < lyrs.getLayersCount();i++){ |
418 | 402 |
if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){ |
403 |
|
|
404 |
//Eliminamos la capa |
|
419 | 405 |
lyrs.removeLayer(i); |
420 | 406 |
File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName()); |
421 | 407 |
try{ |
408 |
//Creamos la nueva capa GeoRaster y la a?adimos al TOC. |
|
422 | 409 |
FLyrGeoRaster lyrGeoRaster = |
423 |
FLyrGeoRaster.createLayer(getLyrGeoRaster().getName(), |
|
410 |
FLyrGeoRaster.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()),
|
|
424 | 411 |
(RasterDriver)getLyrGeoRaster().getSource().getDriver(), |
425 | 412 |
fich, |
426 | 413 |
getLyrGeoRaster().getProjection(), |
427 | 414 |
getLyrGeoRaster().getImageWidth(), |
428 | 415 |
getLyrGeoRaster().getImageHeight()); |
416 |
getLyrPoints().setVisible(false); |
|
417 |
this.getLyrPoints().setLyrGeoRaster(lyrGeoRaster); |
|
418 |
lyrGeoRaster.setFLyrPoints(this.getLyrPoints()); |
|
419 |
lyrGeoRaster.setGeoDialog(this); |
|
420 |
this.lyrGeoRaster = lyrGeoRaster; |
|
421 |
calcNewMiniExtent(theView); |
|
429 | 422 |
lyrs.addLayer(lyrGeoRaster); |
423 |
|
|
424 |
lyrGeoRaster.setActive(false); |
|
425 |
theView.getMapControl().getMapContext().invalidate(); |
|
426 |
|
|
427 |
try{ |
|
428 |
frame.setClosed(true); |
|
429 |
}catch(PropertyVetoException exc){} |
|
430 |
|
|
430 | 431 |
}catch(DriverException exc){ |
431 | 432 |
|
432 | 433 |
} |
... | ... | |
439 | 440 |
} |
440 | 441 |
|
441 | 442 |
/** |
443 |
* Funci?n que se ejecuta al pulsar el bot?n aceptar |
|
444 |
* @param theView |
|
445 |
*/ |
|
446 |
private void accept(View theView)throws Exception{ |
|
447 |
if(getLyrPoints() == null) |
|
448 |
throw new Exception("LyrPoints not loaded."); |
|
449 |
|
|
450 |
if(lyrGeoRaster != null){ |
|
451 |
getLyrPoints().setVisible(false); |
|
452 |
lyrGeoRaster.setName(lyrGeoRaster.getName().substring(1, lyrGeoRaster.getName().length())); |
|
453 |
lyrGeoRaster.setActive(false); |
|
454 |
theView.getMapControl().getMapContext().invalidate(); |
|
455 |
} |
|
456 |
|
|
457 |
try{ |
|
458 |
frame.setClosed(true); |
|
459 |
}catch(PropertyVetoException exc){} |
|
460 |
} |
|
461 |
|
|
462 |
/** |
|
463 |
* Funci?n que se ejecuta al pulsar el bot?n cancelar |
|
464 |
* @param theView |
|
465 |
*/ |
|
466 |
private void cancel(View theView)throws Exception{ |
|
467 |
if(getLyrPoints() == null) |
|
468 |
throw new Exception("LyrPoints not loaded."); |
|
469 |
|
|
470 |
//Cerramos la ventana |
|
471 |
//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener) |
|
472 |
try{ |
|
473 |
frame.setClosed(true); |
|
474 |
theView.getMapControl().getMapContext().invalidate(); |
|
475 |
}catch(PropertyVetoException exc){} |
|
476 |
} |
|
477 |
|
|
478 |
|
|
479 |
/** |
|
480 |
* Recalcula el extent de la mini-imagen que corresponde a los puntos en coordenadas |
|
481 |
* pixel.Para esto calcula el nuevo centro a partir de la capa y con la distancia entre |
|
482 |
* el nuevo centro y el viejo desplaza el extent completo de la mini-imagen. |
|
483 |
* @param theView |
|
484 |
*/ |
|
485 |
private void calcNewMiniExtent(View theView){ |
|
486 |
|
|
487 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
|
488 |
for(int j = 0; j < getLyrPoints().getCountPoints(); j++){ |
|
489 |
//Calculamos el nuevo centro |
|
490 |
Point2D oldCenter = getLyrPoints().getPoint(j).leftCenterPoint; |
|
491 |
Point2D newCenter = new Point2D.Double(); |
|
492 |
newCenter.setLocation( lyrGeoRaster.img2World(getLyrPoints().getPoint(j).pixelPoint)); |
|
493 |
|
|
494 |
double diffX = oldCenter.getX() - newCenter.getX(); |
|
495 |
double diffY = oldCenter.getY() - newCenter.getY(); |
|
496 |
|
|
497 |
getLyrPoints().getPoint(j).leftCenterPoint = newCenter; |
|
498 |
|
|
499 |
ViewPort vpOld = getLyrPoints().getPoint(j).leftViewPort; |
|
500 |
Rectangle2D newExtent = new Rectangle2D.Double( vpOld.getExtent().getMinX() - diffX, |
|
501 |
vpOld.getExtent().getMinY() - diffY, |
|
502 |
vpOld.getExtent().getWidth(), |
|
503 |
vpOld.getExtent().getHeight() ); |
|
504 |
ViewPort vpNew = new ViewPort(vpOld.getProjection()); |
|
505 |
vpNew.setExtent(newExtent); |
|
506 |
vpNew.setImageSize(vpOld.getImageSize()); |
|
507 |
vpNew.setScale(); |
|
508 |
getLyrPoints().getPoint(j).leftViewPort = vpNew; |
|
509 |
} |
|
510 |
} |
|
511 |
|
|
512 |
/** |
|
442 | 513 |
* This method initializes bProcesar |
443 | 514 |
* |
444 | 515 |
* @return javax.swing.JButton |
... | ... | |
449 | 520 |
bProcesar.setText(PluginServices.getText(this,"procesar")); |
450 | 521 |
bProcesar.setEnabled(true); |
451 | 522 |
bProcesar.addActionListener(this); |
452 |
|
|
453 |
/*new java.awt.event.ActionListener() { |
|
454 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
455 |
GeoOperations go = new GeoOperations(this.); |
|
456 |
if (PluginServices.getMainFrame() == null) { |
|
457 |
((JDialog) (getParent().getParent().getParent() |
|
458 |
.getParent())).dispose(); |
|
459 |
} else { |
|
460 |
PluginServices.getMDIManager().closeView((com.iver.andami.ui.mdiManager.View) GeoreferencingDialog.this); |
|
461 |
} |
|
462 |
} |
|
463 |
});*/ |
|
464 | 523 |
} |
465 | 524 |
return bProcesar; |
466 | 525 |
} |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/toc/GeoRasterTocMenuEntry.java | ||
---|---|---|
116 | 116 |
|
117 | 117 |
lyrGeoRaster.getFLyrPoints().saveState(); |
118 | 118 |
|
119 |
lyrGeoRaster.getFLyrPoints().showPoints(); |
|
119 |
//lyrGeoRaster.getFLyrPoints().showPoints();
|
|
120 | 120 |
|
121 | 121 |
View theView = null; |
122 | 122 |
try{ |
... | ... | |
128 | 128 |
//Hacemos visible la capa de puntos |
129 | 129 |
lyrGeoRaster.getFLyrPoints().setVisible(true); |
130 | 130 |
theView.getMapControl().getMapContext().invalidate(); |
131 |
|
|
131 |
|
|
132 | 132 |
geoDialog.getConectorPanel().getDataPointsTabPanel(). |
133 | 133 |
getSelectPointsPanel().getTableControlerPanel().setNItems(lyrGeoRaster.getFLyrPoints().getCountPoints()); |
134 | 134 |
|
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/GeoOperations.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig; |
2 | 2 |
|
3 |
import java.awt.geom.Point2D; |
|
3 | 4 |
import java.io.BufferedOutputStream; |
4 | 5 |
import java.io.DataOutputStream; |
5 | 6 |
import java.io.File; |
... | ... | |
18 | 19 |
public class GeoOperations{ |
19 | 20 |
|
20 | 21 |
private FLyrPoints lyrPoints = null; |
21 |
private int order = 1; |
|
22 |
|
|
22 |
private int order = 1; |
|
23 |
private PointT[] src = null; |
|
24 |
private PointT[] dst = null; |
|
25 |
private AffineT affine = null; |
|
26 |
|
|
27 |
/** |
|
28 |
* Constructor |
|
29 |
*/ |
|
23 | 30 |
public GeoOperations(){} |
24 | 31 |
|
25 | 32 |
/** |
26 |
* Contructor. Crea las estructuras de puntos y calcula la transformaci?n af?n. A partir |
|
27 |
* de esta genera un fichero de georreferenciaci?n para la imagen. |
|
28 |
* @param lyr Capa de puntos |
|
29 |
* @param order Orden del sistema de ecuaciones |
|
30 |
* @param widthPx Ancho en pixeles de la imagen a georreferenciar |
|
31 |
* @param heightPx Alto en pixeles de la imagen a georreferenciar |
|
32 |
* @param file Nombre del fichero raster a georreferenciar |
|
33 |
* Constructor. Crea las estructuras de puntos y calcula la transformaci?n af?n. |
|
34 |
* @param lyr |
|
33 | 35 |
*/ |
34 |
public GeoOperations(FLyrPoints lyr, int widthPx, int heightPx, String file){
|
|
36 |
public GeoOperations(FLyrPoints lyr){ |
|
35 | 37 |
this.lyrPoints = lyr; |
36 |
PointT[] src = new PointT[lyr.getCountPoints()]; |
|
37 |
PointT[] dst = new PointT[lyr.getCountPoints()]; |
|
38 |
src = new PointT[lyr.getCountPoints()]; |
|
39 |
dst = new PointT[lyr.getCountPoints()]; |
|
40 |
int nPoint = 0; |
|
38 | 41 |
for(int i = 0; i<lyr.getCountPoints(); i++){ |
39 |
src[i] = new PointT(); |
|
40 |
dst[i] = new PointT(); |
|
41 |
src[i].setX(lyr.getPoint(i).pixelPoint.getX()); |
|
42 |
src[i].setY(lyr.getPoint(i).pixelPoint.getY()); |
|
43 |
src[i].setI(lyr.getCountPoints()); |
|
44 |
dst[i].setX(lyr.getPoint(i).mapPoint.getX()); |
|
45 |
dst[i].setY(lyr.getPoint(i).mapPoint.getY()); |
|
46 |
dst[i].setI(lyr.getCountPoints()); |
|
42 |
if(lyr.getPoint(i).active == true){ |
|
43 |
src[nPoint] = new PointT(); |
|
44 |
dst[nPoint] = new PointT(); |
|
45 |
src[nPoint].setX(lyr.getPoint(i).pixelPoint.getX()); |
|
46 |
src[nPoint].setY(lyr.getPoint(i).pixelPoint.getY()); |
|
47 |
src[nPoint].setI(lyr.getCountPoints()); |
|
48 |
dst[nPoint].setX(lyr.getPoint(i).mapPoint.getX()); |
|
49 |
dst[nPoint].setY(lyr.getPoint(i).mapPoint.getY()); |
|
50 |
dst[nPoint].setI(lyr.getCountPoints()); |
|
51 |
nPoint++; |
|
52 |
} |
|
47 | 53 |
} |
48 | 54 |
|
49 | 55 |
if(lyr.getCountPoints() >= 3 * 10) |
... | ... | |
54 | 60 |
order = 1; |
55 | 61 |
|
56 | 62 |
|
57 |
AffineT affine = new AffineT();
|
|
63 |
affine = new AffineT(); |
|
58 | 64 |
|
59 | 65 |
//Calcular la transformaci?n afin por m?nimos cuadrados |
60 | 66 |
affine = computeLeastSquaresAffine(affine, src, dst, order); |
61 |
|
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* A partir de la transformaci?n af?n creada en el construtor |
|
71 |
* genera un fichero de georreferenciaci?n para la imagen. |
|
72 |
* @param lyr Capa de puntos |
|
73 |
* @param order Orden del sistema de ecuaciones |
|
74 |
* @param widthPx Ancho en pixeles de la imagen a georreferenciar |
|
75 |
* @param heightPx Alto en pixeles de la imagen a georreferenciar |
|
76 |
* @param file Nombre del fichero raster a georreferenciar |
|
77 |
*/ |
|
78 |
public void createWorldFile(int widthPx, int heightPx, String file){ |
|
62 | 79 |
try{ |
63 | 80 |
File f = new File(file); |
64 | 81 |
String nameWorldFile = f.getPath().substring(0, f.getPath().lastIndexOf(".")) + getExtensionWorldFile(file); |
... | ... | |
69 | 86 |
} |
70 | 87 |
|
71 | 88 |
/** |
89 |
* A partir de la transformaci?n af?n calculada en el contructor |
|
90 |
* transforma los puntos pasados como par?metros. |
|
91 |
* @param lyr Capa de puntos |
|
92 |
* @param list Lista de puntos a transformar |
|
93 |
* @return Lista de puntos transformados |
|
94 |
*/ |
|
95 |
public Point2D[] transformPoints(Point2D[] list){ |
|
96 |
Point2D[] result = new Point2D[list.length]; |
|
97 |
for(int i = 0; i < list.length;i++){ |
|
98 |
double[] pto = transformPoint((int)list[i].getX(), (int)list[i].getY(), affine); |
|
99 |
result[i] = new Point2D.Double(pto[0], pto[1]); |
|
100 |
} |
|
101 |
return result; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
72 | 105 |
* Crea un fichero de georreferenciaci?n (worldfile) a partir de la transformaci?n af?n. Para |
73 | 106 |
* esto necesita obtener las coordenadas reales de la coordenada en pixels (0,0) y calcular |
74 | 107 |
* el tama?o de pixel. |
Also available in: Unified diff