Revision 5185
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GeoFile.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io; |
25 | 25 |
|
26 |
import java.awt.geom.AffineTransform; |
|
26 | 27 |
import java.awt.geom.Point2D; |
27 |
import java.awt.geom.Rectangle2D; |
|
28 | 28 |
import java.util.Date; |
29 | 29 |
|
30 | 30 |
import org.cresques.cts.ICoordTrans; |
... | ... | |
45 | 45 |
|
46 | 46 |
/** |
47 | 47 |
* Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent |
48 |
* guardado en el fichero .rmf asociado a la imagen. En caso de que no exista este fichero la transformaci?n |
|
49 |
* ser? 0 para todos sus valores. |
|
50 |
* El primer punto corresponde al desplazamiento sufrido por la imagen en X e Y. El segundo punto a la proporci?n |
|
51 |
* del ancho y alto entre la imagen origen y destino. |
|
48 |
* guardado en el fichero .rmf asociado a la imagen. En caso de que no exista este fichero no habr? |
|
49 |
* transformaci?n |
|
52 | 50 |
*/ |
53 |
protected Point2D[] extentTransform = new Point2D[2]; |
|
51 |
protected AffineTransform transformNewExtent = null; |
|
52 |
protected AffineTransform transformOldExtent = null; |
|
53 |
protected Point2D extentsRatio = null; |
|
54 |
|
|
55 |
|
|
56 |
protected boolean rmfExists = false; |
|
54 | 57 |
long fileSize = 0; |
55 | 58 |
protected long bytesReaded = 0; |
56 | 59 |
protected long lineCnt = 0; |
... | ... | |
67 | 70 |
name = DataSource.normalize(name); |
68 | 71 |
} |
69 | 72 |
extent = new Extent(); |
70 |
|
|
71 |
extentTransform[0] = new Point2D.Double(); |
|
72 |
extentTransform[0].setLocation(0, 0); |
|
73 |
extentTransform[1] = new Point2D.Double(); |
|
74 |
extentTransform[1].setLocation(1, 1); |
|
73 |
extentsRatio = new Point2D.Double(); |
|
74 |
transformNewExtent = new AffineTransform(); |
|
75 |
transformOldExtent = new AffineTransform(); |
|
75 | 76 |
} |
76 | 77 |
|
77 | 78 |
public String getName() { |
... | ... | |
105 | 106 |
} |
106 | 107 |
|
107 | 108 |
/** |
108 |
* Obtiene la transformaci?n del extent. En caso de que no exista fichero .rmf esta transformaci?n |
|
109 |
* ser? 0 para todos sus valores. Si existe el fichero .rmf esta transformaci?n se calcular? como |
|
110 |
* la diferencia entre el extent de la imagen y el extent del fichero para que al hacer un setView |
|
111 |
* pueda hacerse la transformaci?n correcta. |
|
112 |
* El primer punto corresponde al desplazamiento sufrido por la imagen en X e Y. El segundo punto a la proporci?n |
|
113 |
* del ancho y alto entre la imagen origen y destino. |
|
109 |
* Obtiene la relaci?n entre anchos y altos de la georreferenciaci?n de la imagen y la asignada |
|
110 |
* a trav?s del fichero .rmf. Esto se usa para poder realizar transformaciones entre ambos sistemas |
|
111 |
* al asignar una vista. |
|
114 | 112 |
* @return |
115 | 113 |
*/ |
116 |
public Point2D[] getExtentTransform() {
|
|
117 |
return extentTransform;
|
|
114 |
public Point2D getExtentRatio() {
|
|
115 |
return extentsRatio;
|
|
118 | 116 |
} |
119 | 117 |
|
120 | 118 |
abstract public GeoFile load(); |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/MrSidFile.java | ||
---|---|---|
952 | 952 |
* @param originY Origen de la imagen en la coordenada Y |
953 | 953 |
*/ |
954 | 954 |
public void setExtentTransform(double originX, double originY, double w, double h, double psX, double psY) { |
955 |
extentTransform[0].setLocation(originX - extent.minX(), originY - extent.maxY()); |
|
955 |
|
|
956 | 956 |
} |
957 | 957 |
} |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/EcwFile.java | ||
---|---|---|
96 | 96 |
//System.err.println("Abriendo "+fName); |
97 | 97 |
file = new JNCSFile(fName, false); |
98 | 98 |
load(); |
99 |
readGeoInfo(fName); |
|
99 |
//readGeoInfo(fName);
|
|
100 | 100 |
bandCount = file.numBands; |
101 | 101 |
|
102 | 102 |
if ( bandCount > 2) { |
... | ... | |
168 | 168 |
|
169 | 169 |
public void setView(Extent e) { |
170 | 170 |
//Aplicamos la transformaci?n a la vista en caso de que haya un fichero .rmf |
171 |
double minX = e.minX() - extentTransform[0].getX(); |
|
172 |
double minY = e.minY() - extentTransform[0].getY(); |
|
173 |
double maxX = e.maxX() - extentTransform[0].getX(); |
|
174 |
double maxY = e.maxY() - extentTransform[0].getY(); |
|
175 |
|
|
171 |
/* |
|
176 | 172 |
if(file.cellIncrementY > 0) |
177 | 173 |
file.cellIncrementY = -file.cellIncrementY; |
178 | 174 |
if(minX < file.originX) |
... | ... | |
184 | 180 |
if(minY < file.originY + ((double) (file.height - 1) * file.cellIncrementY)) |
185 | 181 |
minY = file.originY + ((double) (file.height - 1) * file.cellIncrementY); |
186 | 182 |
|
187 |
Extent transformView = new Extent( minX, minY, maxX, maxY ); |
|
188 |
v = new Extent(transformView);
|
|
183 |
Extent transformView = new Extent( minX, minY, maxX, maxY );*/
|
|
184 |
v = new Extent(e);
|
|
189 | 185 |
} |
190 | 186 |
|
191 | 187 |
public Extent getView() { |
... | ... | |
989 | 985 |
* @param originY Origen de la imagen en la coordenada Y |
990 | 986 |
*/ |
991 | 987 |
public void setExtentTransform(double originX, double originY, double w, double h, double psX, double psY) { |
992 |
extentTransform[0].setLocation(originX - extent.minX(), originY - extent.maxY()); |
|
988 |
|
|
993 | 989 |
} |
994 | 990 |
|
995 | 991 |
/** |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GeoRasterFile.java | ||
---|---|---|
361 | 361 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
362 | 362 |
} |
363 | 363 |
|
364 |
//extentTransform.setLocation(originX - extent.minX(), originY - extent.maxY()); |
|
365 |
//extent = new Extent(minX, minY, maxX, maxY); |
|
364 |
rmfExists = true; |
|
366 | 365 |
setExtentTransform(originX, originY, w, h, pixelSizeX, pixelSizeY); |
367 |
//extent = new Extent(originX, originY, originX + w, originY + h); |
|
368 | 366 |
extent = new Extent(originX, originY, originX + (pixelSizeX * imageWidth), originY + (pixelSizeY * imageHeight)); |
369 | 367 |
|
370 |
|
|
371 | 368 |
} catch (FileNotFoundException fnfEx) { |
372 | 369 |
} catch (XmlPullParserException xmlEx) { |
373 | 370 |
xmlEx.printStackTrace(); |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GdalFile.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.Image; |
27 | 27 |
import java.awt.Point; |
28 |
import java.awt.geom.NoninvertibleTransformException; |
|
28 | 29 |
import java.awt.geom.Point2D; |
29 | 30 |
import java.awt.image.BufferedImage; |
30 | 31 |
import java.awt.image.DataBuffer; |
... | ... | |
53 | 54 |
*/ |
54 | 55 |
|
55 | 56 |
class GdalNative extends Gdal { |
56 |
static boolean WITH_OVERVIEWS = true; |
|
57 |
private String ext = ""; |
|
58 |
private String shortName = ""; |
|
57 |
static boolean WITH_OVERVIEWS = true; |
|
58 |
private String ext = ""; |
|
59 |
private String shortName = ""; |
|
60 |
public GeoTransform trans = null; |
|
61 |
/** |
|
62 |
* Contorno en coordenadas geogr?ficas. (y Extent del raster). |
|
63 |
*/ |
|
64 |
public Contour esq = new Contour(); |
|
65 |
public int width = 0, height = 0; |
|
66 |
public double originX = 0D, originY = 0D; |
|
67 |
public String version = ""; |
|
68 |
private int alpha = 0; |
|
69 |
protected int rBandNr = 1, gBandNr = 2, bBandNr = 3, aBandNr = 4; |
|
70 |
private int dataType = GDT_Byte; |
|
71 |
|
|
59 | 72 |
|
60 | 73 |
// Polilinea con extent |
61 | 74 |
public class Contour extends Vector { |
... | ... | |
73 | 86 |
if (pt.getY() < minY) minY = pt.getY(); |
74 | 87 |
} |
75 | 88 |
} |
76 |
/** |
|
77 |
* Contorno en coordenadas geogr?ficas. (y Extent del raster). |
|
78 |
*/ |
|
79 |
|
|
80 |
public Contour esq = new Contour(); |
|
81 |
public int width = 0, height = 0; |
|
82 |
public double originX = 0D, originY = 0D; |
|
83 |
public String version = ""; |
|
84 |
|
|
85 |
private int alpha = 0; |
|
86 |
protected int rBandNr = 1, gBandNr = 2, bBandNr = 3, aBandNr = 4; |
|
87 |
private int dataType = GDT_Byte; |
|
88 |
|
|
89 |
|
|
89 | 90 |
public GdalNative(String fName) throws GdalException, IOException { |
90 | 91 |
super(); |
91 | 92 |
init(fName); |
... | ... | |
104 | 105 |
//String [] metadata = getMetadata(); |
105 | 106 |
double ox=0D, oy=0D, resx=0D, resy=0D; |
106 | 107 |
try{ |
107 |
GeoTransform trans = getGeoTransform();
|
|
108 |
trans = getGeoTransform(); |
|
108 | 109 |
ox = trans.adfgeotransform[0]; |
109 | 110 |
oy = trans.adfgeotransform[3]; |
110 | 111 |
resx = trans.adfgeotransform[1]; |
... | ... | |
504 | 505 |
public class GdalFile extends GeoRasterFile { |
505 | 506 |
public final static int BAND_HEIGHT = 64; |
506 | 507 |
protected GdalNative file = null; |
508 |
/** |
|
509 |
* Tama?o de pixel para las imagenes con fichero RMF. No podemos salvarlo en file porque es necesario conocer el |
|
510 |
* tama?o de pixel asignado por rl .rmf y el tama?o de pixel real. |
|
511 |
*/ |
|
512 |
private double pixelSizeX = 0D, pixelSizeY = 0D; |
|
507 | 513 |
|
508 | 514 |
private Extent v = null; |
509 | 515 |
|
... | ... | |
590 | 596 |
* Asigna el extent de la vista actual |
591 | 597 |
*/ |
592 | 598 |
public void setView(Extent e) { |
593 |
//Aplicamos la transformaci?n a la vista en caso de que haya un fichero .rmf |
|
594 |
Extent transformView = new Extent( e.minX() - extentTransform[0].getX(), |
|
595 |
e.minY() - extentTransform[0].getY(), |
|
596 |
(e.maxX() - extentTransform[0].getX()) / extentTransform[1].getX(), |
|
597 |
(e.maxY() - extentTransform[0].getY()) / extentTransform[1].getY()); |
|
598 |
v = new Extent(transformView); |
|
599 |
if(rmfExists){ |
|
600 |
|
|
601 |
//Trasladamos la petici?n al origen |
|
602 |
Point2D.Double petInit = null, petEnd = null; |
|
603 |
try{ |
|
604 |
petInit = new Point2D.Double(e.minX(), e.maxY()); |
|
605 |
petEnd = new Point2D.Double(e.maxX(), e.minY()); |
|
606 |
transformNewExtent.inverseTransform(petInit, petInit); |
|
607 |
transformNewExtent.inverseTransform(petEnd, petEnd); |
|
608 |
}catch(NoninvertibleTransformException ex){} |
|
609 |
|
|
610 |
//Redimensionamos la petici?n al tama?o de caja del destino |
|
611 |
double originX = (petInit.getX() * getExtentRatio().getX()) / extent.width(); |
|
612 |
double originY = (petInit.getY() * getExtentRatio().getY()) / extent.height(); |
|
613 |
double endX = (petEnd.getX() * getExtentRatio().getX()) / extent.width(); |
|
614 |
double endY = (petEnd.getY() * getExtentRatio().getY()) / extent.height(); |
|
615 |
|
|
616 |
//Trasladamos a su sistema de coordenadas |
|
617 |
Point2D.Double destInit = new Point2D.Double(originX, originY); |
|
618 |
Point2D.Double destEnd = new Point2D.Double(endX, endY); |
|
619 |
|
|
620 |
transformOldExtent.transform(destInit, destInit); |
|
621 |
transformOldExtent.transform(destEnd, destEnd); |
|
622 |
if(file.trans == null){ |
|
623 |
destInit.y = getExtentRatio().getY() + destInit.y; |
|
624 |
destEnd.y = getExtentRatio().getY() + destEnd.y; |
|
625 |
} |
|
626 |
v = new Extent( destInit.getX(), destInit.getY(), destEnd.getX(), destEnd.getY()); |
|
627 |
|
|
628 |
}else |
|
629 |
v = new Extent(e.minX(), e.minY(), e.maxX(), e.maxY()); |
|
599 | 630 |
} |
600 |
|
|
631 |
|
|
601 | 632 |
/** |
602 | 633 |
* Obtiene extent de la vista actual |
603 | 634 |
*/ |
... | ... | |
946 | 977 |
* @param originX Origen de la imagen en la coordenada X |
947 | 978 |
* @param originY Origen de la imagen en la coordenada Y |
948 | 979 |
*/ |
949 |
public void setExtentTransform(double originX, double originY, double w, double h, double psX, double psY) { |
|
950 |
extentTransform[0].setLocation(originX - extent.minX(), originY - extent.minY()); |
|
951 |
extentTransform[1].setLocation(((originX + w) - originX) / extent.width(), ((originY + h) - originY) / extent.height()); |
|
980 |
public void setExtentTransform(double originX, double originY, double w, double h, double psX, double psY) { |
|
981 |
pixelSizeX = psX; |
|
982 |
pixelSizeY = psY; |
|
983 |
|
|
984 |
double oldOriginX = 0D; |
|
985 |
double oldOriginY = 0D; |
|
986 |
if(file.trans != null){ |
|
987 |
oldOriginX = file.trans.adfgeotransform[0]; |
|
988 |
oldOriginY = file.trans.adfgeotransform[3]; |
|
989 |
} |
|
990 |
|
|
991 |
transformNewExtent.translate(originX, originY); |
|
992 |
transformOldExtent.translate(oldOriginX, oldOriginY); |
|
993 |
extentsRatio.setLocation(extent.width(), extent.height()); |
|
952 | 994 |
} |
995 |
|
|
953 | 996 |
} |
954 | 997 |
|
955 | 998 |
|
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/PxRaster.java | ||
---|---|---|
684 | 684 |
double vx2 = sz.maxX(); |
685 | 685 |
double vy2 = sz.maxY(); |
686 | 686 |
|
687 |
if (sz.minX() < extent.minX()) {
|
|
687 |
if (sz.minX() < extent.minX()) |
|
688 | 688 |
vx = extent.minX(); |
689 |
} |
|
690 |
|
|
691 |
if (sz.minY() < extent.minY()) { |
|
689 |
|
|
690 |
if (sz.minY() < extent.minY()) |
|
692 | 691 |
vy = extent.minY(); |
693 |
} |
|
694 |
|
|
695 |
if (sz.maxX() > extent.maxX()) { |
|
692 |
|
|
693 |
if (sz.maxX() > extent.maxX()) |
|
696 | 694 |
vx2 = extent.maxX(); |
697 |
} |
|
698 |
|
|
699 |
if (sz.maxY() > extent.maxY()) { |
|
695 |
|
|
696 |
if (sz.maxY() > extent.maxY()) |
|
700 | 697 |
vy2 = extent.maxY(); |
701 |
} |
|
702 |
|
|
698 |
|
|
703 | 699 |
if (geoFile != null) { |
704 | 700 |
for (int i = 0; i < geoFile.length; i++) |
705 | 701 |
geoFile[i].setView(new Extent(vx, vy, vx2, vy2)); |
... | ... | |
747 | 743 |
double scalex = vp.mat.getScaleX(); |
748 | 744 |
double scaley = vp.mat.getScaleY(); |
749 | 745 |
|
750 |
int wImg = (int) Math.round(Math.abs(w * scalex)); |
|
751 |
int hImg = (int) Math.round(Math.abs(h * scaley)); |
|
746 |
/*int wImg = (int) Math.round(Math.abs(w * scalex)); |
|
747 |
int hImg = (int) Math.round(Math.abs(h * scaley));*/ |
|
748 |
int wImg = (int) Math.round(Math.abs((adjustedExtent[2] - adjustedExtent[0]) * scalex)); |
|
749 |
int hImg = (int) Math.round(Math.abs((adjustedExtent[3] - adjustedExtent[1]) * scaley)); |
|
752 | 750 |
|
753 | 751 |
if ((wImg <= 0) || (hImg <= 0)) |
754 | 752 |
return; |
Also available in: Unified diff