Revision 6214
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/GeoOperations.java | ||
---|---|---|
116 | 116 |
public void createGeorefFile(int widthPx, int heightPx, String file){ |
117 | 117 |
try{ |
118 | 118 |
File f = new File(file); |
119 |
String nameWorldFile = f.getPath().substring(0, f.getPath().lastIndexOf(".")) + getExtensionWorldFile(file);
|
|
119 |
String nameWorldFile = f.getPath().substring(0, f.getPath().lastIndexOf(".")) + GeoUtils.getWorldFileExtensionFromFileName(file);
|
|
120 | 120 |
if(createWorldFile) |
121 | 121 |
createWorldFile(affine, widthPx, heightPx, nameWorldFile); |
122 | 122 |
createRasterMetaFile(affine, widthPx, heightPx, nameWorldFile.substring(0, nameWorldFile.lastIndexOf("."))+".rmf"); |
... | ... | |
502 | 502 |
* @return String con la extensi�n del fichero de georreferenciaci�n dependiendo |
503 | 503 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld |
504 | 504 |
*/ |
505 |
private String getExtensionWorldFile(String file){ |
|
505 |
/*private String getExtensionWorldFile(String file){
|
|
506 | 506 |
String ext = file.substring(file.lastIndexOf(".") + 1).toLowerCase(); |
507 | 507 |
String extWorldFile = ".wld"; |
508 | 508 |
if(ext.equals("tif") || ext.equals("tiff")) |
... | ... | |
514 | 514 |
if(ext.equals("png")) |
515 | 515 |
extWorldFile = ".pgw"; |
516 | 516 |
return extWorldFile; |
517 |
} |
|
517 |
}*/
|
|
518 | 518 |
|
519 | 519 |
/** |
520 | 520 |
* Obtiene la matriz de transformaci?n |
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/utils/GeoUtils.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
import java.awt.geom.Point2D; |
22 | 22 |
import java.awt.geom.Rectangle2D; |
23 |
import java.io.BufferedReader; |
|
23 | 24 |
import java.io.File; |
24 | 25 |
import java.io.FileInputStream; |
25 | 26 |
import java.io.FileNotFoundException; |
26 | 27 |
import java.io.FileOutputStream; |
28 |
import java.io.FileReader; |
|
27 | 29 |
import java.io.IOException; |
28 | 30 |
import java.io.InputStream; |
29 | 31 |
import java.io.OutputStream; |
... | ... | |
242 | 244 |
* sucesivamente. |
243 | 245 |
* @param fName Nombre del fichero que se quiere hacer un backup. |
244 | 246 |
*/ |
245 |
public static void fileBackup(String fName){ |
|
246 |
File backupFile = new File(fName+"~"); |
|
247 |
public static String fileBackup(String fName){ |
|
248 |
File inFile = new File(fName); |
|
249 |
if(!inFile.exists()) |
|
250 |
return null; |
|
251 |
|
|
252 |
File backupFile = new File(fName +"~"); |
|
247 | 253 |
int nBackupFile = 1; |
248 | 254 |
while(backupFile.exists()){ |
249 |
backupFile = new File(fName+"~"+nBackupFile);
|
|
255 |
backupFile = new File(fName + "~"+nBackupFile);
|
|
250 | 256 |
nBackupFile ++; |
251 | 257 |
} |
252 |
File inFile = new File(fName); |
|
253 |
|
|
258 |
|
|
254 | 259 |
try{ |
255 | 260 |
InputStream in = new FileInputStream(inFile); |
256 | 261 |
OutputStream out = new FileOutputStream(backupFile); |
... | ... | |
263 | 268 |
in.close(); |
264 | 269 |
out.close(); |
265 | 270 |
}catch(FileNotFoundException exc){ |
266 |
System.err.print("RMF Backup isn't possible: File not found, "+fName); |
|
271 |
System.err.print("RMF Backup: File not found, "+fName); |
|
272 |
return null; |
|
267 | 273 |
}catch(IOException exc){ |
268 |
System.err.print("RMF Backup isn't possible: IOException, "+fName); |
|
274 |
System.err.print("RMF Backup: IOException, "+fName); |
|
275 |
return null; |
|
269 | 276 |
} |
277 |
return backupFile.getAbsolutePath(); |
|
270 | 278 |
} |
279 |
|
|
280 |
/** |
|
281 |
* A partir de una extensi?n de fichero devuelve la extensi?n del fichero |
|
282 |
* WorldFile que le corresponde. |
|
283 |
* @param fileExtension Extensi?n del fichero |
|
284 |
* @return Extensi?n del fichero de georreferenciaci?n |
|
285 |
*/ |
|
286 |
public static String getWorldFileExtension(String ext){ |
|
287 |
String extWorldFile = ".wld"; |
|
288 |
if(ext.equals("tif") || ext.equals("tiff")) |
|
289 |
extWorldFile = ".tfw"; |
|
290 |
if(ext.equals("jpeg") || ext.equals("jpg")) |
|
291 |
extWorldFile = ".jgw"; |
|
292 |
if(ext.equals("gif")) |
|
293 |
extWorldFile = ".gfw"; |
|
294 |
if(ext.equals("png")) |
|
295 |
extWorldFile = ".pgw"; |
|
296 |
return extWorldFile; |
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* A partir de un nombre de fichero devuelve la extensi?n del fichero |
|
301 |
* WorldFile que le corresponde. |
|
302 |
* @param file Nombre del fichero |
|
303 |
* @return Extensi?n del fichero de georreferenciaci?n |
|
304 |
*/ |
|
305 |
public static String getWorldFileExtensionFromFileName(String file){ |
|
306 |
String ext = file.substring(file.lastIndexOf(".") + 1).toLowerCase(); |
|
307 |
return GeoUtils.getWorldFileExtension(ext); |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* Obtiene la codificaci?n del fichero XML |
|
312 |
* @param file Nombre del fichero XML |
|
313 |
* @return Codificaci?n |
|
314 |
*/ |
|
315 |
public static String readFileEncoding(String file){ |
|
316 |
FileReader fr; |
|
317 |
String encoding = null; |
|
318 |
try |
|
319 |
{ |
|
320 |
fr = new FileReader(file); |
|
321 |
BufferedReader br = new BufferedReader(fr); |
|
322 |
char[] buffer = new char[100]; |
|
323 |
br.read(buffer); |
|
324 |
StringBuffer st = new StringBuffer(new String(buffer)); |
|
325 |
String searchText = "encoding=\""; |
|
326 |
int index = st.indexOf(searchText); |
|
327 |
if (index>-1) { |
|
328 |
st.delete(0, index+searchText.length()); |
|
329 |
encoding = st.substring(0, st.indexOf("\"")); |
|
330 |
} |
|
331 |
fr.close(); |
|
332 |
} catch(FileNotFoundException ex) { |
|
333 |
ex.printStackTrace(); |
|
334 |
} catch (IOException e) { |
|
335 |
e.printStackTrace(); |
|
336 |
} |
|
337 |
return encoding; |
|
338 |
} |
|
271 | 339 |
} |
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/wizards/GeoRasterWizard.java | ||
---|---|---|
24 | 24 |
import java.awt.GridBagLayout; |
25 | 25 |
import java.awt.event.ActionEvent; |
26 | 26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.io.BufferedReader; |
|
28 |
import java.io.BufferedWriter; |
|
27 | 29 |
import java.io.File; |
30 |
import java.io.FileInputStream; |
|
31 |
import java.io.FileNotFoundException; |
|
32 |
import java.io.FileWriter; |
|
33 |
import java.io.IOException; |
|
34 |
import java.io.InputStreamReader; |
|
35 |
import java.io.UnsupportedEncodingException; |
|
28 | 36 |
|
29 | 37 |
import javax.swing.JButton; |
30 | 38 |
import javax.swing.JCheckBox; |
... | ... | |
236 | 244 |
if (PluginServices.getMainFrame() == null) { |
237 | 245 |
((JDialog) (getParent().getParent().getParent() |
238 | 246 |
.getParent())).dispose(); |
239 |
} else { |
|
240 |
//Hacemos un backup del fichero RMF antes que nada |
|
241 |
GeoUtils.fileBackup(fName.substring(0, fName.lastIndexOf(".")) + ".rmf"); |
|
242 |
|
|
247 |
} else { |
|
243 | 248 |
//Creamos la capa y la cargamos |
244 | 249 |
IProjection proj = this.getPProyection().getCurProj(); |
245 | 250 |
try{ |
... | ... | |
268 | 273 |
//Asigna el nombre de la capa con el marcador * |
269 | 274 |
this.setLyrName("*"+fName.substring(fName.lastIndexOf(File.separator)+1)); |
270 | 275 |
|
276 |
//Antes de crear la capa si tiene georreferenciaci?n por .rmf la reseteamos |
|
277 |
if(!this.getCbUseGeoref().isSelected()) |
|
278 |
removeGeoref(fName); |
|
279 |
|
|
271 | 280 |
//Crea la capa |
272 | 281 |
lyrGeoRaster = GeoLayerFactory.createLayer(getLyrName(), |
273 | 282 |
(RasterDriver) driver, |
... | ... | |
297 | 306 |
} |
298 | 307 |
|
299 | 308 |
/** |
309 |
* Elimina la georrefenciaci?n externa de la imagen antes de comenzar a georreferenciar |
|
310 |
* @param fName Nombre del fichero a georreferenciar. |
|
311 |
*/ |
|
312 |
private void removeGeoref(String fName){ |
|
313 |
String rmf = fName.substring(0, fName.lastIndexOf(".")) + ".rmf"; |
|
314 |
File file = new File(rmf); |
|
315 |
String ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length()); |
|
316 |
|
|
317 |
//Hacemos un backup del fichero RMF |
|
318 |
String backupRmf = GeoUtils.fileBackup(rmf); |
|
319 |
File backupFile = new File(backupRmf); |
|
320 |
|
|
321 |
//Eliminamos el fichero rmf y lo volvemos a crear sin la informaci?n de georreferenciaci?n |
|
322 |
if(file.exists()){ |
|
323 |
file.delete(); |
|
324 |
try{ |
|
325 |
file.createNewFile(); |
|
326 |
String encoding = GeoUtils.readFileEncoding(backupRmf); |
|
327 |
|
|
328 |
FileInputStream fis = new FileInputStream(backupRmf); |
|
329 |
BufferedReader inReader = null; |
|
330 |
BufferedWriter outWriter = null; |
|
331 |
|
|
332 |
if(encoding != null) |
|
333 |
inReader = new BufferedReader(new InputStreamReader(fis, encoding)); |
|
334 |
else |
|
335 |
inReader = new BufferedReader(new InputStreamReader(fis, "ISO-8859-15")); |
|
336 |
outWriter = new BufferedWriter(new FileWriter(file, false)); |
|
337 |
|
|
338 |
String line = null; |
|
339 |
boolean write = true; |
|
340 |
while((line = inReader.readLine()) != null) { |
|
341 |
if(line.startsWith("<FLyrGeoRaster ")) |
|
342 |
write = false; |
|
343 |
if(write) |
|
344 |
outWriter.write(line+"\n"); |
|
345 |
if(line.startsWith("</FLyrGeoRaster>")) |
|
346 |
write = true; |
|
347 |
} |
|
348 |
inReader.close(); |
|
349 |
outWriter.close(); |
|
350 |
|
|
351 |
}catch(FileNotFoundException exc){ |
|
352 |
System.err.print("RMF Backup: File not found, "+fName); |
|
353 |
return; |
|
354 |
}catch(IOException exc){ |
|
355 |
System.err.print("RMF Backup: IOException, "+fName); |
|
356 |
return; |
|
357 |
} |
|
358 |
|
|
359 |
} |
|
360 |
|
|
361 |
//Si tiene worldfile lo renombramos |
|
362 |
String georef = fName.substring(0, fName.lastIndexOf(".")) + GeoUtils.getWorldFileExtensionFromFileName(fName); |
|
363 |
File worldFile = new File(georef); |
|
364 |
if(worldFile.exists()){ |
|
365 |
GeoUtils.fileBackup(georef); |
|
366 |
worldFile.delete(); |
|
367 |
} |
|
368 |
|
|
369 |
} |
|
370 |
|
|
371 |
/** |
|
300 | 372 |
* M?todo que se ejecuta al pulsar el bot?n de aceptar. En este caso asignamos el |
301 | 373 |
* extent calculado desde la vista si el checkbox no est? marcado y lanzaremos el |
302 | 374 |
* dialogo de georeferenciaci?n. El resto del trabajo lo realiza la clase AddLayer. |
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/selectPoints/SelectPointsPanel.java | ||
---|---|---|
35 | 35 |
import javax.swing.JButton; |
36 | 36 |
import javax.swing.JOptionPane; |
37 | 37 |
import javax.swing.JPanel; |
38 |
import javax.swing.JToggleButton; |
|
38 | 39 |
|
39 | 40 |
import org.gvsig.georeferencing.GeoreferencingToolsModule; |
40 | 41 |
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog; |
... | ... | |
42 | 43 |
import org.gvsig.georeferencing.gui.pointsTable.TableControlerPanel; |
43 | 44 |
|
44 | 45 |
import com.iver.andami.PluginServices; |
45 |
import com.iver.andami.ui.mdiFrame.JToggleButton; |
|
46 |
import com.iver.cit.gvsig.fmap.FMap; |
|
47 | 46 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
48 | 47 |
import com.iver.cit.gvsig.gui.View; |
49 | 48 |
|
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/dialog/GeoreferencingDialog.java | ||
---|---|---|
36 | 36 |
import javax.swing.JInternalFrame; |
37 | 37 |
import javax.swing.JOptionPane; |
38 | 38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JToggleButton; |
|
39 | 40 |
import javax.swing.filechooser.FileFilter; |
40 | 41 |
import javax.swing.table.DefaultTableModel; |
41 | 42 |
|
... | ... | |
61 | 62 |
import org.gvsig.georeferencing.utils.StackZoom; |
62 | 63 |
|
63 | 64 |
import com.iver.andami.PluginServices; |
64 |
import com.iver.andami.ui.mdiFrame.JToggleButton; |
|
65 | 65 |
import com.iver.cit.gvsig.fmap.DriverException; |
66 | 66 |
import com.iver.cit.gvsig.fmap.MapControl; |
67 | 67 |
import com.iver.cit.gvsig.fmap.ViewPort; |
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/dialog/DialogButtons.java | ||
---|---|---|
25 | 25 |
import javax.swing.JPanel; |
26 | 26 |
|
27 | 27 |
import com.iver.andami.PluginServices; |
28 |
import com.iver.andami.ui.mdiFrame.JToggleButton; |
|
29 |
import com.iver.cit.gvsig.gui.View; |
|
30 | 28 |
|
31 | 29 |
/** |
32 | 30 |
* Control para el manejo de tablas. No contiene eventos, estos deben |
trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/pointsTable/TablePanelButtons.java | ||
---|---|---|
23 | 23 |
import javax.swing.ImageIcon; |
24 | 24 |
import javax.swing.JButton; |
25 | 25 |
import javax.swing.JPanel; |
26 |
import javax.swing.JToggleButton; |
|
26 | 27 |
|
27 | 28 |
import com.iver.andami.PluginServices; |
28 |
import com.iver.andami.ui.mdiFrame.JToggleButton; |
|
29 |
import com.iver.cit.gvsig.gui.View; |
|
30 | 29 |
|
31 | 30 |
/** |
32 | 31 |
* Control para el manejo de tablas. No contiene eventos, estos deben |
Also available in: Unified diff