Revision 4436
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/util/DefaultFileUtils.java | ||
---|---|---|
33 | 33 |
import java.io.IOException; |
34 | 34 |
import java.io.InputStream; |
35 | 35 |
import java.io.OutputStream; |
36 |
import java.net.URI; |
|
36 | 37 |
import java.security.MessageDigest; |
37 | 38 |
import java.security.NoSuchAlgorithmException; |
38 | 39 |
import java.text.NumberFormat; |
39 | 40 |
import java.util.ArrayList; |
40 | 41 |
|
42 |
import org.apache.commons.lang3.StringUtils; |
|
43 |
|
|
41 | 44 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
42 | 45 |
import org.gvsig.fmap.dal.coverage.util.FileUtils; |
43 | 46 |
import org.gvsig.fmap.dal.coverage.util.PropertyEvent; |
... | ... | |
45 | 48 |
|
46 | 49 |
|
47 | 50 |
/** |
48 |
* Utilities for files, directories and file names
|
|
51 |
* Utilities for files, directories and file names |
|
49 | 52 |
* |
50 | 53 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
51 | 54 |
*/ |
52 | 55 |
public class DefaultFileUtils implements FileUtils { |
53 |
/** |
|
54 |
* Copia de ficheros |
|
55 |
* @param pathOrig Ruta de origen |
|
56 |
* @param pathDst Ruta de destino. |
|
57 |
*/ |
|
56 |
|
|
58 | 57 |
public void copyFile(String pathOrig, String pathDst) throws FileNotFoundException, IOException { |
59 | 58 |
InputStream in; |
60 | 59 |
OutputStream out; |
... | ... | |
74 | 73 |
String file = new File(pathOrig).getName(); |
75 | 74 |
if (dest.isDirectory()) |
76 | 75 |
pathDst += file; |
77 |
|
|
76 |
|
|
78 | 77 |
dest = new File(pathDst); |
79 | 78 |
if(!dest.exists()) |
80 | 79 |
dest.createNewFile(); |
... | ... | |
92 | 91 |
out.close(); |
93 | 92 |
} |
94 | 93 |
|
95 |
/** |
|
96 |
* Crea un fichero de georeferenciaci?n (world file) para un dataset |
|
97 |
* determinado |
|
98 |
* @param fileName Nombre completo del fichero de raster |
|
99 |
* @param Extent |
|
100 |
* @param pxWidth Ancho en p?xeles |
|
101 |
* @param pxHeight Alto en p?xeles |
|
102 |
* @return |
|
103 |
* @throws IOException |
|
104 |
*/ |
|
105 | 94 |
public void createWorldFile(String fileName, Extent ext, int pxWidth, int pxHeight) throws IOException { |
106 | 95 |
File tfw = null; |
107 | 96 |
|
... | ... | |
124 | 113 |
dos.close(); |
125 | 114 |
} |
126 | 115 |
|
127 |
/** |
|
128 |
* Crea un fichero de georeferenciaci?n (world file) para un dataset |
|
129 |
* determinado |
|
130 |
* @param fileName Nombre completo del fichero de raster |
|
131 |
* @param AffineTransform |
|
132 |
* @param pxWidth Ancho en p?xeles |
|
133 |
* @param pxHeight Alto en p?xeles |
|
134 |
* @return |
|
135 |
* @throws IOException |
|
136 |
*/ |
|
137 | 116 |
public void createWorldFile(String fileName, AffineTransform at, int pxWidth, int pxHeight) throws IOException { |
138 | 117 |
File tfw = null; |
139 | 118 |
|
... | ... | |
156 | 135 |
dos.close(); |
157 | 136 |
} |
158 | 137 |
|
159 |
/** |
|
160 |
* Formatea en forma de cadena un tama?o dado en bytes. El resultado ser? una |
|
161 |
* cadena con GB, MB, KB y B |
|
162 |
* @param size tama?o a formatear |
|
163 |
* @return cadena con la cantidad formateada |
|
164 |
*/ |
|
165 | 138 |
public String formatFileSize(long size) { |
166 | 139 |
double bytes = size; |
167 | 140 |
double kBytes = 0.0; |
... | ... | |
208 | 181 |
return texto + " (" + numberFormat.format(bytes) + " bytes)"; |
209 | 182 |
} |
210 | 183 |
|
211 |
/** |
|
212 |
* Obtiene la extensi?n del fichero a partir de su nombre. |
|
213 |
* @param file Nombre o ruta del fichero |
|
214 |
* @return Cadena con la extensi?n que representa el tipo de fichero. Devuelve |
|
215 |
* null si no tiene extension. |
|
216 |
*/ |
|
217 | 184 |
public String getExtensionFromFileName(String file) { |
218 | 185 |
return file.substring(file.lastIndexOf(".") + 1).toLowerCase(); |
219 | 186 |
} |
220 | 187 |
|
221 |
/** |
|
222 |
* Obtiene el nombre de fichero sin la extensi?n. |
|
223 |
* @param file Nombre o ruta del fichero |
|
224 |
* @return Cadena con la extensi?n que representa el tipo de fichero. Si no |
|
225 |
* tiene extensi?n devuelve el mismo fichero de entrada |
|
226 |
*/ |
|
227 | 188 |
public String getNameWithoutExtension(String file) { |
228 | 189 |
if (file == null) |
229 | 190 |
return null; |
... | ... | |
234 | 195 |
return file; |
235 | 196 |
} |
236 | 197 |
|
237 |
/** |
|
238 |
* Obtiene el nombre de fichero sin la extensi?n ni la ruta. |
|
239 |
* @param file Ruta del fichero |
|
240 |
* @return Cadena que representa el nombre del fichero sin extensi?n ni path de directorios |
|
241 |
*/ |
|
242 | 198 |
public String getFileNameFromCanonical(String file) { |
243 | 199 |
if (file == null) |
244 | 200 |
return null; |
... | ... | |
254 | 210 |
return file; |
255 | 211 |
} |
256 | 212 |
|
257 |
/** |
|
258 |
* Obtiene el ?ltimo trozo de la cadena a partir de los caracteres que |
|
259 |
* coincidan con el patr?n. En caso de que el patr?n no exista en la cadena |
|
260 |
* devuelve esta completa |
|
261 |
* @param string |
|
262 |
* @param pattern |
|
263 |
* @return |
|
264 |
*/ |
|
265 | 213 |
public String getLastPart(String string, String pattern) { |
266 | 214 |
int n = string.lastIndexOf(pattern); |
267 | 215 |
if (n > 0) |
... | ... | |
269 | 217 |
return string; |
270 | 218 |
} |
271 | 219 |
|
272 |
/** |
|
273 |
* Obtiene la codificaci?n de un fichero XML |
|
274 |
* @param file Nombre del fichero XML |
|
275 |
* @return Codificaci?n |
|
276 |
*/ |
|
277 | 220 |
public String readFileEncoding(String file) { |
278 | 221 |
FileReader fr; |
279 | 222 |
String encoding = null; |
... | ... | |
298 | 241 |
return encoding; |
299 | 242 |
} |
300 | 243 |
|
301 |
/** |
|
302 |
* Obtiene el nombre del fichero RMF a partir del nombre del fichero. Si el |
|
303 |
* nombre del fichero tiene una extensi?n esta llamada sustituir? la extensi?n |
|
304 |
* existente por .rmf. Si el fichero pasado no tiene extensi?n esta llamada |
|
305 |
* a?adir? .rm al final. |
|
306 |
* @param fileName Nombre del fichero raster de origen |
|
307 |
* @return Nombre del fichero rmf asociado al raster. |
|
308 |
*/ |
|
309 | 244 |
public String getRMFNameFromFileName(String fileName) { |
310 | 245 |
return getNameWithoutExtension(fileName) + ".rmf"; |
311 | 246 |
} |
312 |
|
|
247 |
|
|
313 | 248 |
/** |
314 | 249 |
* Recursive directory delete. |
315 | 250 |
* @param f |
... | ... | |
322 | 257 |
files[i].delete(); |
323 | 258 |
} |
324 | 259 |
} |
325 |
|
|
260 |
|
|
326 | 261 |
//******* Servicio de directorios temporales ************** |
327 |
|
|
262 |
|
|
328 | 263 |
/** |
329 | 264 |
* Directorio temporal para la cach?. Si gastamos el mismo que andami este se ocupar? de gestionar su |
330 | 265 |
* destrucci?n al cerrar gvSIG. |
331 | 266 |
*/ |
332 | 267 |
private String tempCacheDirectoryPath = System.getProperty("java.io.tmpdir") |
333 | 268 |
+ File.separator + "tmp-andami"; |
334 |
|
|
335 |
/** |
|
336 |
* Elimina los ficheros del directorio temporal. Realizamos esta acci?n al |
|
337 |
* levantar la librer?a. |
|
338 |
*/ |
|
269 |
|
|
339 | 270 |
public void cleanUpTempFiles() { |
340 | 271 |
try { |
341 | 272 |
File tempDirectory = new File(tempCacheDirectoryPath); |
... | ... | |
353 | 284 |
} |
354 | 285 |
} |
355 | 286 |
|
356 |
/** |
|
357 |
* Esta funci?n crea el directorio para temporales y devuelve el manejador |
|
358 |
* del directorio |
|
359 |
* @return |
|
360 |
*/ |
|
361 | 287 |
public File getTemporalFile() { |
362 | 288 |
File tempDirectory = new File(tempCacheDirectoryPath); |
363 | 289 |
if (!tempDirectory.exists()) |
364 | 290 |
tempDirectory.mkdir(); |
365 | 291 |
return tempDirectory; |
366 | 292 |
} |
367 |
|
|
368 |
/** |
|
369 |
* Esta funci?n crea el directorio para temporales y devuelve la ruta de este |
|
370 |
* @return |
|
371 |
*/ |
|
293 |
|
|
372 | 294 |
public String getTemporalPath() { |
373 | 295 |
return getTemporalFile().getAbsolutePath(); |
374 | 296 |
} |
... | ... | |
378 | 300 |
* @see org.gvsig.fmap.dal.coverage.util.FileUtils#getFormatedRasterFileName(java.lang.String) |
379 | 301 |
*/ |
380 | 302 |
public String getFormatedRasterFileName(String name) { |
381 |
if(name.startsWith("PG:host=")) { |
|
382 |
String newName = ""; |
|
383 |
String schema = null; |
|
384 |
String table = null; |
|
385 |
int index = name.indexOf(" schema='") + 8; |
|
386 |
if(index != -1) { |
|
387 |
try { |
|
388 |
schema = name.substring(index + 1, name.indexOf("'", index + 1)); |
|
389 |
newName += schema + "."; |
|
390 |
} catch (StringIndexOutOfBoundsException e) { |
|
391 |
} |
|
392 |
} |
|
393 |
index = name.indexOf(" table='") + 7; |
|
394 |
if(index != -1) { |
|
395 |
try { |
|
396 |
table = name.substring(index + 1, name.indexOf("'", index + 1)); |
|
397 |
newName += table; |
|
398 |
} catch (StringIndexOutOfBoundsException e) { |
|
399 |
} |
|
400 |
} |
|
401 |
return newName; |
|
402 |
} |
|
403 |
return name; |
|
303 |
throw new UnsupportedOperationException("Deprecated (name = '"+name+"')"); |
|
304 |
|
|
305 |
// if(name.startsWith("PG:host=")) { |
|
306 |
// String newName = ""; |
|
307 |
// String schema = null; |
|
308 |
// String table = null; |
|
309 |
// int index = name.indexOf(" schema='") + 8; |
|
310 |
// if(index != -1) { |
|
311 |
// try { |
|
312 |
// schema = name.substring(index + 1, name.indexOf("'", index + 1)); |
|
313 |
// newName += schema + "."; |
|
314 |
// } catch (StringIndexOutOfBoundsException e) { |
|
315 |
// } |
|
316 |
// } |
|
317 |
// index = name.indexOf(" table='") + 7; |
|
318 |
// if(index != -1) { |
|
319 |
// try { |
|
320 |
// table = name.substring(index + 1, name.indexOf("'", index + 1)); |
|
321 |
// newName += table; |
|
322 |
// } catch (StringIndexOutOfBoundsException e) { |
|
323 |
// } |
|
324 |
// } |
|
325 |
// return newName; |
|
326 |
// } |
|
327 |
// return name; |
|
404 | 328 |
} |
405 |
|
|
329 |
|
|
406 | 330 |
public String convertPathToMD5(String path) throws NoSuchAlgorithmException { |
407 | 331 |
MessageDigest md = java.security.MessageDigest.getInstance("MD5"); |
408 | 332 |
md.update(path.getBytes()); |
409 | 333 |
return convertToHex(md.digest()); |
410 | 334 |
} |
411 |
|
|
335 |
|
|
412 | 336 |
/** |
413 | 337 |
* Converts an array of bytes to hexadecimal string |
414 | 338 |
* @param data |
415 | 339 |
* @return |
416 | 340 |
*/ |
417 |
private String convertToHex(byte[] data) {
|
|
341 |
private String convertToHex(byte[] data) { |
|
418 | 342 |
StringBuffer buf = new StringBuffer(); |
419 |
for (int i = 0; i < data.length; i++) {
|
|
343 |
for (int i = 0; i < data.length; i++) { |
|
420 | 344 |
int halfbyte = (data[i] >>> 4) & 0x0F; |
421 | 345 |
int two_halfs = 0; |
422 |
do {
|
|
423 |
if ((0 <= halfbyte) && (halfbyte <= 9))
|
|
346 |
do { |
|
347 |
if ((0 <= halfbyte) && (halfbyte <= 9)) |
|
424 | 348 |
buf.append((char) ('0' + halfbyte)); |
425 |
else
|
|
349 |
else |
|
426 | 350 |
buf.append((char) ('a' + (halfbyte - 10))); |
427 | 351 |
halfbyte = data[i] & 0x0F; |
428 | 352 |
} while(two_halfs++ < 1); |
429 |
}
|
|
353 |
} |
|
430 | 354 |
return buf.toString(); |
431 | 355 |
} |
432 | 356 |
|
433 | 357 |
//******* Servicio de nombres de capas ?nicos ************** |
434 | 358 |
/** |
435 | 359 |
* Contador global de las capas generadas para raster. Hay que contar con que esta |
436 |
* clase es un singleton desde el manager. Si hay varias instanciaciones layerCount
|
|
437 |
* dar? valores erroneos.
|
|
360 |
* clase es un singleton desde el manager. Si hay varias instanciaciones layerCount |
|
361 |
* dar? valores erroneos. |
|
438 | 362 |
*/ |
439 | 363 |
private int layerCount = 1; |
440 |
private ArrayList<PropertyListener>
|
|
364 |
private ArrayList<PropertyListener> |
|
441 | 365 |
propetiesListeners = new ArrayList<PropertyListener>(); |
442 | 366 |
|
443 |
/** |
|
444 |
* La gesti?n de nombres ?nicos en la generaci?n de capas se lleva de forma |
|
445 |
* autom?tica. Cuando alguien crea una capa nueva, si esta no tiene nombre especifico, |
|
446 |
* obtiene su nombre mediante este m?todo. La siguiente vez que se llame dar? un nombre |
|
447 |
* distinto. El nombre de la capa ser? NewLayer_ seguido de un contador de actualizaci?n |
|
448 |
* autom?tica cada vez que se usa. |
|
449 |
* @return Nombre ?nico para la capa. |
|
450 |
*/ |
|
451 | 367 |
public String usesOnlyLayerName() { |
452 | 368 |
String oldValue = getOnlyLayerName(); |
453 | 369 |
String newValue = "NewLayer_" + (++layerCount); |
... | ... | |
457 | 373 |
return newValue; |
458 | 374 |
} |
459 | 375 |
|
460 |
/** |
|
461 |
* Obtiene el nombre ?nico de la siguiente capa sin actualizar el contador. Es |
|
462 |
* solo para consulta. La siguiente vez que se llama a getOnlyLayerName o usesOnlyLayerName |
|
463 |
* devolver? el mismo nomnbre. |
|
464 |
* @return Nombre ?nico para la capa. |
|
465 |
*/ |
|
466 | 376 |
public String getOnlyLayerName() { |
467 | 377 |
return "NewLayer_" + layerCount; |
468 | 378 |
} |
469 | 379 |
|
470 |
/** |
|
471 |
* A?adir un listener a la lista de eventos |
|
472 |
* @param listener |
|
473 |
*/ |
|
474 | 380 |
public void addOnlyLayerNameListener(PropertyListener listener) { |
475 | 381 |
if (!propetiesListeners.contains(listener)) |
476 | 382 |
propetiesListeners.add(listener); |
477 | 383 |
} |
478 | 384 |
|
479 |
/** |
|
480 |
* Elimina un listener de la lista de eventos |
|
481 |
* @param listener |
|
482 |
*/ |
|
483 | 385 |
public void removeOnlyLayerNameListener(PropertyListener listener) { |
484 | 386 |
for (int i = 0; i < propetiesListeners.size(); i++) |
485 | 387 |
if(propetiesListeners.get(i) == listener) |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/util/DefaultRasterUtils.java | ||
---|---|---|
48 | 48 |
public class DefaultRasterUtils implements RasterUtils { |
49 | 49 |
public static final int MAX_BYTE_BIT_VALUE = 255; |
50 | 50 |
public static final int MAX_SHORT_BIT_VALUE = 65535; |
51 |
|
|
51 |
|
|
52 | 52 |
public boolean loadInMemory(RasterDataStore datasource) { |
53 | 53 |
return (datasource.getFileSize() < (RasterLibrary.cacheSize * 1048576)); |
54 | 54 |
} |
55 |
|
|
56 |
public boolean isBufferTooBig(double[] coords, int bands) {
|
|
55 |
|
|
56 |
public boolean isBufferTooBig(double[] coords, int bands) { |
|
57 | 57 |
int w = (int)Math.abs(coords[2] - coords[0]); |
58 | 58 |
int h = (int)Math.abs(coords[3] - coords[1]); |
59 | 59 |
|
60 |
long windowSize = w * h * bands;
|
|
60 |
long windowSize = w * h * bands; |
|
61 | 61 |
return (windowSize > (RasterLibrary.cacheSize * 1048576)); |
62 |
}
|
|
63 |
|
|
62 |
} |
|
63 |
|
|
64 | 64 |
public boolean isBufferTooBig(double[] coords, double resolution, int bands) { |
65 | 65 |
double wPx = (coords[0] - coords[2]) / resolution; |
66 | 66 |
double hPx = (coords[1] - coords[3]) / resolution; |
67 | 67 |
return isBufferTooBig(new double[]{0, 0, wPx, hPx}, bands); |
68 |
}
|
|
68 |
} |
|
69 | 69 |
|
70 | 70 |
// --------------------------------------------------------------- |
71 | 71 |
// TIPOS DE DATOS |
... | ... | |
158 | 158 |
str.append(list[i] + ","); |
159 | 159 |
return str.toString(); |
160 | 160 |
} |
161 |
|
|
161 |
|
|
162 | 162 |
// --------------------------------------------------------------- |
163 | 163 |
// CONVERSI?N DE COORDENADAS |
164 | 164 |
|
... | ... | |
221 | 221 |
return true; |
222 | 222 |
return false; |
223 | 223 |
} |
224 |
|
|
224 |
|
|
225 | 225 |
public Extent intersection(Extent e1, Extent e2) { |
226 | 226 |
if( (e1.getMin().getX() > e2.getMax().getX()) || |
227 | 227 |
(e1.getMax().getX() < e2.getMin().getX()) || |
... | ... | |
258 | 258 |
} |
259 | 259 |
|
260 | 260 |
public boolean isInside(Extent e1, Extent e2) { |
261 |
return ((e1.getMin().getX() >= e2.getMin().getX()) &&
|
|
262 |
(e1.getMin().getY() >= e2.getMin().getY()) &&
|
|
263 |
(e1.getMax().getX() <= e2.getMax().getX()) &&
|
|
261 |
return ((e1.getMin().getX() >= e2.getMin().getX()) && |
|
262 |
(e1.getMin().getY() >= e2.getMin().getY()) && |
|
263 |
(e1.getMax().getX() <= e2.getMax().getX()) && |
|
264 | 264 |
(e1.getMax().getY() <= e2.getMax().getY())); |
265 | 265 |
} |
266 |
|
|
266 |
|
|
267 | 267 |
public boolean isInside(Point2D p1, Extent e1) { |
268 | 268 |
return ((p1.getX() >= e1.getMin().getX()) && (p1.getX() <= e1.getMax().getX()) && (p1.getY() >= e1.getMin().getY())) && (p1.getY() <= e1.getMax().getY()); |
269 | 269 |
} |
... | ... | |
321 | 321 |
/** |
322 | 322 |
* Gets the exception trace |
323 | 323 |
* @param e |
324 |
* @return |
|
324 |
* @return the exception trace
|
|
325 | 325 |
*/ |
326 | 326 |
public String getTrace(Exception e) { |
327 | 327 |
Throwable throwable = e; |
... | ... | |
330 | 330 |
for (int i = 0; i < elemList.length; i++) { |
331 | 331 |
r += " !!!-" + elemList[i].toString() + "\n"; |
332 | 332 |
} |
333 |
|
|
333 |
|
|
334 | 334 |
while(throwable.getCause() != null) { |
335 | 335 |
elemList = throwable.getCause().getStackTrace(); |
336 | 336 |
for (int i = 0; i < elemList.length; i++) { |
... | ... | |
340 | 340 |
} |
341 | 341 |
return r; |
342 | 342 |
} |
343 |
|
|
343 |
|
|
344 | 344 |
public String formatTime(long time) { |
345 | 345 |
int days = 0; |
346 | 346 |
int hours = 0; |
... | ... | |
400 | 400 |
} |
401 | 401 |
return coordPx; |
402 | 402 |
} |
403 |
|
|
403 |
|
|
404 | 404 |
public Extent calculateAdjustedView(Extent extToAdj, Extent imgExt) { |
405 | 405 |
double vx = extToAdj.minX(); |
406 | 406 |
double vy = extToAdj.minY(); |
... | ... | |
424 | 424 |
|
425 | 425 |
public Extent calculateAdjustedView(Extent extToAdj, AffineTransform at, double w, double h) { |
426 | 426 |
// Obtenemos los cuatro puntos de la petici?n de origen |
427 |
Point2D ul = new Point2D.Double(extToAdj.getULX(), extToAdj.getULY()); |
|
428 |
Point2D lr = new Point2D.Double(extToAdj.getLRX(), extToAdj.getLRY()); |
|
427 |
Point2D src_ul = new Point2D.Double(extToAdj.getULX(), extToAdj.getULY()); |
|
428 |
Point2D src_lr = new Point2D.Double(extToAdj.getLRX(), extToAdj.getLRY()); |
|
429 |
Point2D ul = new Point2D.Double(); |
|
430 |
Point2D lr = new Point2D.Double(); |
|
429 | 431 |
|
430 | 432 |
// Los convertimos a coordenadas pixel con la matriz de transformaci?n |
431 | 433 |
try { |
432 |
at.inverseTransform(ul, ul); |
|
433 |
at.inverseTransform(lr, lr); |
|
434 |
at.inverseTransform(src_ul, ul);
|
|
435 |
at.inverseTransform(src_lr, lr);
|
|
434 | 436 |
} catch (NoninvertibleTransformException e) { |
435 | 437 |
return extToAdj; |
436 | 438 |
} |
... | ... | |
455 | 457 |
lr.setLocation(lr.getX(), h); |
456 | 458 |
|
457 | 459 |
// Lo convertimos a coordenadas reales nuevamente |
458 |
at.transform(ul, ul); |
|
459 |
at.transform(lr, lr); |
|
460 |
return new ExtentImpl(ul, lr); |
|
460 |
Point2D real_ul = new Point2D.Double(); |
|
461 |
Point2D real_lr = new Point2D.Double(); |
|
462 |
at.transform(ul, real_ul); |
|
463 |
at.transform(lr, real_lr); |
|
464 |
return new ExtentImpl(real_ul, real_lr); |
|
461 | 465 |
} |
462 | 466 |
|
463 | 467 |
public void saveGeoInfo(String outRmf, AffineTransform at, Point2D dim) throws IOException { |
... | ... | |
466 | 470 |
manager.addClient(ser3); |
467 | 471 |
manager.write(); |
468 | 472 |
} |
469 |
|
|
473 |
|
|
470 | 474 |
/** |
471 | 475 |
* Obtiene el extent m?ximo de todas las ROIs pasadas por par?metro. |
472 | 476 |
* @param rois Lista de ROIs para calcular la extensi?n m?xima que ocupan |
... | ... | |
494 | 498 |
} |
495 | 499 |
return RasterLocator.getManager().getDataStructFactory().createExtent(minx, miny, maxx, maxy); |
496 | 500 |
} |
497 |
|
|
498 |
|
|
501 |
|
|
502 |
|
|
499 | 503 |
/** |
500 | 504 |
* Convierte un histograma al rango de valores de RGB, en pocas palabras |
501 | 505 |
* aplica una operacion 0xff a cada pixel para quitar los numeros negativos |
... | ... | |
507 | 511 |
return null; |
508 | 512 |
|
509 | 513 |
BufferHistogramImpl histImp = (BufferHistogramImpl)histogram; |
510 |
|
|
514 |
|
|
511 | 515 |
if (histImp.getDataType() != Buffer.TYPE_BYTE) |
512 | 516 |
return histogram; |
513 | 517 |
|
... | ... | |
539 | 543 |
|
540 | 544 |
double mins[] = new double[histImp.getNumBands()]; |
541 | 545 |
double maxs[] = new double[histImp.getNumBands()]; |
542 |
|
|
546 |
|
|
543 | 547 |
for (int i = 0; i < mins.length; i++) { |
544 | 548 |
mins[i] = 0; |
545 | 549 |
maxs[i] = 255; |
... | ... | |
551 | 555 |
|
552 | 556 |
return histogramNew; |
553 | 557 |
} |
554 |
|
|
558 |
|
|
555 | 559 |
public void copyToBuffer(Buffer bufResult, Extent tileExtent, |
556 | 560 |
Buffer buf, Extent ex, double rel, boolean hasAlphaBand) { |
557 | 561 |
double distx = Math.abs(ex.getULX() - tileExtent.getULX()); |
... | ... | |
590 | 594 |
} |
591 | 595 |
} |
592 | 596 |
} |
593 |
|
|
597 |
|
|
594 | 598 |
//En el resto de casos no se usa banda de transparencia sino que las zonas del tile fuera de la imagen |
595 | 599 |
//se inicializaron previamente a NoData |
596 |
|
|
600 |
|
|
597 | 601 |
if(bufResult.getDataType() == Buffer.TYPE_SHORT) { |
598 | 602 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
599 | 603 |
for (int i = distpxy; (i < bufResult.getHeight() && (i - distpxy) < buf.getHeight()); i++) { |
... | ... | |
631 | 635 |
} |
632 | 636 |
} |
633 | 637 |
} |
634 |
|
|
638 |
|
|
635 | 639 |
} |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/AbstractRasterProvider.java | ||
---|---|---|
173 | 173 |
setFileSize(f.length()); |
174 | 174 |
} |
175 | 175 |
} |
176 |
uri = translateURI(uri); |
|
176 | 177 |
} |
177 | 178 |
|
178 | 179 |
ownTransformation = new AffineTransform(); |
... | ... | |
265 | 266 |
|
266 | 267 |
/** |
267 | 268 |
* Factoria para abrir distintos tipos de raster. |
268 |
* @param fName Nombre del fichero. |
|
269 |
* @param storeServices |
|
270 |
* @param param |
|
269 | 271 |
* |
270 | 272 |
* @return SingleDataset, o null si hay problemas. |
273 |
* @throws RasterDriverException |
|
271 | 274 |
*/ |
272 | 275 |
@SuppressWarnings("unchecked") |
273 | 276 |
public static AbstractRasterProvider singleDatasetInstance(DataStoreProviderServices storeServices, String param) throws RasterDriverException { |
... | ... | |
316 | 319 |
/** |
317 | 320 |
* Carga un fichero raster. Puede usarse para calcular el extent e instanciar |
318 | 321 |
* un objeto de este tipo. |
322 |
* @return RasterProvider |
|
319 | 323 |
*/ |
320 | 324 |
abstract public RasterProvider load(); |
321 | 325 |
|
... | ... | |
349 | 353 |
* raster. |
350 | 354 |
* @param x coordenada X |
351 | 355 |
* @param y coordenada Y |
352 |
* @return |
|
356 |
* @return data
|
|
353 | 357 |
*/ |
354 | 358 |
abstract public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException; |
355 | 359 |
|
356 | 360 |
/** |
357 | 361 |
* Gets the set of data selected in the {@link RasterQuery} |
358 | 362 |
* @param q |
359 |
* @return |
|
363 |
* @return buffer
|
|
360 | 364 |
* @throws RasterDriverException |
361 | 365 |
* @throws ProcessInterruptedException |
362 | 366 |
*/ |
... | ... | |
486 | 490 |
if(noData == null) { |
487 | 491 |
noData = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(getBandCount(), getDataType()[0]); |
488 | 492 |
noData.setNoDataTransparent(false); |
489 |
noData.setFileName(getRMFFile().getName()); |
|
493 |
File rmfFile = getRMFFile(); |
|
494 |
if(rmfFile!=null){ |
|
495 |
noData.setFileName(rmfFile.getName()); |
|
496 |
} |
|
490 | 497 |
} |
491 | 498 |
return noData; |
492 | 499 |
} |
... | ... | |
557 | 564 |
|
558 | 565 |
/** |
559 | 566 |
* Asigna el par?metro de inicializaci?n del driver. |
567 |
* @param provServices |
|
568 |
* @param param |
|
560 | 569 |
*/ |
561 | 570 |
public void setParam(DataStoreProviderServices provServices, DataStoreParameters param) { |
562 | 571 |
if(param instanceof RasterDataParameters) |
... | ... | |
605 | 614 |
if ("FILE".equalsIgnoreCase(objUri.getScheme())) { |
606 | 615 |
file = new File(objUri); |
607 | 616 |
fileName = FilenameUtils.getBaseName(objUri.getPath()); |
608 |
} else { |
|
609 |
file = new File(objUri.getHost()); |
|
610 |
fileName = FilenameUtils.getBaseName(objUri.getHost()); |
|
611 |
} |
|
612 |
if (rmfFolder == null) { |
|
613 |
rmfFolder = file.getParentFile(); |
|
614 |
if ((getDataParameters() != null && getDataParameters() instanceof RasterDataParameters)) { |
|
615 |
((RasterDataParameters) getDataParameters()).setRMFFolder(rmfFolder); |
|
617 |
if (rmfFolder == null) { |
|
618 |
rmfFolder = file.getParentFile(); |
|
619 |
if ((getDataParameters() != null && getDataParameters() instanceof RasterDataParameters)) { |
|
620 |
((RasterDataParameters) getDataParameters()).setRMFFolder(rmfFolder); |
|
621 |
} |
|
622 |
// return new File(fileName + tail); |
|
616 | 623 |
} |
617 |
return new File(fileName + tail); |
|
618 |
} else { |
|
619 | 624 |
return new File(rmfFolder.getAbsolutePath() + File.separator + fileName + tail); |
620 | 625 |
} |
626 |
return null; |
|
621 | 627 |
} |
622 | 628 |
|
623 | 629 |
protected String getRMFFileForRemoteServices(String layerName) { |
... | ... | |
673 | 679 |
|
674 | 680 |
/** |
675 | 681 |
* Devuelve si el Dataset es reproyectable |
676 |
* @return |
|
682 |
* @return true if Dataset is reproyectable
|
|
677 | 683 |
*/ |
678 | 684 |
public boolean isReproyectable() { |
679 | 685 |
return true; |
... | ... | |
734 | 740 |
* @param file |
735 | 741 |
* @param class1 |
736 | 742 |
* @param value |
737 |
* @return |
|
743 |
* @return Object
|
|
738 | 744 |
* @throws RmfSerializerException |
739 | 745 |
*/ |
740 | 746 |
public static Object loadObjectFromRmfFile(String file, Class<?> class1, Object value) throws RmfSerializerException { |
... | ... | |
756 | 762 |
* Carga un objecto desde un serializador usando el tipo del mismo objeto pasado por parametro. |
757 | 763 |
* Usa value para iniciar dicho serializador |
758 | 764 |
* @param value |
759 |
* @return |
|
765 |
* @return Object
|
|
760 | 766 |
* @throws RmfSerializerException |
761 | 767 |
*/ |
762 | 768 |
public Object loadObjectFromRmf(Object value) throws RmfSerializerException { |
... | ... | |
861 | 867 |
|
862 | 868 |
/** |
863 | 869 |
* Returs the DataParameters |
864 |
* @return |
|
870 |
* @return the DataParameters
|
|
865 | 871 |
*/ |
866 | 872 |
public RasterDataParameters getDataParameters() { |
867 | 873 |
if(getDataStoreParameters() instanceof RasterDataParameters) |
... | ... | |
892 | 898 |
* Cuando es traducido por un alias el driver intentar๏ฟฝ abrir el alias y no el |
893 | 899 |
* fichero. Esto es util porque algunos formatos tienen la extensi๏ฟฝn en el |
894 | 900 |
* fichero de cabecera pero lo que se abre realmente es el fichero de datos. |
895 |
* @param fileName
|
|
896 |
* @return |
|
901 |
* @param uri
|
|
902 |
* @return uri
|
|
897 | 903 |
*/ |
898 | 904 |
public URI translateURI(URI uri) { |
899 | 905 |
return uri; |
... | ... | |
908 | 914 |
|
909 | 915 |
|
910 | 916 |
public String getFileSuffix() { |
911 |
//FIXME: ?Sirve para algo? |
|
912 | 917 |
String path = getURIOfFirstProvider().getPath(); |
913 |
return path.substring(path.lastIndexOf(".") + 1, path.length());
|
|
918 |
return FilenameUtils.getExtension(path);
|
|
914 | 919 |
} |
915 | 920 |
|
916 | 921 |
public URI getURIOfFirstProvider() { |
... | ... | |
949 | 954 |
|
950 | 955 |
/** |
951 | 956 |
* Gets the size of the file if exists in Bytes |
952 |
* @return |
|
957 |
* @return the size of file
|
|
953 | 958 |
*/ |
954 | 959 |
public long getFileSize() { |
955 | 960 |
return fileSize; |
... | ... | |
986 | 991 |
* Elimina la matriz de transformaci๏ฟฝn asociada al raster y que se tiene en |
987 | 992 |
* cuenta para el setView. Este reseteo tendr๏ฟฝ en cuenta que si el raster |
988 | 993 |
* tiene asociado un rmf esta transformaci๏ฟฝn no ser๏ฟฝ eliminada sino que se |
989 |
* asignar๏ฟฝ la correspondiente al rmf existente. |
|
990 |
* @return devuelve true si tiene fichero rmf asociado y false si no lo tiene. |
|
994 |
* asignar? la correspondiente al rmf existente. |
|
991 | 995 |
*/ |
992 | 996 |
public void resetAffineTransform() { |
993 | 997 |
externalTransformation.setToIdentity(); |
... | ... | |
1137 | 1141 |
|
1138 | 1142 |
/** |
1139 | 1143 |
* Gets the list of geo points associated to this provider |
1140 |
* @return |
|
1144 |
* @return the list of geo points
|
|
1141 | 1145 |
*/ |
1142 | 1146 |
public GeoPointList getGeoPointList() { |
1143 | 1147 |
return geoPointList; |
... | ... | |
1152 | 1156 |
|
1153 | 1157 |
/** |
1154 | 1158 |
* @deprecated This method should not be used. The store have a getDefaultBandList |
1155 |
* @return |
|
1159 |
* @return BandList
|
|
1156 | 1160 |
*/ |
1157 | 1161 |
public BandList getDefaultBandList() { |
1158 | 1162 |
BandList bandList = new BandListImpl(); |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataStore.java | ||
---|---|---|
22 | 22 |
package org.gvsig.raster.impl.store; |
23 | 23 |
|
24 | 24 |
import java.io.File; |
25 |
import java.net.URI; |
|
25 | 26 |
import java.util.Iterator; |
26 | 27 |
import java.util.List; |
27 | 28 |
import java.util.Set; |
28 | 29 |
|
29 | 30 |
import org.cresques.cts.ICoordTrans; |
31 |
|
|
30 | 32 |
import org.gvsig.fmap.dal.DataManager; |
31 | 33 |
import org.gvsig.fmap.dal.DataQuery; |
32 | 34 |
import org.gvsig.fmap.dal.DataServerExplorer; |
... | ... | |
142 | 144 |
for(int i = 0; i < provider.getBandCount(); i++) { |
143 | 145 |
try { |
144 | 146 |
int dataType = provider.getDataType()[i]; |
145 |
DatasetBand band = new DatasetBandImpl(provider.getURIByBand(i).getPath(), |
|
147 |
String filename; |
|
148 |
URI uriByBand = provider.getURIByBand(i); |
|
149 |
if("FILE".equalsIgnoreCase(uriByBand.getScheme())){ |
|
150 |
filename = uriByBand.getPath(); |
|
151 |
} else { |
|
152 |
filename = uriByBand.toString(); |
|
153 |
} |
|
154 |
DatasetBand band = new DatasetBandImpl(filename, |
|
146 | 155 |
provider.getBandPositionByProvider(i), |
147 | 156 |
dataType, |
148 | 157 |
provider.getBandCount()); |
... | ... | |
263 | 272 |
|
264 | 273 |
/** |
265 | 274 |
* Saves information about serials |
266 |
* @param object to save |
|
275 |
* @param serialInfo object to save
|
|
267 | 276 |
* @throws RmfSerializerException |
268 | 277 |
*/ |
269 | 278 |
public abstract void saveSerialInfoToRmf(TimeSeries serialInfo) throws RmfSerializerException; |
270 | 279 |
|
271 | 280 |
/** |
272 | 281 |
* Loads information about serials |
273 |
* @param object to load |
|
282 |
* @param serialInfo |
|
283 |
* @return true if work correctly |
|
274 | 284 |
* @throws RmfSerializerException |
275 | 285 |
*/ |
276 | 286 |
public abstract boolean loadSerialInfoFromRmf(TimeSeries serialInfo); |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterFileDataParameters.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 | 31 |
import java.net.URI; |
32 |
import java.net.URISyntaxException; |
|
33 | 32 |
|
34 | 33 |
import org.slf4j.Logger; |
35 | 34 |
import org.slf4j.LoggerFactory; |
... | ... | |
59 | 58 |
|
60 | 59 |
public File getFile() { |
61 | 60 |
URI uri = getURI(); |
62 |
if (uri!=null) { |
|
61 |
if (uri!=null && "FILE".equalsIgnoreCase(uri.getScheme())) {
|
|
63 | 62 |
return new File(uri); |
64 | 63 |
} |
65 | 64 |
return null; |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/datastruct/ExtentImpl.java | ||
---|---|---|
39 | 39 |
|
40 | 40 |
/** |
41 | 41 |
* Clase que getiona el extent de una imagen |
42 |
*
|
|
42 |
* |
|
43 | 43 |
* @author Luis W.Sevilla (sevilla_lui@gva.es) |
44 | 44 |
*/ |
45 | 45 |
public class ExtentImpl implements Extent { |
46 | 46 |
public static final String PERSISTENT_NAME = "Extent_Persistent"; |
47 | 47 |
public static final String PERSISTENT_DESCRIPTION = "Extent Persistent"; |
48 |
|
|
48 |
|
|
49 | 49 |
Point2D min = null; |
50 | 50 |
Point2D max = null; |
51 |
|
|
51 |
|
|
52 | 52 |
Point2D ul = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
53 | 53 |
Point2D lr = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
54 | 54 |
Point2D ur = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
55 | 55 |
Point2D ll = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
56 |
|
|
56 |
|
|
57 | 57 |
/** |
58 | 58 |
* Constructor sin par?metros |
59 | 59 |
*/ |
... | ... | |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
/** |
66 |
* Constructor
|
|
67 |
* @param pt1 punto que representa la esquina superior izquierda
|
|
68 |
* @param pt2 punto que representa la esquina inferior derecha
|
|
66 |
* Constructor |
|
67 |
* @param ul punto que representa la esquina superior izquierda
|
|
68 |
* @param lr punto que representa la esquina inferior derecha
|
|
69 | 69 |
*/ |
70 | 70 |
public ExtentImpl(Point2D ul, Point2D lr) { |
71 | 71 |
this.ul = ul; |
72 | 72 |
this.lr = lr; |
73 | 73 |
newExtent(ul.getX(), ul.getY(), lr.getX(), lr.getY()); |
74 | 74 |
} |
75 |
|
|
75 |
|
|
76 | 76 |
/** |
77 |
* Constructor
|
|
77 |
* Constructor |
|
78 | 78 |
* @param ul punto que representa la esquina superior izquierda |
79 | 79 |
* @param lr punto que representa la esquina inferior derecha |
80 | 80 |
* @param ur punto que representa la esquina superior derecha |
... | ... | |
85 | 85 |
this.lr = lr; |
86 | 86 |
this.ur = ur; |
87 | 87 |
this.ll = ll; |
88 |
min = new Point2D.Double(
|
|
89 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())),
|
|
90 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY())));
|
|
91 |
max = new Point2D.Double(
|
|
92 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())),
|
|
88 |
min = new Point2D.Double( |
|
89 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())), |
|
90 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY()))); |
|
91 |
max = new Point2D.Double( |
|
92 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())), |
|
93 | 93 |
Math.max(Math.max(ul.getY(), lr.getY()), Math.max(ur.getY(), ll.getY()))); |
94 | 94 |
} |
95 | 95 |
|
... | ... | |
129 | 129 |
min = new Point2D.Double(ext.minX(), ext.minY()); |
130 | 130 |
max = new Point2D.Double(ext.maxX(), ext.maxY()); |
131 | 131 |
} |
132 |
|
|
132 |
|
|
133 | 133 |
public Extent encloseBoundinBoxes(Extent ext) { |
134 | 134 |
Point2D pUl = new Point2D.Double( |
135 |
Math.min(getULX(), ext.getULX()),
|
|
135 |
Math.min(getULX(), ext.getULX()), |
|
136 | 136 |
Math.max(getULY(), ext.getULY())); |
137 | 137 |
Point2D pLr = new Point2D.Double( |
138 |
Math.max(getLRX(), ext.getLRX()),
|
|
138 |
Math.max(getLRX(), ext.getLRX()), |
|
139 | 139 |
Math.min(getLRY(), ext.getLRY())); |
140 | 140 |
return new ExtentImpl(pUl, pLr); |
141 | 141 |
} |
142 |
|
|
142 |
|
|
143 | 143 |
public Extent intersection(Extent ext) { |
144 | 144 |
if(intersects(ext)) { |
145 | 145 |
Point2D pUl = new Point2D.Double( |
146 |
Math.max(getULX(), ext.getULX()),
|
|
146 |
Math.max(getULX(), ext.getULX()), |
|
147 | 147 |
Math.min(getULY(), ext.getULY())); |
148 | 148 |
Point2D pLr = new Point2D.Double( |
149 |
Math.min(getLRX(), ext.getLRX()),
|
|
149 |
Math.min(getLRX(), ext.getLRX()), |
|
150 | 150 |
Math.max(getLRY(), ext.getLRY())); |
151 | 151 |
return new ExtentImpl(pUl, pLr); |
152 | 152 |
} |
... | ... | |
154 | 154 |
} |
155 | 155 |
|
156 | 156 |
public boolean intersects(Extent ext) { |
157 |
if (getMin().getX() > ext.getMax().getX())
|
|
157 |
if (getMin().getX() > ext.getMax().getX()) |
|
158 | 158 |
return false; |
159 |
else if (getMax().getX() < ext.getMin().getX())
|
|
159 |
else if (getMax().getX() < ext.getMin().getX()) |
|
160 | 160 |
return false; |
161 |
if (getMin().getY() > ext.getMax().getY())
|
|
161 |
if (getMin().getY() > ext.getMax().getY()) |
|
162 | 162 |
return false; |
163 |
else if (getMax().getY() < ext.getMin().getY())
|
|
163 |
else if (getMax().getY() < ext.getMin().getY()) |
|
164 | 164 |
return false; |
165 | 165 |
return true; |
166 | 166 |
} |
... | ... | |
173 | 173 |
ExtentImpl e = new ExtentImpl(); |
174 | 174 |
e.min = min != null ? (Point2D) min.clone() : null; |
175 | 175 |
e.max = max != null ? (Point2D) max.clone() : null; |
176 |
|
|
176 |
|
|
177 | 177 |
e.ul = ul != null ? (Point2D) ul.clone() : null; |
178 | 178 |
e.lr = lr != null ? (Point2D) lr.clone() : null; |
179 | 179 |
e.ur = ur != null ? (Point2D) ur.clone() : null; |
... | ... | |
217 | 217 |
public double maxY() { |
218 | 218 |
return max.getY(); |
219 | 219 |
} |
220 |
|
|
220 |
|
|
221 | 221 |
/** |
222 | 222 |
* Obtiene el punto m?nimo |
223 | 223 |
* @return m?nimo |
... | ... | |
235 | 235 |
} |
236 | 236 |
|
237 | 237 |
public boolean isAt(Point2D pt) { |
238 |
if (pt.getX() < minX())
|
|
238 |
if (pt.getX() < minX()) |
|
239 | 239 |
return false; |
240 |
|
|
241 |
if (pt.getX() > maxX())
|
|
240 |
|
|
241 |
if (pt.getX() > maxX()) |
|
242 | 242 |
return false; |
243 |
|
|
243 |
|
|
244 | 244 |
if (pt.getY() < minY()) |
245 | 245 |
return false; |
246 |
|
|
247 |
if (pt.getY() > maxY())
|
|
246 |
|
|
247 |
if (pt.getY() > maxY()) |
|
248 | 248 |
return false; |
249 |
|
|
249 |
|
|
250 | 250 |
return true; |
251 | 251 |
} |
252 | 252 |
|
... | ... | |
257 | 257 |
public double height() { |
258 | 258 |
return Math.abs(maxY() - minY()); |
259 | 259 |
} |
260 |
|
|
260 |
|
|
261 | 261 |
/** |
262 | 262 |
* Obtiene el centro en X del extent |
263 |
* @return |
|
263 |
* @return coordinate X of center
|
|
264 | 264 |
*/ |
265 | 265 |
public double getCenterX() { |
266 | 266 |
return minX() + (width() / 2); |
267 | 267 |
} |
268 |
|
|
268 |
|
|
269 | 269 |
/** |
270 | 270 |
* Obtiene el centro en Y del extent |
271 |
* @return |
|
271 |
* @return coordinate Y of center
|
|
272 | 272 |
*/ |
273 | 273 |
public double getCenterY() { |
274 | 274 |
return minY() + (height() / 2); |
... | ... | |
276 | 276 |
|
277 | 277 |
/** |
278 | 278 |
* Verifica un punto, y modifica el extent si no est? incluido |
279 |
* @param pt |
|
279 | 280 |
*/ |
280 | 281 |
public void add(Point2D pt) { |
281 | 282 |
if (pt == null) { |
... | ... | |
301 | 302 |
* Obtiene la escala |
302 | 303 |
* @param width Ancho |
303 | 304 |
* @param height Alto |
304 |
* @return |
|
305 |
* @return the scale
|
|
305 | 306 |
*/ |
306 | 307 |
public double[] getScale(int width, int height) { |
307 | 308 |
return getScale((double) width, (double) height); |
... | ... | |
330 | 331 |
public interface Has { |
331 | 332 |
public Extent getExtent(); |
332 | 333 |
} |
333 |
|
|
334 |
|
|
334 | 335 |
public Point2D getUL() { |
335 | 336 |
return (Point2D)ul.clone(); |
336 | 337 |
} |
337 |
|
|
338 |
|
|
338 | 339 |
public Point2D getLR() { |
339 | 340 |
return (Point2D)lr.clone(); |
340 | 341 |
} |
341 |
|
|
342 |
|
|
342 | 343 |
/** |
343 | 344 |
* Obtiene la coordenada X de la esquina superior izquierda. Esta, en condiciones normales |
344 | 345 |
* conincide con el minimo en X pero cuando un raster est? rotado esto puede variar. |
... | ... | |
349 | 350 |
return minX(); |
350 | 351 |
return ul.getX(); |
351 | 352 |
} |
352 |
|
|
353 |
|
|
353 | 354 |
/** |
354 | 355 |
* Obtiene la coordenada Y de la esquina superior izquierda. Esta, en condiciones normales |
355 | 356 |
* conincide con el maximo en Y pero cuando un raster est? rotado esto puede variar. |
... | ... | |
360 | 361 |
return maxY(); |
361 | 362 |
return ul.getY(); |
362 | 363 |
} |
363 |
|
|
364 |
|
|
364 | 365 |
/** |
365 | 366 |
* Obtiene la coordenada X de la esquina inferior derecha. Esta, en condiciones normales |
366 | 367 |
* conincide con el m?ximo en X pero cuando un raster est? rotado esto puede variar. |
... | ... | |
371 | 372 |
return maxX(); |
372 | 373 |
return lr.getX(); |
373 | 374 |
} |
374 |
|
|
375 |
|
|
375 | 376 |
/** |
376 | 377 |
* Obtiene la coordenada Y de la esquina inferior derecha. Esta, en condiciones normales |
377 | 378 |
* conincide con el minimo en Y pero cuando un raster est? rotado esto puede variar. |
378 | 379 |
* @return lry |
379 | 380 |
*/ |
380 | 381 |
public double getLRY() { |
381 |
if(lr.getX() == -999999999.0)
|
|
382 |
if(lr.getY() == -999999999.0)
|
|
382 | 383 |
return minY(); |
383 | 384 |
return lr.getY(); |
384 | 385 |
} |
385 |
|
|
386 |
|
|
386 | 387 |
/** |
387 |
* Obtiene la coordenada X de la esquina superior derecha.
|
|
388 |
* Obtiene la coordenada X de la esquina superior derecha. |
|
388 | 389 |
* @return urx |
389 | 390 |
*/ |
390 | 391 |
public double getURX() { |
391 | 392 |
return ur.getX(); |
392 | 393 |
} |
393 |
|
|
394 |
|
|
394 | 395 |
/** |
395 | 396 |
* Obtiene la coordenada Y de la esquina superior derecha. |
396 | 397 |
* @return uly |
... | ... | |
398 | 399 |
public double getURY() { |
399 | 400 |
return ur.getY(); |
400 | 401 |
} |
401 |
|
|
402 |
|
|
402 | 403 |
/** |
403 | 404 |
* Obtiene la coordenada X de la esquina inferior izquierda. |
404 | 405 |
* @return lrx |
... | ... | |
406 | 407 |
public double getLLX() { |
407 | 408 |
return ll.getX(); |
408 | 409 |
} |
409 |
|
|
410 |
|
|
410 | 411 |
/** |
411 | 412 |
* Obtiene la coordenada Y de la esquina inferior izquierda. |
412 | 413 |
* @return lly |
... | ... | |
414 | 415 |
public double getLLY() { |
415 | 416 |
return ll.getY(); |
416 | 417 |
} |
417 |
|
|
418 |
|
|
418 | 419 |
/** |
419 | 420 |
* Asigna la coordenada X de la esquina superior izquierda al m?nimo X |
420 | 421 |
*/ |
... | ... | |
422 | 423 |
ul.setLocation(minX(), ul.getY()); |
423 | 424 |
lr.setLocation(maxX(), lr.getY()); |
424 | 425 |
} |
425 |
|
|
426 |
|
|
426 | 427 |
/** |
427 | 428 |
* Asigna la coordenada X de la esquina superior izquierda al m?ximo X |
428 | 429 |
*/ |
... | ... | |
430 | 431 |
ul.setLocation(maxX(), ul.getY()); |
431 | 432 |
lr.setLocation(minX(), lr.getY()); |
432 | 433 |
} |
433 |
|
|
434 |
|
|
434 | 435 |
/** |
435 | 436 |
* Asigna la coordenada Y de la esquina superior izquierda al m?nimo Y |
436 | 437 |
*/ |
... | ... | |
438 | 439 |
ul.setLocation(ul.getX(), minY()); |
439 | 440 |
lr.setLocation(lr.getX(), maxY()); |
440 | 441 |
} |
441 |
|
|
442 |
|
|
442 | 443 |
/** |
443 | 444 |
* Asigna la coordenada Y de la esquina superior izquierda al m?ximo Y |
444 | 445 |
*/ |
... | ... | |
446 | 447 |
ul.setLocation(ul.getX(), maxY()); |
447 | 448 |
lr.setLocation(lr.getX(), minY()); |
448 | 449 |
} |
449 |
|
|
450 |
|
|
450 | 451 |
/** |
451 | 452 |
* Asigna la coordenada X de la esquina inferior derecha al m?nimo X |
452 | 453 |
*/ |
453 | 454 |
public void setLRXToMin() { |
454 | 455 |
lr.setLocation(minX(), lr.getY()); |
455 | 456 |
ul.setLocation(maxX(), ul.getY()); |
456 |
|
|
457 |
|
|
457 | 458 |
} |
458 |
|
|
459 |
|
|
459 | 460 |
/** |
460 | 461 |
* Asigna la coordenada X de la esquina inferior derecha al m?ximo X |
461 | 462 |
*/ |
... | ... | |
463 | 464 |
lr.setLocation(maxX(), lr.getY()); |
464 | 465 |
ul.setLocation(minX(), ul.getY()); |
465 | 466 |
} |
466 |
|
|
467 |
|
|
467 | 468 |
/** |
468 | 469 |
* Asigna la coordenada Y de la esquina inferior derecha al m?nimo Y |
469 | 470 |
*/ |
... | ... | |
471 | 472 |
lr.setLocation(lr.getX(), minY()); |
472 | 473 |
ul.setLocation(ul.getX(), maxX()); |
473 | 474 |
} |
474 |
|
|
475 |
|
|
475 | 476 |
/** |
476 | 477 |
* Asigna la coordenada Y de la esquina inferior derecha al m?ximo Y |
477 | 478 |
*/ |
... | ... | |
479 | 480 |
lr.setLocation(lr.getX(), maxY()); |
480 | 481 |
ul.setLocation(ul.getX(), minY()); |
481 | 482 |
} |
482 |
|
|
483 |
|
|
483 | 484 |
public Extent convert(ICoordTrans trans) { |
484 | 485 |
Rectangle2D rect = new Rectangle2D.Double(getURX(), getLRY(), width(), height()); |
485 | 486 |
Rectangle2D rectDest = trans.convert(rect); |
... | ... | |
488 | 489 |
} |
489 | 490 |
|
490 | 491 |
return new ExtentImpl( |
491 |
rectDest.getMinX(),
|
|
492 |
rectDest.getMaxY(),
|
|
493 |
rectDest.getMaxX(),
|
|
492 |
rectDest.getMinX(), |
|
493 |
rectDest.getMaxY(), |
|
494 |
rectDest.getMaxX(), |
|
494 | 495 |
rectDest.getMinY()); |
495 | 496 |
} |
496 |
|
|
497 |
|
|
497 | 498 |
public boolean equals(Object obj) { |
498 | 499 |
if(!(obj instanceof Extent)) |
499 | 500 |
return false; |
... | ... | |
507 | 508 |
this.getLLX() == e1.getLLX() && |
508 | 509 |
this.getLLY() == e1.getLLY()); |
509 | 510 |
} |
510 |
|
|
511 |
|
|
511 | 512 |
/** |
512 | 513 |
* Given a cell size, converts a point in raster coordinates to world coordinates |
513 | 514 |
* @param pt Point to transform |
... | ... | |
533 | 534 |
} |
534 | 535 |
return p; |
535 | 536 |
} |
536 |
|
|
537 |
|
|
537 | 538 |
public void loadFromState(PersistentState state) |
538 | 539 |
throws PersistenceException { |
539 | 540 |
double ulx = state.getDouble("ulx"); |
... | ... | |
548 | 549 |
lr.setLocation(lrx, lry); |
549 | 550 |
ur.setLocation(urx, ury); |
550 | 551 |
ll.setLocation(llx, lly); |
551 |
if( ur.getX() != Double.POSITIVE_INFINITY &&
|
|
552 |
if( ur.getX() != Double.POSITIVE_INFINITY && |
|
552 | 553 |
ur.getY() != Double.POSITIVE_INFINITY && |
553 | 554 |
ll.getX() != Double.POSITIVE_INFINITY && |
554 | 555 |
ll.getY() != Double.POSITIVE_INFINITY) { |
555 |
min = new Point2D.Double(
|
|
556 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())),
|
|
557 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY())));
|
|
558 |
max = new Point2D.Double(
|
|
559 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())),
|
|
556 |
min = new Point2D.Double( |
|
557 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())), |
|
558 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY()))); |
|
559 |
max = new Point2D.Double( |
|
560 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())), |
|
560 | 561 |
Math.max(Math.max(ul.getY(), lr.getY()), Math.max(ur.getY(), ll.getY()))); |
561 | 562 |
} else { |
562 | 563 |
newExtent(ulx, uly, lrx, lry); |
... | ... | |
572 | 573 |
state.set("ury", getURY()); |
573 | 574 |
state.set("llx", getLLX()); |
574 | 575 |
state.set("lly", getLLY()); |
575 |
}
|
|
576 |
|
|
576 |
} |
|
577 |
|
|
577 | 578 |
public static void registerPersistence() { |
578 | 579 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
579 | 580 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
... | ... | |
582 | 583 |
Extent.class, |
583 | 584 |
PERSISTENT_NAME, |
584 | 585 |
PERSISTENT_DESCRIPTION, |
585 |
null,
|
|
586 |
null, |
|
586 | 587 |
null |
587 | 588 |
); |
588 |
|
|
589 |
|
|
589 | 590 |
definition.addDynFieldDouble("ulx").setMandatory(true); |
590 | 591 |
definition.addDynFieldDouble("uly").setMandatory(true); |
591 | 592 |
definition.addDynFieldDouble("lrx").setMandatory(true); |
... | ... | |
596 | 597 |
definition.addDynFieldDouble("lly").setMandatory(false); |
597 | 598 |
} |
598 | 599 |
} |
599 |
|
|
600 |
|
|
600 | 601 |
protected void finalize() throws Throwable { |
601 | 602 |
min = null; |
602 | 603 |
max = null; |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/util/FileUtils.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
|
33 | 33 |
/** |
34 |
* Utilities for files, directories and file names
|
|
34 |
* Utilities for files, directories and file names |
|
35 | 35 |
* |
36 | 36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
37 | 37 |
*/ |
... | ... | |
40 | 40 |
* Copia de ficheros |
41 | 41 |
* @param pathOrig Ruta de origen |
42 | 42 |
* @param pathDst Ruta de destino. |
43 |
* @throws FileNotFoundException |
|
44 |
* @throws IOException |
|
43 | 45 |
*/ |
44 | 46 |
public void copyFile(String pathOrig, String pathDst) throws FileNotFoundException, IOException; |
45 | 47 |
|
... | ... | |
47 | 49 |
* Crea un fichero de georeferenciaci?n (world file) para un dataset |
48 | 50 |
* determinado |
49 | 51 |
* @param fileName Nombre completo del fichero de raster |
50 |
* @param Extent
|
|
52 |
* @param ext
|
|
51 | 53 |
* @param pxWidth Ancho en p?xeles |
52 | 54 |
* @param pxHeight Alto en p?xeles |
53 |
* @return |
|
54 | 55 |
* @throws IOException |
55 | 56 |
*/ |
56 | 57 |
public void createWorldFile(String fileName, Extent ext, int pxWidth, int pxHeight) throws IOException; |
... | ... | |
59 | 60 |
* Crea un fichero de georeferenciaci?n (world file) para un dataset |
60 | 61 |
* determinado |
61 | 62 |
* @param fileName Nombre completo del fichero de raster |
62 |
* @param AffineTransform |
|
63 |
* @param at AffineTransform
|
|
63 | 64 |
* @param pxWidth Ancho en p?xeles |
64 | 65 |
* @param pxHeight Alto en p?xeles |
65 |
* @return |
|
66 | 66 |
* @throws IOException |
67 | 67 |
*/ |
68 | 68 |
public void createWorldFile(String fileName, AffineTransform at, int pxWidth, int pxHeight) throws IOException; |
... | ... | |
97 | 97 |
* @return Cadena que representa el nombre del fichero sin extensi?n ni path de directorios |
98 | 98 |
*/ |
99 | 99 |
public String getFileNameFromCanonical(String file); |
100 |
|
|
100 |
|
|
101 | 101 |
/** |
102 | 102 |
* Obtiene el ?ltimo trozo de la cadena a partir de los caracteres que |
103 | 103 |
* coincidan con el patr?n. En caso de que el patr?n no exista en la cadena |
104 | 104 |
* devuelve esta completa |
105 | 105 |
* @param string |
106 | 106 |
* @param pattern |
107 |
* @return
|
|
107 |
* @return the last part of string maching pattern
|
|
108 | 108 |
*/ |
109 | 109 |
public String getLastPart(String string, String pattern); |
110 | 110 |
|
... | ... | |
124 | 124 |
* @return Nombre del fichero rmf asociado al raster. |
125 | 125 |
*/ |
126 | 126 |
public String getRMFNameFromFileName(String fileName); |
127 |
|
|
128 |
|
|
127 |
|
|
128 |
|
|
129 | 129 |
//******* Servicio de directorios temporales ************** |
130 |
|
|
130 |
|
|
131 | 131 |
/** |
132 | 132 |
* Elimina los ficheros del directorio temporal. Realizamos esta acci?n al |
133 | 133 |
* levantar la librer?a. |
... | ... | |
137 | 137 |
/** |
138 | 138 |
* Esta funci?n crea el directorio para temporales y devuelve el manejador |
139 | 139 |
* del directorio |
140 |
* @return
|
|
140 |
* @return temporal file
|
|
141 | 141 |
*/ |
142 | 142 |
public File getTemporalFile(); |
143 |
|
|
143 |
|
|
144 | 144 |
/** |
145 | 145 |
* Esta funci?n crea el directorio para temporales y devuelve la ruta de este |
146 |
* @return
|
|
146 |
* @return path of temporal file
|
|
147 | 147 |
*/ |
148 | 148 |
public String getTemporalPath(); |
149 |
|
|
149 |
|
|
150 | 150 |
/** |
151 | 151 |
* Gets the name of a raster file |
152 |
* @param name |
|
153 |
* @return the name of a raster file |
|
154 |
* @deprecated |
|
152 | 155 |
*/ |
153 | 156 |
public String getFormatedRasterFileName(String name); |
154 |
|
|
157 |
|
|
155 | 158 |
/** |
156 | 159 |
* Converts a string to MD5 |
157 | 160 |
* @param path |
158 |
* @return |
|
161 |
* @return the MD5
|
|
159 | 162 |
* @throws NoSuchAlgorithmException |
160 | 163 |
*/ |
161 | 164 |
public String convertPathToMD5(String path) throws NoSuchAlgorithmException; |
162 | 165 |
|
163 |
|
|
166 |
|
|
164 | 167 |
//******* Servicio de nombres de capas ?nicos ************** |
165 |
|
|
168 |
|
|
166 | 169 |
/** |
167 | 170 |
* La gesti?n de nombres ?nicos en la generaci?n de capas se lleva de forma |
168 | 171 |
* autom?tica. Cuando alguien crea una capa nueva, si esta no tiene nombre especifico, |
Also available in: Unified diff