Revision 2887
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/georeferencing/GeoreferencingModule.java | ||
---|---|---|
60 | 60 |
*/ |
61 | 61 |
public class GeoreferencingModule implements Extension { |
62 | 62 |
private GeoreferencingDialog geoDialog = null; |
63 |
|
|
63 | 64 |
/** |
64 | 65 |
* El control est? activo siempre que haya una vista abierta |
65 | 66 |
*/ |
... | ... | |
96 | 97 |
MapControl mapCtrl = vista.getMapControl(); |
97 | 98 |
geoDialog = new GeoreferencingDialog(); |
98 | 99 |
PluginServices.getMDIManager().addView(geoDialog); |
99 |
|
|
100 | 100 |
} |
101 | 101 |
|
102 | 102 |
/** |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/fmap/tools/ZoomInGeorefListenerImpl.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.fmap.tools; |
42 | 42 |
|
43 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
44 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
45 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
46 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
47 |
|
|
48 | 43 |
import java.awt.Cursor; |
49 | 44 |
import java.awt.Image; |
50 | 45 |
import java.awt.Point; |
... | ... | |
53 | 48 |
|
54 | 49 |
import javax.swing.ImageIcon; |
55 | 50 |
|
51 |
import org.cresques.px.Extent; |
|
56 | 52 |
|
53 |
import com.iver.andami.PluginServices; |
|
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
55 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
56 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
57 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
58 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
59 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
60 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
61 |
import com.iver.cit.gvsig.gui.View; |
|
62 |
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
|
63 |
|
|
64 |
|
|
57 | 65 |
/** |
58 | 66 |
* Implementaci?n de la interfaz RectangleListener como herramienta para |
59 |
* realizar un zoom m?s. |
|
67 |
* realizar un zoom m?s en la imagen a georeferenciar.
|
|
60 | 68 |
* |
61 |
* @author Vicente Caballero Navarro
|
|
69 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
|
62 | 70 |
*/ |
63 | 71 |
public class ZoomInGeorefListenerImpl implements RectangleListener { |
64 | 72 |
private final Image izoomin = new ImageIcon(MapControl.class.getResource( |
... | ... | |
75 | 83 |
public ZoomInGeorefListenerImpl(MapControl mapCtrl) { |
76 | 84 |
this.mapCtrl = mapCtrl; |
77 | 85 |
System.out.println("****ZOOMIN"); |
86 |
|
|
87 |
|
|
88 |
/*((View)theView).addMouseMotionListener(new java.awt.event.MouseMotionListener() { |
|
89 |
public void mouseMoved(java.awt.event.MouseEvent e) { |
|
90 |
System.out.println("-->Move"); |
|
91 |
} |
|
92 |
public void mouseDragged(java.awt.event.MouseEvent e) { |
|
93 |
System.out.println("-->Dragg"); |
|
94 |
} |
|
95 |
});*/ |
|
78 | 96 |
} |
79 | 97 |
|
80 | 98 |
/** |
... | ... | |
84 | 102 |
Rectangle2D rect = event.getWorldCoordRect(); |
85 | 103 |
Rectangle2D pixelRect = event.getPixelCoordRect(); |
86 | 104 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
87 |
|
|
105 |
|
|
106 |
//Obtenemos la capa a georreferenciar a trav?s del nombre |
|
107 |
String fileName = SelectFilePanel.getLyrName(); |
|
108 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
|
109 |
FLyrRaster lyrRaster = (FLyrRaster)theView.getMapControl().getMapContext().getLayers().getLayer(fileName); |
|
110 |
lyrRaster.setTempExtent(new Extent(rect)); |
|
111 |
try { |
|
112 |
lyrRaster.load(); |
|
113 |
} catch (DriverIOException e) { |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
lyrRaster.setVisible(true); |
|
118 |
|
|
119 |
//theView.getMapControl().getMapContext().invalidate(); |
|
120 |
|
|
88 | 121 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
89 |
|
|
90 |
if ((pixelRect.getWidth() < 3) && (pixelRect.getHeight() < 3)) |
|
122 |
vp.setExtent(vp.getExtent()); |
|
123 |
/*if ((pixelRect.getWidth() < 3) && (pixelRect.getHeight() < 3))
|
|
91 | 124 |
{ |
92 | 125 |
if (vp.getExtent()!=null){ |
93 | 126 |
double factor = 0.6; |
... | ... | |
105 | 138 |
else |
106 | 139 |
{ |
107 | 140 |
vp.setExtent(event.getWorldCoordRect()); |
108 |
} |
|
141 |
}*/
|
|
109 | 142 |
// mapCtrl.drawMap(false); |
143 |
|
|
110 | 144 |
} |
111 | 145 |
|
112 | 146 |
/** |
trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/Panels/SelectFilePanel.java | ||
---|---|---|
4 | 4 |
import java.awt.GridBagConstraints; |
5 | 5 |
import java.awt.GridBagLayout; |
6 | 6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.geom.Rectangle2D; |
|
7 | 8 |
import java.io.File; |
8 | 9 |
|
9 | 10 |
import javax.swing.JButton; |
... | ... | |
14 | 15 |
import javax.swing.filechooser.FileFilter; |
15 | 16 |
|
16 | 17 |
import org.cresques.cts.IProjection; |
18 |
import org.cresques.io.GeoRasterFile; |
|
19 |
import org.cresques.px.Extent; |
|
17 | 20 |
|
18 | 21 |
import com.hardcode.driverManager.DriverLoadException; |
19 | 22 |
import com.iver.andami.PluginServices; |
20 | 23 |
import com.iver.andami.messages.NotificationManager; |
21 | 24 |
import com.iver.cit.gvsig.fmap.DriverException; |
25 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
26 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
22 | 27 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLayer;
|
|
28 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
|
|
24 | 29 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
30 |
import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
|
31 |
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter; |
|
25 | 32 |
import com.iver.cit.gvsig.gui.FOpenDialog; |
26 | 33 |
import com.iver.cit.gvsig.gui.View; |
27 | 34 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
... | ... | |
43 | 50 |
* Nombre del fichero seleccionado |
44 | 51 |
*/ |
45 | 52 |
private String fName = ""; |
53 |
|
|
46 | 54 |
/** |
55 |
* Nombre de la capa |
|
56 |
*/ |
|
57 |
private static String lyrName = ""; |
|
58 |
/** |
|
47 | 59 |
* Recuerda la ?ltima ruta seleccionada por el usuario |
48 | 60 |
*/ |
49 | 61 |
private String lastPath = "./"; |
50 | 62 |
private GeoreferencingDialog parent = null; |
63 |
private FLyrRaster lyrRaster = null; |
|
64 |
|
|
51 | 65 |
|
52 | 66 |
/** |
53 | 67 |
* This is the default constructor |
... | ... | |
183 | 197 |
return ((ProjChooserPanel)pProyection); |
184 | 198 |
} |
185 | 199 |
|
200 |
/** |
|
201 |
* Crea una capa Raster a partir del nombre driver, fichero y proyecci?n y |
|
202 |
* coordenadas de georeferenciaci?n. Esta funci?n es para georeferenciar |
|
203 |
* capas raster. Para imagenes que no tienen georeferenciaci?n hay que asignarle |
|
204 |
* una temporal, normalmente a partir de la vista activa. |
|
205 |
* |
|
206 |
* @param layerName Nombre de la capa. |
|
207 |
* @param d RasterDriver. |
|
208 |
* @param f Fichero. |
|
209 |
* @param proj Proyecci?n. |
|
210 |
* @param extent Extent de la vista activa |
|
211 |
* |
|
212 |
* @return Nueva capa de tipo raster. |
|
213 |
* |
|
214 |
* @throws DriverIOException |
|
215 |
*/ |
|
216 |
private FLyrRaster createLayer(String layerName, RasterDriver d, |
|
217 |
File f, IProjection proj, Extent ext) throws DriverException { |
|
218 |
RasterAdapter adapter = new RasterFileAdapter(f); |
|
219 |
adapter.setDriver(d); |
|
220 |
FLyrRaster capa = new FLyrRaster(); |
|
221 |
if (capa != null) { |
|
222 |
capa.setName(layerName); |
|
223 |
capa.setSource(adapter); |
|
224 |
capa.setProjection(proj); |
|
225 |
capa.setTempExtent(ext); |
|
226 |
capa.setExtentFlag(GeoRasterFile.ORDER); |
|
227 |
try { |
|
228 |
capa.load(); |
|
229 |
} catch (DriverIOException e) { |
|
230 |
throw new DriverException(e); |
|
231 |
} |
|
232 |
|
|
233 |
capa.setVisible(true); |
|
234 |
}else |
|
235 |
return null; |
|
236 |
return capa; |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Calcula un extent posible para la imagen a partir del extent de la vista. |
|
241 |
* En este caso centra la imagen en la vista. |
|
242 |
* @param w Ancho de la imagen |
|
243 |
* @param h Alto de la imagen |
|
244 |
* @return Extent para la imagen |
|
245 |
*/ |
|
246 |
protected Extent calcTempExtent(String file, ViewPort vp, IProjection proj){ |
|
247 |
|
|
248 |
//Obtenemos el ancho y alto de la imagen y obtenemos un extent a partir |
|
249 |
//del viewport. |
|
250 |
Extent tempExtent = null; |
|
251 |
GeoRasterFile grf = GeoRasterFile.openFile(proj, file); |
|
252 |
double w = grf.getWidth(); |
|
253 |
double h = grf.getHeight(); |
|
254 |
if(vp == null || vp.getAdjustedExtent() == null){ |
|
255 |
vp = new ViewPort(proj); |
|
256 |
Rectangle2D r2d = new Rectangle2D.Double(0, 0, w, h); |
|
257 |
vp.setExtent(r2d); |
|
258 |
tempExtent = new Extent(0, 0, w, h); |
|
259 |
}else |
|
260 |
tempExtent = new Extent(vp.getAdjustedExtent()); |
|
261 |
grf.close(); |
|
262 |
|
|
263 |
|
|
264 |
double ulX = 0D, ulY = 0D, lrX = 0D, lrY = 0D; |
|
265 |
if(w > h){ |
|
266 |
double widthView = tempExtent.maxX() - tempExtent.minX(); |
|
267 |
ulX = tempExtent.minX() + (widthView / 4); |
|
268 |
lrX = ulX + (widthView / 2); |
|
269 |
double newAlto = ((h * (widthView / 2)) / w); |
|
270 |
double centroY = tempExtent.minY()+((tempExtent.maxY() - tempExtent.minY())/2); |
|
271 |
ulY = centroY - (newAlto / 2); |
|
272 |
lrY = centroY + (newAlto / 2); |
|
273 |
}else{ |
|
274 |
double heightView = tempExtent.maxY() - tempExtent.minY(); |
|
275 |
ulY = tempExtent.minY() + (heightView / 4); |
|
276 |
lrY = ulY + (heightView / 2); |
|
277 |
double newAncho = ((w * (heightView / 2)) / h); |
|
278 |
double centroX = tempExtent.minX()+((tempExtent.maxX() - tempExtent.minX())/2); |
|
279 |
ulX = centroX - (newAncho / 2); |
|
280 |
lrX = centroX + (newAncho / 2); |
|
281 |
} |
|
282 |
return new Extent(ulX, ulY, lrX, lrY); |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Evento de pulsado del bot?n de seleccionar fichero |
|
287 |
* @param e |
|
288 |
*/ |
|
186 | 289 |
private void acceptButtonActionPerformed(ActionEvent e) { |
187 | 290 |
//Selector de Fichero que se quiere georeferenciar |
188 | 291 |
|
... | ... | |
210 | 313 |
try{ |
211 | 314 |
com.hardcode.driverManager.Driver driver = LayerFactory.getDM().getDriver("gvSIG Image Driver"); |
212 | 315 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
213 |
|
|
316 |
|
|
214 | 317 |
File fich = new File(fName); |
215 |
FLayer lyr = LayerFactory.createLayer("*"+fName.substring(fName.lastIndexOf("/")+1, fName.length()), |
|
216 |
(RasterDriver) driver, fich, proj, theView.getMapControl().getMapContext().getViewPort()); |
|
217 |
|
|
218 |
if (lyr != null) { |
|
219 |
lyr.setVisible(true); |
|
220 |
|
|
221 |
theView.getMapControl().getMapContext().getLayers() |
|
222 |
.addLayer(lyr); |
|
223 |
} |
|
318 |
|
|
319 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
|
320 |
|
|
321 |
//Calculamos el extent de la imagen que ser? cargada |
|
322 |
Extent ext = calcTempExtent( fName, |
|
323 |
viewPort, |
|
324 |
proj); |
|
325 |
|
|
326 |
SelectFilePanel.setLyrName("*"+fName.substring(fName.lastIndexOf("/")+1)); |
|
327 |
lyrRaster = this.createLayer("*"+fName.substring(fName.lastIndexOf("/")+1, fName.length()), |
|
328 |
(RasterDriver) driver, fich, proj, ext); |
|
329 |
|
|
330 |
theView.getMapControl().getMapContext().getLayers() |
|
331 |
.addLayer(lyrRaster); |
|
332 |
|
|
224 | 333 |
}catch(DriverLoadException exc){ |
225 | 334 |
NotificationManager.addError("No se pudo acceder a los drivers", exc); |
226 | 335 |
}catch(DriverException exc){ |
... | ... | |
233 | 342 |
|
234 | 343 |
} |
235 | 344 |
|
345 |
/** |
|
346 |
* @return Returns the lyrRaster. |
|
347 |
*/ |
|
348 |
public FLyrRaster getFLyrRaster() { |
|
349 |
return lyrRaster; |
|
350 |
} |
|
351 |
|
|
352 |
/** |
|
353 |
* @param lyrRaster The lyrRaster to set. |
|
354 |
*/ |
|
355 |
public void setFLyrRaster(FLyrRaster lyrRaster) { |
|
356 |
this.lyrRaster = lyrRaster; |
|
357 |
} |
|
236 | 358 |
|
237 | 359 |
/** |
238 | 360 |
* |
... | ... | |
260 | 382 |
|
261 | 383 |
} |
262 | 384 |
|
263 |
|
|
385 |
/** |
|
386 |
* @return Returns the fName. |
|
387 |
*/ |
|
388 |
public static String getLyrName() { |
|
389 |
return lyrName; |
|
390 |
} |
|
391 |
/** |
|
392 |
* @param name The fName to set. |
|
393 |
*/ |
|
394 |
public static void setLyrName(String name) { |
|
395 |
lyrName = name; |
|
396 |
} |
|
264 | 397 |
} |
Also available in: Unified diff