Revision 2977

View differences:

trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/layers/FLyrGeoRaster.java
41 41
package com.iver.cit.gvsig.fmap.layers;
42 42

  
43 43
import java.awt.Graphics2D;
44
import java.awt.geom.Point2D;
44 45
import java.awt.geom.Rectangle2D;
45 46
import java.awt.image.BufferedImage;
46 47

  
......
50 51
import com.iver.cit.gvsig.fmap.DriverException;
51 52
import com.iver.cit.gvsig.fmap.ViewPort;
52 53
import com.iver.cit.gvsig.fmap.operations.Cancellable;
54
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel;
53 55

  
54 56

  
55 57
/**
......
267 269
	public StackZoom getStackZoom(){
268 270
		return zoom;
269 271
	}
272

  
273
	/**
274
	 * Transforma un pixel de la imagen cuyas coordenadas son (0..maxWidth, 0..maxHeight)
275
	 * en coordenadas del mundo real a partir del extent asignado a la imagen. 
276
	 * @param pixel Pixel de la imagen
277
	 * @return	Coordenadas del mundo de ese pixel
278
	 */
279
	public Point2D img2World(Point2D pixel){
280
		Point2D p = new Point2D.Double();
281
		double wcWidth = 0.0, wcHeight = 0.0, ptoWCX = 0.0, ptoWCY = 0.0;
282
		int pixelImgX = 0, pixelImgY = 0;
283
		try{
284
			wcWidth = getFullExtent().getWidth();
285
			wcHeight = getFullExtent().getHeight();
286
			pixelImgX = (int)((pixel.getX() * wcWidth) / SelectFilePanel.widthPxImg);
287
			pixelImgY = (int)((pixel.getY() * wcHeight) / SelectFilePanel.heightPxImg);
288
		}catch(DriverException ex){}
289
		p.setLocation(pixelImgX, pixelImgY);
290
		System.out.println("ENTRADA="+pixel);
291
		System.out.println("SALIDA="+p);
292
		System.out.println("wc AxH="+wcWidth+" "+wcHeight);
293
		System.out.println("img AxH="+SelectFilePanel.widthPxImg+" "+SelectFilePanel.heightPxImg);
294
		return p;
295
	}
296
	
297
	/**
298
	 * Transforma un pixel de la imagen cuyas coordenadas son (0..maxWidth, 0..maxHeight)
299
	 * en coordenadas del mundo real a partir del extent asignado a la imagen. 
300
	 * @param x Coordenada X del pixel de la imagen
301
	 * @param y Coordenada Y del pixel de la imagen
302
	 * @return	Coordenadas del mundo de ese pixel
303
	 */
304
	public Point2D img2World(double x, double y){
305
		Point2D p = new Point2D.Double();
306
		p.setLocation(x, y);
307
		return this.img2World(p);
308
	}
270 309
}
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/layers/FLyrPoints.java
52 52
import com.iver.cit.gvsig.fmap.ViewPort;
53 53
import com.iver.cit.gvsig.fmap.operations.Cancellable;
54 54
import com.iver.cit.gvsig.gui.View;
55
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel;
55 56

  
56 57

  
57 58
/**
......
74 75
	private ArrayList pointList = new ArrayList();
75 76
	private final int DIAM_CIRCLE = 18;
76 77
	private String lastTool = null;
77
			
78
	
79
	
78 80
	/**
79 81
	 * Dibujado de la capa de raster georeferenciado aplicando la 
80 82
	 * transformaci?n del viewPort.
......
82 84
	public void draw(BufferedImage image, Graphics2D g, ViewPort vp,
83 85
			Cancellable cancel,double scale) throws DriverException {
84 86
		View theView = (View) PluginServices.getMDIManager().getActiveView();
85
		BufferedImage img = theView.getMapControl().getImage();
86
		g.drawImage(img, 0, 0, null);
87
		g.setColor(Color.red);
88
				
87
		//BufferedImage img = theView.getMapControl().getImage();
88
		//g.drawImage(img, 0, 0, null);
89
		int dpto = (DIAM_CIRCLE >> 1);
90
		int incr = 5;
91
		Point2D pto = null;
92
		FLyrGeoRaster lyrGeoRaster = null;
93
		//Obtenemos la capa de puntos y la capa de georaster
94
		
95
		for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
96
			FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
97
			if(lyr instanceof FLyrGeoRaster)
98
				lyrGeoRaster = (FLyrGeoRaster)lyr;
99
		}
100
		
89 101
		for(int i=0; i<pointList.size();i++){
90
			//Point2D pto = vp.fromMapPoint((Point2D)pointList.get(i));
91
			Point2D pto = ((GeoPoint)pointList.get(i)).pixelPoint;
92
			int dpto = (DIAM_CIRCLE >> 1);
102
			
103
			//Punto de la imagen
104
			pto = ((GeoPoint)pointList.get(i)).pixelPoint;
105
			
93 106
			if(pto != null){
107
				g.setColor(Color.red);
108
				Point2D p = lyrGeoRaster.img2World(pto.getX(), pto.getY());
109
				p = vp.fromMapPoint(p);
110
				System.out.println(" DIBUJANDO..."+p);
111
				g.drawOval(	(int)p.getX() - dpto, 
112
							(int)p.getY() - dpto, 
113
							DIAM_CIRCLE, 
114
							DIAM_CIRCLE);
115
				g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
116
				g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
117
			}
118
			
119
			//Punto de la vista
120
			pto = ((GeoPoint)pointList.get(i)).mapPoint;
121
			if(pto != null){
122
				pto = vp.fromMapPoint(pto);
123
				g.setColor(Color.green);
94 124
				g.drawOval(	(int)pto.getX() - dpto, 
95 125
							(int)pto.getY() - dpto, 
96 126
							DIAM_CIRCLE, 
97 127
							DIAM_CIRCLE);
98
				int incr = 5;
99 128
				g.drawLine((int)pto.getX(), (int)pto.getY() - dpto - incr, (int)pto.getX(), (int)pto.getY() + dpto + incr);
100 129
				g.drawLine((int)pto.getX() - dpto - incr, (int)pto.getY(), (int)pto.getX() + dpto + incr, (int)pto.getY());
101 130
			}
102
			
103 131
		}
104 132
	}
105 133
	
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/Behavior/GeoRedimBehavior.java
166 166
		}else
167 167
			r.setFrameFromDiagonal(tmpUl, tmpLr);
168 168
			
169
		
170
			
171 169
			g.drawRect(r.x, r.y, r.width, r.height);
172 170
		
173 171
	}
......
183 181
		if (e.getButton() == MouseEvent.BUTTON1) {
184 182
			
185 183
			loadLayer();
186
			
187 184
			tmpUl = ul;
188 185
			tmpLr = lr;
186
			
187
			ViewPort vp = getMapControl().getMapContext().getViewPort();
188
			double wcX = vp.toMapPoint(e.getX(), e.getY()).getX();
189
			double wcY = vp.toMapPoint(e.getX(), e.getY()).getY();
190
			
191
			double minX = lyrGeoRaster.getAssignExtent().getMin().getX();
192
			double minY = lyrGeoRaster.getAssignExtent().getMin().getY();
193
			double maxX = lyrGeoRaster.getAssignExtent().getMax().getX();
194
			double maxY = lyrGeoRaster.getAssignExtent().getMax().getY();
195
			
196
			
189 197
			if(iconActive[0]){//Estirar en horizontal activado
190
				if(e.getX() > (tmpLr.getX() - WIDTH_BORDER) && e.getX() < tmpLr.getX())
198
				if(wcX > (maxX - WIDTH_BORDER) && wcX < maxX)
191 199
					redimActive[0] = true;
192
				if(e.getX() < (tmpUl.getX() + WIDTH_BORDER) && e.getX() > tmpUl.getX())
200
				if(wcX < (minX + WIDTH_BORDER) && wcX > minX)
193 201
					redimActive[1] = true;
194 202
			}
195 203
			if(iconActive[1]){//Estirar en vertical activado
196
				if(e.getY() < (tmpLr.getY() + WIDTH_BORDER) && e.getY() > tmpLr.getY())
204
				if(wcY > (maxY - WIDTH_BORDER) && wcY < maxY)
197 205
					redimActive[3] = true;
198
				if(e.getY() > (tmpUl.getY() - WIDTH_BORDER) && e.getY() < tmpUl.getY())
206
				if(wcY < (minY + WIDTH_BORDER) && wcY > minY)
199 207
					redimActive[2] = true;
200 208
			}
201 209
			if(iconActive[2] || iconActive[3]){ //Estirar en oblicuo activado
......
259 267
			double coordCentro = tmpLr.getY() + (Math.abs(tmpLr.getY() - tmpUl.getY()) / 2);
260 268
			tmpUl = new Point2D.Double(tmpUl.getX(), coordCentro + (newLadoCorto/2));
261 269
			tmpLr = new Point2D.Double(e.getX(), coordCentro - (newLadoCorto/2));
262
			System.out.println("Vertical derecha "+e.getPoint()+" newladoLargo="+newLadoLargo+" newladoCorto="+newLadoCorto+" centro="+coordCentro);
263
			System.out.println("................  longLadoLargo="+longLadoLargo+" longLadoCorto="+longLadoCorto);
270
			//System.out.println("Vertical derecha "+e.getPoint()+" newladoLargo="+newLadoLargo+" newladoCorto="+newLadoCorto+" centro="+coordCentro);
271
			//System.out.println("................  longLadoLargo="+longLadoLargo+" longLadoCorto="+longLadoCorto);
264 272
		}
265 273
		if(redimActive[1]){//vertical izquierda
266 274
			double newLadoLargo = (e.getX() - tmpLr.getX());
......
356 364
		double maxY = lyrGeoRaster.getAssignExtent().getMax().getY();
357 365
		
358 366
		//Calculamos el borde sobre el cual cambiar? el puntero del rat?n y la longitud de la esquina
367
		
359 368
		WIDTH_BORDER = (int)Math.round((maxX - minX) * 0.02);
360 369
		LONG_CORNER = (int)Math.round((maxX - minX) * 0.03);
361 370
		if(WIDTH_BORDER < 15)
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/toolListeners/GeorefPointerListener.java
42 42

  
43 43
import java.awt.geom.Point2D;
44 44

  
45
import javax.swing.JComboBox;
46

  
47 45
import com.iver.andami.PluginServices;
46
import com.iver.cit.gvsig.fmap.DriverException;
48 47
import com.iver.cit.gvsig.fmap.ViewPort;
49 48
import com.iver.cit.gvsig.fmap.layers.FLayer;
49
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
50 50
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
51 51
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
52 52
import com.iver.cit.gvsig.fmap.tools.GeorefPointerListenerImpl;
53 53
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
54 54
import com.iver.cit.gvsig.gui.View;
55 55
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog;
56
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel;
56 57

  
57 58

  
58 59
/**
......
65 66
public class GeorefPointerListener extends GeorefPointerListenerImpl {
66 67
	
67 68
	private GeoreferencingDialog dialog = null;
69
	private boolean firstPoint = true;
70
	private View theView = null;
71
	private FLyrPoints lyrPoints = null;
72
	private FLyrGeoRaster lyrGeoRaster = null;
68 73
	
74
	
69 75
	/**
70 76
	 * Posici?n del punto a ser seleccionado. 
71 77
	 */
......
91 97
	public void point(PointEvent event) throws BehaviorException {
92 98
		super.point(event);
93 99
			
94
		//Obtenemos la capa de puntos 
95
		View theView = (View) PluginServices.getMDIManager().getActiveView();
96
		FLyrPoints lyrPoints = null;
100
		theView = (View) PluginServices.getMDIManager().getActiveView();
101
		//Obtenemos la capa de puntos y la capa de georaster
102
		
97 103
		for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
98 104
			FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
99 105
			if(lyr instanceof FLyrPoints)
100 106
				lyrPoints = (FLyrPoints)lyr;
107
			if(lyr instanceof FLyrGeoRaster)
108
				lyrGeoRaster = (FLyrGeoRaster)lyr;
101 109
		}
102 110
		
103
		//Le a?adimos un punto 
104
		if(lyrPoints != null){
105
			ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
106
			Point2D wcPoint = viewPort.toMapPoint(event.getPoint());
107
					
108
			//lyrPoints.addPoint(event.getPoint(), wcPoint)
109
			System.out.println("Insertando pos="+GeorefPointerListener.posPoint);
110
			System.out.println("...........pixel:="+wcPoint);
111
			System.out.println("...........map="+event.getPoint());
112
			
111
		ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
112
		Point2D wcPoint = viewPort.toMapPoint(event.getPoint());
113
		
114
		if(firstPoint){	
115
			if(lyrPoints != null){
116
						
117
				//Hallamos pixelImg q son las coordenadas en pixeles de la imagen que corresponden
118
				//con el punto seleccionado
119
				double wcWidth = 0.0, wcHeight = 0.0, ptoWCX = 0.0, ptoWCY = 0.0;
120
				int pixelImgX = 0, pixelImgY = 0;
121
				try{
122
					wcWidth = lyrGeoRaster.getFullExtent().getWidth();
123
					wcHeight = lyrGeoRaster.getFullExtent().getHeight();
124
					ptoWCX = wcPoint.getX() - lyrGeoRaster.getFullExtent().getMinX();
125
					ptoWCY = wcPoint.getY() - lyrGeoRaster.getFullExtent().getMinY();
126
					pixelImgX = (int)((ptoWCX * SelectFilePanel.widthPxImg) / wcWidth);
127
					pixelImgY = (int)((ptoWCY * SelectFilePanel.heightPxImg) / wcHeight);
128
				}catch(DriverException ex){}
129
				 
130
				
131
				//Salvamos el primer punto pinchado en la capa. (Pixeles de la imagen)
132
				lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint = new Point2D.Double();
133
				lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint.setLocation(event.getPoint());
134
				//Cargamos en la ventana el nuevo punto
135
				dialog.getSelectPointsPanel().getTX().setText(String.valueOf(pixelImgX));
136
				dialog.getSelectPointsPanel().getTY().setText(String.valueOf(pixelImgY));
137
				firstPoint = false;
138
			}
139
		}else{
140
			//Salvamos el segundo punto pinchado en la capa (Coordenadas de georreferenciaci?n)
113 141
			lyrPoints.getPoint(GeorefPointerListener.posPoint).mapPoint = new Point2D.Double();
114 142
			lyrPoints.getPoint(GeorefPointerListener.posPoint).mapPoint.setLocation(wcPoint);
115
			lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint = new Point2D.Double();
116
			lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint.setLocation(event.getPoint());
117
			
118
			lyrPoints.showPoints();
119
			
120
			theView.getMapControl().getMapContext().invalidate();
121
			
122
			//Deseleccionamos la herramienta de marcado de puntos
123
			theView.getMapControl().setTool(lyrPoints.getLastTool());
124
			
125 143
			//Cargamos en la ventana el nuevo punto
126
			dialog.getSelectPointsPanel().getTX().setText(String.valueOf(event.getPoint().getX()));
127
			dialog.getSelectPointsPanel().getTY().setText(String.valueOf(event.getPoint().getY()));
128 144
			dialog.getSelectPointsPanel().getLongitud().setText(String.valueOf(wcPoint.getX()));
129 145
			dialog.getSelectPointsPanel().getLatitud().setText(String.valueOf(wcPoint.getY()));
146
									
147
			//Deseleccionamos la herramienta de marcado de puntos
148
			theView.getMapControl().setTool(lyrPoints.getLastTool());
149
			firstPoint = true;
130 150
		}
131
			
151
		theView.getMapControl().getMapContext().invalidate();
152
		lyrPoints.showPoints();
132 153
	}
133 154
}
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/Panels/SelectPointsPanel.java
40 40
	private JLabel lX = null;
41 41
	private JLabel lY = null;
42 42
	private JTextField tY = null;
43
	private JLabel lLongitud = null;
43 44
	private JLabel lLatitud = null;
44
	private JLabel lLongitud = null;
45 45
	private JTextField tLatitud = null;
46 46
	private JTextField tLongitud = null;
47 47

  
......
280 280
		isNew = true;
281 281
		getCPoint().removeAllItems();
282 282
		checkArrows();
283
		View theView = (View) PluginServices.getMDIManager().getActiveView();
284
		theView.getMapControl().getMapContext().invalidate();
283 285
	}
284 286
	
285 287
	/**
......
581 583
	 */
582 584
	private JPanel getPLatitud() {
583 585
		if (pLatitud == null) {
584
			lLatitud = new JLabel();
585
			lLatitud.setText(PluginServices.getText(this,"latitud")+":");
586
			lLongitud = new JLabel();
587
			lLongitud.setText("longitud:");
586 588
			FlowLayout flowLayout3 = new FlowLayout();
587 589
			flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
588 590
			pLatitud = new JPanel();
589 591
			pLatitud.setLayout(flowLayout3);
590 592
			pLatitud.setPreferredSize(new java.awt.Dimension(185,29));
591
			pLatitud.add(lLatitud, null);
592
			pLatitud.add(getLatitud(), null);
593
			pLatitud.add(lLongitud, null);
594
			pLatitud.add(getLongitud(), null);
593 595
		}
594 596
		return pLatitud;
595 597
	}
......
601 603
	 */
602 604
	private JPanel getPLongitud() {
603 605
		if (pLongitud == null) {
604
			lLongitud = new JLabel();
605
			lLongitud.setText(PluginServices.getText(this, "longitud")+":");
606
			lLatitud = new JLabel();
607
			lLatitud.setText(PluginServices.getText(this, "latitud")+":");
606 608
			FlowLayout flowLayout4 = new FlowLayout();
607 609
			flowLayout4.setAlignment(java.awt.FlowLayout.RIGHT);
608 610
			pLongitud = new JPanel();
609 611
			pLongitud.setLayout(flowLayout4);
610 612
			pLongitud.setPreferredSize(new java.awt.Dimension(185,29));
611
			pLongitud.add(lLongitud, null);
612
			pLongitud.add(getLongitud(), null);
613
			pLongitud.add(lLatitud, null);
614
			pLongitud.add(getLatitud(), null);
613 615
		}
614 616
		return pLongitud;
615 617
	}
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/Panels/SelectFilePanel.java
66 66
	private JPanel pCheckUseGeoref = null;
67 67
	private JCheckBox cbUseGeoref = null;
68 68
	private JLabel lUseGeoref = null;
69
	public static double widthPxImg, heightPxImg;
70
	
69 71
	/**
70 72
	 * This is the default constructor
71 73
	 */
......
250 252
		//del viewport.
251 253
		Extent tempExtent = null;
252 254
		GeoRasterFile grf = GeoRasterFile.openFile(proj, file);
253
		double w = grf.getWidth();
254
		double h = grf.getHeight();
255
		double w = widthPxImg = grf.getWidth();
256
		double h = heightPxImg = grf.getHeight();
255 257
		if(vp == null || vp.getAdjustedExtent() == null){
256 258
			vp = new ViewPort(proj);
257 259
			Rectangle2D r2d = new Rectangle2D.Double(0, 0, w, h);

Also available in: Unified diff