Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/TifGeoRefFile.java
TifGeoRefFile.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io; |
25 | 25 |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.awt.Image; |
|
28 |
import java.awt.Point; |
|
29 |
import java.io.IOException; |
|
30 |
|
|
31 | 26 |
import org.cresques.cts.ICoordTrans; |
32 | 27 |
import org.cresques.cts.IProjection; |
28 |
|
|
33 | 29 |
import org.cresques.geo.GeoPoint; |
34 | 30 |
import org.cresques.geo.Geodetic; |
35 | 31 |
import org.cresques.geo.ProjPoint; |
36 | 32 |
import org.cresques.geo.Projection; |
33 |
|
|
37 | 34 |
import org.cresques.px.Extent; |
38 | 35 |
|
36 |
import java.awt.Dimension; |
|
37 |
import java.awt.Image; |
|
38 |
import java.awt.Point; |
|
39 |
|
|
40 |
import java.io.IOException; |
|
41 |
|
|
42 |
|
|
39 | 43 |
/** |
40 | 44 |
* Soporte para ficheros georeferenciados con World File (.tfw) |
41 | 45 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
42 | 46 |
* @author "Jos? Morell Rama" <morell_josram@gva.es> |
43 | 47 |
*/ |
44 | 48 |
public class TifGeoRefFile extends GeoRasterFile { |
45 |
geo.raster.GeoRasterFile geoRasterFile = null;
|
|
46 |
Extent v = null;
|
|
49 |
geo.raster.GeoRasterFile geoRasterFile = null;
|
|
50 |
Extent v = null;
|
|
47 | 51 |
|
48 |
/**
|
|
49 |
* @param name
|
|
50 |
*/
|
|
51 |
public TifGeoRefFile(IProjection proj, String fName) {
|
|
52 |
super(proj, null); // TODO aqui van las proyecciones
|
|
53 |
fName = DataSource.normalize(fName);
|
|
54 |
super.setName(fName);
|
|
55 |
System.out.println("jmGeoRaster: "+fName);
|
|
52 |
/**
|
|
53 |
* @param name
|
|
54 |
*/
|
|
55 |
public TifGeoRefFile(IProjection proj, String fName) {
|
|
56 |
super(proj, null); // TODO aqui van las proyecciones
|
|
57 |
fName = DataSource.normalize(fName);
|
|
58 |
super.setName(fName);
|
|
59 |
System.out.println("jmGeoRaster: " + fName);
|
|
56 | 60 |
|
57 |
geoRasterFile = geo.raster.GeoRasterFile.createFile(fName);
|
|
61 |
geoRasterFile = geo.raster.GeoRasterFile.createFile(fName);
|
|
58 | 62 |
|
59 |
load();
|
|
60 |
}
|
|
63 |
load();
|
|
64 |
}
|
|
61 | 65 |
|
62 |
/* (non-Javadoc) |
|
63 |
* @see org.cresques.io.GeoRasterFile#load() |
|
64 |
*/ |
|
65 |
public GeoFile load() { |
|
66 |
try { |
|
67 |
geoRasterFile.open(); |
|
68 |
if (!(proj instanceof Geodetic) && (proj instanceof Projection) && |
|
69 |
geoRasterFile.getOriginX() >= -180.0 && geoRasterFile.getOriginX() <= 180.0) { |
|
70 |
GeoPoint gPt = new GeoPoint(geoRasterFile.getOriginX(), geoRasterFile.getOriginY()); |
|
71 |
ProjPoint pt = (ProjPoint) getProjection().createPoint(0.0, 0.0); |
|
72 |
pt = (ProjPoint) ((Geodetic)getProjection()).fromGeo(gPt, pt); |
|
73 |
GeoPoint gPt2 = new GeoPoint(geoRasterFile.getOriginX()+geoRasterFile.getCellIncrementX(), geoRasterFile.getOriginY()+geoRasterFile.getCellIncrementY()); |
|
74 |
ProjPoint pt2 = (ProjPoint) ((Geodetic)getProjection()).createPoint(0.0, 0.0); |
|
75 |
pt2 = (ProjPoint) ((Geodetic)getProjection()).fromGeo(gPt2, pt2); |
|
76 |
geoRasterFile.setOriginX(pt.getX()); |
|
77 |
geoRasterFile.setOriginY(pt.getY()); |
|
78 |
geoRasterFile.setCellIncrementX(pt2.getX()-pt.getX()); |
|
79 |
geoRasterFile.setCellIncrementY(pt2.getY()-pt.getY()); |
|
80 |
|
|
81 |
//geoRasterFile.computeExtent(); |
|
82 |
} |
|
83 |
extent = new Extent(geoRasterFile.getExtent()); |
|
84 |
System.out.println("jmGeoRaster: Extent="+extent); |
|
85 |
geoRasterFile.setOriginRaster(new Point(0, 0)); |
|
86 |
geoRasterFile.setGraphics2Doffset(new Point(0, 0)); |
|
66 |
/* (non-Javadoc) |
|
67 |
* @see org.cresques.io.GeoRasterFile#load() |
|
68 |
*/ |
|
69 |
public GeoFile load() { |
|
70 |
try { |
|
71 |
geoRasterFile.open(); |
|
87 | 72 |
|
88 |
} catch (IOException e) { |
|
89 |
e.printStackTrace(); |
|
90 |
geoRasterFile = null; |
|
91 |
} |
|
92 |
return this; |
|
93 |
} |
|
73 |
if (!(proj instanceof Geodetic) && (proj instanceof Projection) && |
|
74 |
(geoRasterFile.getOriginX() >= -180.0) && |
|
75 |
(geoRasterFile.getOriginX() <= 180.0)) { |
|
76 |
GeoPoint gPt = new GeoPoint(geoRasterFile.getOriginX(), |
|
77 |
geoRasterFile.getOriginY()); |
|
78 |
ProjPoint pt = (ProjPoint) getProjection().createPoint(0.0, 0.0); |
|
79 |
pt = (ProjPoint) ((Geodetic) getProjection()).fromGeo(gPt, pt); |
|
94 | 80 |
|
95 |
public int getWidth() { return geoRasterFile.getWidth(); } |
|
96 |
public int getHeight() { return geoRasterFile.getHeight(); } |
|
81 |
GeoPoint gPt2 = new GeoPoint(geoRasterFile.getOriginX() + |
|
82 |
geoRasterFile.getCellIncrementX(), |
|
83 |
geoRasterFile.getOriginY() + |
|
84 |
geoRasterFile.getCellIncrementY()); |
|
85 |
ProjPoint pt2 = (ProjPoint) ((Geodetic) getProjection()).createPoint(0.0, |
|
86 |
0.0); |
|
87 |
pt2 = (ProjPoint) ((Geodetic) getProjection()).fromGeo(gPt2, pt2); |
|
88 |
geoRasterFile.setOriginX(pt.getX()); |
|
89 |
geoRasterFile.setOriginY(pt.getY()); |
|
90 |
geoRasterFile.setCellIncrementX(pt2.getX() - pt.getX()); |
|
91 |
geoRasterFile.setCellIncrementY(pt2.getY() - pt.getY()); |
|
97 | 92 |
|
98 |
/* (non-Javadoc) |
|
99 |
* @see org.cresques.io.GeoRasterFile#setView(org.cresques.px.Extent) |
|
100 |
*/ |
|
101 |
public void setView(Extent e) { v = new Extent(e); } |
|
102 |
public Extent getView() { return v; } |
|
93 |
//geoRasterFile.computeExtent(); |
|
94 |
} |
|
103 | 95 |
|
104 |
/* (non-Javadoc) |
|
105 |
* @see org.cresques.io.GeoRasterFile#setTransparency(boolean) |
|
106 |
*/ |
|
107 |
public void setTransparency(boolean t) { |
|
108 |
//transparency = t; |
|
109 |
} |
|
96 |
extent = new Extent(geoRasterFile.getExtent()); |
|
97 |
System.out.println("jmGeoRaster: Extent=" + extent); |
|
98 |
geoRasterFile.setOriginRaster(new Point(0, 0)); |
|
99 |
geoRasterFile.setGraphics2Doffset(new Point(0, 0)); |
|
100 |
} catch (IOException e) { |
|
101 |
e.printStackTrace(); |
|
102 |
geoRasterFile = null; |
|
103 |
} |
|
110 | 104 |
|
111 |
public void setTransparency(int t) { |
|
112 |
//transparency = t; |
|
113 |
} |
|
114 |
/* (non-Javadoc) |
|
115 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.geo.ReProjection) |
|
116 |
*/ |
|
117 |
public Image updateImage(int width, int height, ICoordTrans rp) { |
|
118 |
double viewportScale = (double) width/v.width(); |
|
119 |
Dimension sz = new Dimension(width, height); |
|
105 |
return this; |
|
106 |
} |
|
120 | 107 |
|
121 |
//return geoRasterFile.window(v.toRectangle2D(), viewportScale);
|
|
122 |
return ((geo.raster.GeoRasterFile) geoRasterFile).updateImage(sz, v.toRectangle2D(), viewportScale);
|
|
123 |
}
|
|
108 |
public int getWidth() {
|
|
109 |
return geoRasterFile.getWidth();
|
|
110 |
}
|
|
124 | 111 |
|
112 |
public int getHeight() { |
|
113 |
return geoRasterFile.getHeight(); |
|
114 |
} |
|
125 | 115 |
|
126 |
/* (non-Javadoc) |
|
127 |
* @see org.cresques.io.GeoRasterFile#reProject(org.cresques.geo.ReProjection) |
|
128 |
*/ |
|
129 |
public void reProject(ICoordTrans rp) { |
|
130 |
// TODO Auto-generated method stub |
|
131 |
|
|
132 |
} |
|
116 |
/* (non-Javadoc) |
|
117 |
* @see org.cresques.io.GeoRasterFile#setView(org.cresques.px.Extent) |
|
118 |
*/ |
|
119 |
public void setView(Extent e) { |
|
120 |
v = new Extent(e); |
|
121 |
} |
|
133 | 122 |
|
134 |
/* (non-Javadoc) |
|
135 |
* @see org.cresques.io.GeoRasterFile#close() |
|
136 |
*/ |
|
137 |
public void close() { |
|
138 |
} |
|
123 |
public Extent getView() { |
|
124 |
return v; |
|
125 |
} |
|
139 | 126 |
|
140 |
/* (non-Javadoc) |
|
141 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int) |
|
142 |
*/ |
|
143 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, int flags) { |
|
144 |
// TODO Auto-generated method stub |
|
145 |
return null; |
|
146 |
} |
|
147 |
|
|
148 |
/* (non-Javadoc) |
|
149 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int) |
|
150 |
*/ |
|
151 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, int origBand, int destBand) { |
|
152 |
// TODO Auto-generated method stub |
|
153 |
return null; |
|
154 |
} |
|
155 |
/* (non-Javadoc) |
|
156 |
* @see org.cresques.io.GeoRasterFile#getData(int, int) |
|
157 |
*/ |
|
158 |
public Object getData(int x, int y, int band) { |
|
159 |
// TODO Auto-generated method stub |
|
160 |
return null; |
|
161 |
} |
|
162 |
|
|
163 |
public int getBlockSize(){ |
|
164 |
return 0; |
|
165 |
} |
|
166 |
|
|
167 |
public byte[] getWindow(int ulX, int ulY, int sizeX, int sizeY, int band){ |
|
168 |
return null; |
|
169 |
} |
|
127 |
/* (non-Javadoc) |
|
128 |
* @see org.cresques.io.GeoRasterFile#setTransparency(boolean) |
|
129 |
*/ |
|
130 |
public void setTransparency(boolean t) { |
|
131 |
//transparency = t; |
|
132 |
} |
|
133 |
|
|
134 |
public void setTransparency(int t) { |
|
135 |
//transparency = t; |
|
136 |
} |
|
137 |
|
|
138 |
/* (non-Javadoc) |
|
139 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.geo.ReProjection) |
|
140 |
*/ |
|
141 |
public Image updateImage(int width, int height, ICoordTrans rp) { |
|
142 |
double viewportScale = (double) width / v.width(); |
|
143 |
Dimension sz = new Dimension(width, height); |
|
144 |
|
|
145 |
//return geoRasterFile.window(v.toRectangle2D(), viewportScale); |
|
146 |
return ((geo.raster.GeoRasterFile) geoRasterFile).updateImage(sz, |
|
147 |
v.toRectangle2D(), |
|
148 |
viewportScale); |
|
149 |
} |
|
150 |
|
|
151 |
/* (non-Javadoc) |
|
152 |
* @see org.cresques.io.GeoRasterFile#reProject(org.cresques.geo.ReProjection) |
|
153 |
*/ |
|
154 |
public void reProject(ICoordTrans rp) { |
|
155 |
// TODO Auto-generated method stub |
|
156 |
} |
|
157 |
|
|
158 |
/* (non-Javadoc) |
|
159 |
* @see org.cresques.io.GeoRasterFile#close() |
|
160 |
*/ |
|
161 |
public void close() { |
|
162 |
} |
|
163 |
|
|
164 |
/* (non-Javadoc) |
|
165 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int) |
|
166 |
*/ |
|
167 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, |
|
168 |
int flags) { |
|
169 |
// TODO Auto-generated method stub |
|
170 |
return null; |
|
171 |
} |
|
172 |
|
|
173 |
/* (non-Javadoc) |
|
174 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int) |
|
175 |
*/ |
|
176 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, |
|
177 |
int origBand, int destBand) { |
|
178 |
// TODO Auto-generated method stub |
|
179 |
return null; |
|
180 |
} |
|
181 |
|
|
182 |
/* (non-Javadoc) |
|
183 |
* @see org.cresques.io.GeoRasterFile#getData(int, int) |
|
184 |
*/ |
|
185 |
public Object getData(int x, int y, int band) { |
|
186 |
// TODO Auto-generated method stub |
|
187 |
return null; |
|
188 |
} |
|
189 |
|
|
190 |
public int getBlockSize() { |
|
191 |
return 0; |
|
192 |
} |
|
193 |
|
|
194 |
public byte[] getWindow(int ulX, int ulY, int sizeX, int sizeY, int band) { |
|
195 |
return null; |
|
196 |
} |
|
170 | 197 |
} |
Also available in: Unified diff