root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrRaster.java @ 1100
History | View | Annotate | Download (7.05 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.DriverException; |
44 |
import com.iver.cit.gvsig.fmap.ViewPort; |
45 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
46 |
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver; |
47 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
48 |
|
49 |
import com.iver.utiles.XMLEntity; |
50 |
|
51 |
import org.cresques.cts.IProjection; |
52 |
import org.cresques.geo.ViewPortData; |
53 |
import org.cresques.px.Extent; |
54 |
|
55 |
import java.awt.Dimension; |
56 |
import java.awt.Graphics2D; |
57 |
import java.awt.Point; |
58 |
import java.awt.Rectangle; |
59 |
import java.awt.geom.AffineTransform; |
60 |
import java.awt.geom.NoninvertibleTransformException; |
61 |
import java.awt.geom.Rectangle2D; |
62 |
import java.awt.image.BufferedImage; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Clase b?sica de capa raster.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class FLyrRaster extends FLyrDefault implements RasterOperations { |
71 |
private RasterAdapter source;
|
72 |
|
73 |
/**
|
74 |
* Devuelve el RasterAdapter de la capa.
|
75 |
*
|
76 |
* @return RasterAdapter.
|
77 |
*/
|
78 |
public RasterAdapter getSource() {
|
79 |
return source;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Inserta el RasterAdapter.
|
84 |
*
|
85 |
* @param ra RasterAdapter.
|
86 |
*/
|
87 |
public void setSource(RasterAdapter ra) { |
88 |
source = ra; |
89 |
} |
90 |
|
91 |
/*
|
92 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
93 |
*/
|
94 |
public void load() throws DriverIOException { |
95 |
((RasterFileAdapter) source).start(); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
100 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
101 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
102 |
*/
|
103 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
104 |
Cancellable cancel) throws DriverException {
|
105 |
try {
|
106 |
((RasterFileAdapter) source).draw(image, g, vp, cancel); |
107 |
} catch (DriverIOException e) {
|
108 |
throw new DriverException(e); |
109 |
} |
110 |
|
111 |
if (getVirtualLayers() != null) { |
112 |
getVirtualLayers().draw(image, g, vp, cancel); |
113 |
} |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Inserta la proyecci?n.
|
118 |
*
|
119 |
* @param proj Proyecci?n.
|
120 |
*/
|
121 |
public void setProjection(IProjection proj) { |
122 |
super.setProjection(proj);
|
123 |
|
124 |
if (source.getDriver() instanceof GeorreferencedRasterDriver) { |
125 |
GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver(); |
126 |
|
127 |
if (geoDrv.getProjection() == null) { |
128 |
geoDrv.setProjection(proj); |
129 |
} |
130 |
} |
131 |
} |
132 |
|
133 |
/*
|
134 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
135 |
*/
|
136 |
public Rectangle2D getFullExtent() throws DriverException { |
137 |
return ((RasterFileAdapter) source).getFullExtent();
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
|
142 |
*/
|
143 |
public String queryByPoint(Point point) { |
144 |
return null; |
145 |
} |
146 |
|
147 |
/**
|
148 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
149 |
*/
|
150 |
public XMLEntity getXMLEntity() {
|
151 |
XMLEntity xml = super.getXMLEntity();
|
152 |
|
153 |
if (source instanceof RasterFileAdapter) { |
154 |
xml.putProperty("file", ((RasterFileAdapter) source).getFile());
|
155 |
} |
156 |
|
157 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
158 |
|
159 |
return xml;
|
160 |
} |
161 |
|
162 |
/* (non-Javadoc)
|
163 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
|
164 |
*/
|
165 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
166 |
throws DriverException {
|
167 |
// Para no pedir imagenes demasiado grandes, vamos
|
168 |
// a hacer lo mismo que hace EcwFile: chunkear.
|
169 |
// Llamamos a drawView con cuadraditos m?s peque?os
|
170 |
// del BufferedImage ni caso, cuando se imprime viene con null
|
171 |
int numW, numH;
|
172 |
int stepX, stepY;
|
173 |
int xProv, yProv, wProv, hProv;
|
174 |
double xProvD, yProvD, wProvD, hProvD;
|
175 |
int A = 4200; |
176 |
int H = 4000; |
177 |
int altoAux, anchoAux;
|
178 |
|
179 |
AffineTransform mat = viewPort.getAffineTransform();
|
180 |
|
181 |
// Vamos a hacerlo en trozos de AxH
|
182 |
Rectangle r = g.getClipRect();
|
183 |
numW = (int) (r.width) / A;
|
184 |
numH = (int) (r.height) / H;
|
185 |
|
186 |
|
187 |
double[] srcPts = new double[8]; |
188 |
double[] dstPts= new double[8]; |
189 |
|
190 |
yProv = (int) r.y;
|
191 |
for (stepY=0; stepY < numH+1; stepY++) |
192 |
{ |
193 |
if ((yProv + H) > r.getMaxY())
|
194 |
altoAux = (int) r.getMaxY() - yProv;
|
195 |
else
|
196 |
altoAux = H; |
197 |
|
198 |
xProv = (int) r.x;
|
199 |
for (stepX=0; stepX < numW+1; stepX++) |
200 |
{ |
201 |
if ((xProv + A) > r.getMaxX())
|
202 |
anchoAux = (int) r.getMaxX() - xProv;
|
203 |
else
|
204 |
anchoAux = A; |
205 |
|
206 |
Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux); |
207 |
|
208 |
// Parte que dibuja
|
209 |
srcPts[0] = xProv;
|
210 |
srcPts[1] = yProv;
|
211 |
srcPts[2] = xProv + anchoAux+1; |
212 |
srcPts[3] = yProv;
|
213 |
srcPts[4] = xProv + anchoAux+1; |
214 |
srcPts[5] = yProv + altoAux+1; |
215 |
srcPts[6] = xProv;
|
216 |
srcPts[7] = yProv + altoAux+1; |
217 |
|
218 |
try {
|
219 |
mat.inverseTransform(srcPts, 0, dstPts, 0, 4); |
220 |
Rectangle2D.Double rectCuadricula = new Rectangle2D.Double( |
221 |
dstPts[0], dstPts[1], |
222 |
dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]); |
223 |
Extent extent = new Extent(rectCuadricula);
|
224 |
|
225 |
Dimension tam = new Dimension(anchoAux+1, altoAux+1); |
226 |
ViewPort vp = viewPort.cloneViewPort(); |
227 |
vp.setExtent(rectCuadricula); |
228 |
vp.setImageSize(tam); |
229 |
// ViewPortData vp = new ViewPortData(getProjection(), extent, tam);
|
230 |
// vp.setMat(mat);
|
231 |
// rasterList.draw(g2, vp);
|
232 |
draw(null, g, viewPort, cancel);
|
233 |
|
234 |
} catch (NoninvertibleTransformException e) { |
235 |
// TODO Auto-generated catch block
|
236 |
e.printStackTrace(); |
237 |
} |
238 |
// Fin parte que dibuja
|
239 |
xProv = xProv + A; |
240 |
} |
241 |
yProv = yProv + H; |
242 |
} |
243 |
|
244 |
} |
245 |
} |