svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrRaster.java @ 1076
History | View | Annotate | Download (5.86 KB)
1 | 214 | fernando | package com.iver.cit.gvsig.fmap.layers; |
---|---|---|---|
2 | |||
3 | 651 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
4 | 303 | fernando | import com.iver.cit.gvsig.fmap.ViewPort; |
5 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
6 | 567 | luisw | import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver; |
7 | 303 | fernando | import com.iver.cit.gvsig.fmap.operations.Cancellable; |
8 | 1034 | vcaballero | |
9 | 415 | fernando | import com.iver.utiles.XMLEntity; |
10 | 303 | fernando | |
11 | 1034 | vcaballero | import org.cresques.cts.IProjection; |
12 | 1040 | fjp | import org.cresques.geo.ViewPortData; |
13 | import org.cresques.px.Extent; |
||
14 | 1034 | vcaballero | |
15 | 1040 | fjp | import java.awt.Dimension; |
16 | 1034 | vcaballero | import java.awt.Graphics2D; |
17 | import java.awt.Point; |
||
18 | 1040 | fjp | import java.awt.Rectangle; |
19 | import java.awt.geom.AffineTransform; |
||
20 | import java.awt.geom.NoninvertibleTransformException; |
||
21 | 1034 | vcaballero | import java.awt.geom.Rectangle2D; |
22 | import java.awt.image.BufferedImage; |
||
23 | |||
24 | |||
25 | 526 | vcaballero | /**
|
26 | 1034 | vcaballero | * Clase b?sica de capa raster.
|
27 | 526 | vcaballero | *
|
28 | * @author Vicente Caballero Navarro
|
||
29 | */
|
||
30 | 567 | luisw | public class FLyrRaster extends FLyrDefault implements RasterOperations { |
31 | private RasterAdapter source;
|
||
32 | 435 | vcaballero | |
33 | 1034 | vcaballero | /**
|
34 | * Devuelve el RasterAdapter de la capa.
|
||
35 | *
|
||
36 | * @return RasterAdapter.
|
||
37 | */
|
||
38 | public RasterAdapter getSource() {
|
||
39 | return source;
|
||
40 | } |
||
41 | 567 | luisw | |
42 | 1034 | vcaballero | /**
|
43 | * Inserta el RasterAdapter.
|
||
44 | *
|
||
45 | * @param ra RasterAdapter.
|
||
46 | */
|
||
47 | public void setSource(RasterAdapter ra) { |
||
48 | source = ra; |
||
49 | } |
||
50 | 567 | luisw | |
51 | /*
|
||
52 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
||
53 | */
|
||
54 | 1034 | vcaballero | public void load() throws DriverIOException { |
55 | ((RasterFileAdapter) source).start(); |
||
56 | 567 | luisw | } |
57 | 1034 | vcaballero | |
58 | 526 | vcaballero | /**
|
59 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
||
60 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
||
61 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
62 | */
|
||
63 | 659 | luisw | public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
64 | 1034 | vcaballero | Cancellable cancel) throws DriverException {
|
65 | 671 | luisw | try {
|
66 | 1034 | vcaballero | ((RasterFileAdapter) source).draw(image, g, vp, cancel); |
67 | 671 | luisw | } catch (DriverIOException e) {
|
68 | throw new DriverException(e); |
||
69 | } |
||
70 | 1034 | vcaballero | |
71 | if (getVirtualLayers() != null) { |
||
72 | 745 | fjp | getVirtualLayers().draw(image, g, vp, cancel); |
73 | 1034 | vcaballero | } |
74 | 526 | vcaballero | } |
75 | 1034 | vcaballero | |
76 | /**
|
||
77 | * Inserta la proyecci?n.
|
||
78 | *
|
||
79 | * @param proj Proyecci?n.
|
||
80 | */
|
||
81 | 567 | luisw | public void setProjection(IProjection proj) { |
82 | super.setProjection(proj);
|
||
83 | 1034 | vcaballero | |
84 | 567 | luisw | if (source.getDriver() instanceof GeorreferencedRasterDriver) { |
85 | GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver(); |
||
86 | 1034 | vcaballero | |
87 | if (geoDrv.getProjection() == null) { |
||
88 | 567 | luisw | geoDrv.setProjection(proj); |
89 | 1034 | vcaballero | } |
90 | 567 | luisw | } |
91 | 562 | fernando | } |
92 | |||
93 | 567 | luisw | /*
|
94 | 526 | vcaballero | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
95 | */
|
||
96 | 651 | fernando | public Rectangle2D getFullExtent() throws DriverException { |
97 | 567 | luisw | return ((RasterFileAdapter) source).getFullExtent();
|
98 | 526 | vcaballero | } |
99 | 303 | fernando | |
100 | 526 | vcaballero | /**
|
101 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
|
||
102 | */
|
||
103 | 1011 | fernando | public String queryByPoint(Point point) { |
104 | 526 | vcaballero | return null; |
105 | } |
||
106 | 435 | vcaballero | |
107 | 526 | vcaballero | /**
|
108 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
||
109 | */
|
||
110 | 1034 | vcaballero | public XMLEntity getXMLEntity() {
|
111 | 526 | vcaballero | XMLEntity xml = super.getXMLEntity();
|
112 | 1034 | vcaballero | |
113 | 895 | vcaballero | if (source instanceof RasterFileAdapter) { |
114 | xml.putProperty("file", ((RasterFileAdapter) source).getFile());
|
||
115 | 1034 | vcaballero | } |
116 | |||
117 | 895 | vcaballero | xml.putProperty("driverName", getSource().getDriver().getName());
|
118 | 1034 | vcaballero | |
119 | 526 | vcaballero | return xml;
|
120 | } |
||
121 | 435 | vcaballero | |
122 | 569 | luisw | /* (non-Javadoc)
|
123 | * @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)
|
||
124 | */
|
||
125 | 1034 | vcaballero | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
126 | 1040 | fjp | throws DriverException {
|
127 | // Para no pedir imagenes demasiado grandes, vamos
|
||
128 | // a hacer lo mismo que hace EcwFile: chunkear.
|
||
129 | // Llamamos a drawView con cuadraditos m?s peque?os
|
||
130 | // del BufferedImage ni caso, cuando se imprime viene con null
|
||
131 | int numW, numH;
|
||
132 | int stepX, stepY;
|
||
133 | int xProv, yProv, wProv, hProv;
|
||
134 | double xProvD, yProvD, wProvD, hProvD;
|
||
135 | int A = 4200; |
||
136 | int H = 4000; |
||
137 | int altoAux, anchoAux;
|
||
138 | |||
139 | AffineTransform mat = viewPort.getAffineTransform();
|
||
140 | |||
141 | // Vamos a hacerlo en trozos de AxH
|
||
142 | Rectangle r = g.getClipRect();
|
||
143 | numW = (int) (r.width) / A;
|
||
144 | numH = (int) (r.height) / H;
|
||
145 | |||
146 | |||
147 | double[] srcPts = new double[8]; |
||
148 | double[] dstPts= new double[8]; |
||
149 | |||
150 | yProv = (int) r.y;
|
||
151 | for (stepY=0; stepY < numH+1; stepY++) |
||
152 | { |
||
153 | if ((yProv + H) > r.getMaxY())
|
||
154 | altoAux = (int) r.getMaxY() - yProv;
|
||
155 | else
|
||
156 | altoAux = H; |
||
157 | |||
158 | xProv = (int) r.x;
|
||
159 | for (stepX=0; stepX < numW+1; stepX++) |
||
160 | { |
||
161 | if ((xProv + A) > r.getMaxX())
|
||
162 | anchoAux = (int) r.getMaxX() - xProv;
|
||
163 | else
|
||
164 | anchoAux = A; |
||
165 | |||
166 | Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux); |
||
167 | |||
168 | // Parte que dibuja
|
||
169 | srcPts[0] = xProv;
|
||
170 | srcPts[1] = yProv;
|
||
171 | srcPts[2] = xProv + anchoAux+1; |
||
172 | srcPts[3] = yProv;
|
||
173 | srcPts[4] = xProv + anchoAux+1; |
||
174 | srcPts[5] = yProv + altoAux+1; |
||
175 | srcPts[6] = xProv;
|
||
176 | srcPts[7] = yProv + altoAux+1; |
||
177 | |||
178 | try {
|
||
179 | mat.inverseTransform(srcPts, 0, dstPts, 0, 4); |
||
180 | Rectangle2D.Double rectCuadricula = new Rectangle2D.Double( |
||
181 | dstPts[0], dstPts[1], |
||
182 | dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]); |
||
183 | Extent extent = new Extent(rectCuadricula);
|
||
184 | |||
185 | Dimension tam = new Dimension(anchoAux+1, altoAux+1); |
||
186 | ViewPort vp = viewPort.cloneViewPort(); |
||
187 | vp.setExtent(rectCuadricula); |
||
188 | vp.setImageSize(tam); |
||
189 | // ViewPortData vp = new ViewPortData(getProjection(), extent, tam);
|
||
190 | // vp.setMat(mat);
|
||
191 | // rasterList.draw(g2, vp);
|
||
192 | draw(null, g, viewPort, cancel);
|
||
193 | |||
194 | } catch (NoninvertibleTransformException e) { |
||
195 | // TODO Auto-generated catch block
|
||
196 | e.printStackTrace(); |
||
197 | } |
||
198 | // Fin parte que dibuja
|
||
199 | xProv = xProv + A; |
||
200 | } |
||
201 | yProv = yProv + H; |
||
202 | } |
||
203 | |||
204 | 569 | luisw | } |
205 | 214 | fernando | } |