root / tags / v1_0_RELEASE / libraries / libCq CMS for java.old / src / org / cresques / io / TifGeoRefFile.java @ 9167
History | View | Annotate | Download (6.54 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.io; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.GeoPoint; |
30 |
import org.cresques.geo.Geodetic; |
31 |
import org.cresques.geo.ProjPoint; |
32 |
import org.cresques.geo.Projection; |
33 |
|
34 |
import org.cresques.px.Extent; |
35 |
|
36 |
import java.awt.Dimension; |
37 |
import java.awt.Image; |
38 |
import java.awt.Point; |
39 |
|
40 |
import java.io.IOException; |
41 |
|
42 |
|
43 |
/**
|
44 |
* Soporte para ficheros georeferenciados con World File (.tfw)
|
45 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
46 |
* @author "Jos? Morell Rama" <morell_josram@gva.es>
|
47 |
*/
|
48 |
public class TifGeoRefFile extends GeoRasterFile { |
49 |
geo.raster.GeoRasterFile geoRasterFile = null;
|
50 |
Extent v = null;
|
51 |
|
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); |
60 |
|
61 |
geoRasterFile = geo.raster.GeoRasterFile.createFile(fName); |
62 |
|
63 |
load(); |
64 |
} |
65 |
|
66 |
/* (non-Javadoc)
|
67 |
* @see org.cresques.io.GeoRasterFile#load()
|
68 |
*/
|
69 |
public GeoFile load() {
|
70 |
try {
|
71 |
geoRasterFile.open(); |
72 |
|
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); |
80 |
|
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()); |
92 |
|
93 |
//geoRasterFile.computeExtent();
|
94 |
} |
95 |
|
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 |
} |
104 |
|
105 |
return this; |
106 |
} |
107 |
|
108 |
public int getWidth() { |
109 |
return geoRasterFile.getWidth();
|
110 |
} |
111 |
|
112 |
public int getHeight() { |
113 |
return geoRasterFile.getHeight();
|
114 |
} |
115 |
|
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 |
} |
122 |
|
123 |
public Extent getView() {
|
124 |
return v;
|
125 |
} |
126 |
|
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 updateImage(width, height, rp) ;
|
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 updateImage(width, height, rp) ;
|
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 |
} |
197 |
|
198 |
public void setExtentTransform(double originX, double originY, double psX, double psY) {} |
199 |
} |