gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / buffer / cache / CacheDataFromDriverServer.java @ 4181
History | View | Annotate | Download (4.3 KB)
1 | 2443 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.raster.impl.buffer.cache; |
||
23 | |||
24 | import java.io.IOException; |
||
25 | |||
26 | import org.gvsig.fmap.dal.coverage.RasterLocator; |
||
27 | import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
||
28 | import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
||
29 | import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
||
30 | import org.gvsig.fmap.dal.coverage.exception.QueryException; |
||
31 | import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
||
32 | import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
||
33 | import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
||
34 | import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
||
35 | import org.gvsig.raster.impl.provider.RasterProvider; |
||
36 | import org.gvsig.raster.impl.store.DefaultRasterStore; |
||
37 | import org.slf4j.Logger; |
||
38 | import org.slf4j.LoggerFactory; |
||
39 | |||
40 | |||
41 | 4181 | fdiaz | /**
|
42 | 2443 | nbrodin | * Servidor de datos de cach?. Esta clase es la encargada de recuperar las p?ginas
|
43 | * cuando le son solicitadas. Implementar? el interfaz ICacheDataSource, aunque esta
|
||
44 | * clase se encargar? de servir p?ginas de solo lectura. Las p?ginas son servidas directamente desde
|
||
45 | * un RasterDataset y un objeto de este tipo representa a una sola p?gina, por lo que tendr? asociado
|
||
46 | * el extent correspondiente al trozo de p?gina que sirve.
|
||
47 | 4181 | fdiaz | *
|
48 | 2443 | nbrodin | * @author Nacho Brodin (nachobrodin@gmail.com)
|
49 | *
|
||
50 | */
|
||
51 | public class CacheDataFromDriverServer implements ICacheDataSource { |
||
52 | private Logger log = LoggerFactory.getLogger(CacheDataFromDriverServer.class); |
||
53 | private AbstractRasterProvider provider = null; |
||
54 | 4181 | fdiaz | private Extent pageExtent = null; |
55 | |||
56 | 2443 | nbrodin | /**
|
57 | 4181 | fdiaz | * Constructor.
|
58 | * Crea el identificador para todos los trozos de cach? que se guardar?n en disco.
|
||
59 | 2443 | nbrodin | * @param id Identificador de fichero. Si este es null se calcula uno autom?ticamente
|
60 | * @param numBand N?mero de banda
|
||
61 | * @param numPag N?mero de p?gina
|
||
62 | 4181 | fdiaz | * @throws RasterDriverException
|
63 | * @throws NotSupportedExtensionException
|
||
64 | 2443 | nbrodin | */
|
65 | public CacheDataFromDriverServer(RasterProvider provider, int numPag, Extent extent) { |
||
66 | if(provider instanceof AbstractRasterProvider) |
||
67 | this.provider = (AbstractRasterProvider)provider;
|
||
68 | pageExtent = extent; |
||
69 | } |
||
70 | |||
71 | public void loadPage(PageBandBuffer pageBuffer) throws ProcessInterruptedException { |
||
72 | //Creamos un BandList con todas las bandas del fichero
|
||
73 | /*BandList bandList = new BandListImpl();
|
||
74 | for(int i = 0; i < provider.getBandCount();i++) {
|
||
75 | try {
|
||
76 | DatasetBand band = new DatasetBandImpl(provider.getURIByBand(i), i, provider.getDataType()[i], provider.getBandCount());
|
||
77 | bandList.addBand(band, i);
|
||
78 | } catch(BandNotFoundInListException ex) {
|
||
79 | //No a?adimos la banda
|
||
80 | }
|
||
81 | }*/
|
||
82 | try {
|
||
83 | DefaultRasterStore store = new DefaultRasterStore();
|
||
84 | store.setProvider(provider); |
||
85 | 4181 | fdiaz | |
86 | 2443 | nbrodin | RasterQuery q = RasterLocator.getManager().createQuery(); |
87 | q.setAreaOfInterest(pageExtent, pageBuffer.getWidth(), pageBuffer.getHeight()); |
||
88 | q.setAllDrawableBands(); |
||
89 | q.setBufferForProviders(pageBuffer); |
||
90 | 4181 | fdiaz | |
91 | 2443 | nbrodin | provider.getDataSet((SpiRasterQuery)q); |
92 | //dataset.getWindow(pageExtent, bandList, pageBuffer);
|
||
93 | } catch (RasterDriverException e) {
|
||
94 | log.debug("Error loading the PageBandBuffer", e);
|
||
95 | } catch (QueryException e) {
|
||
96 | log.debug("Error loading the PageBandBuffer", e);
|
||
97 | } |
||
98 | } |
||
99 | |||
100 | public void savePage(PageBandBuffer pageBuffer) throws IOException { |
||
101 | 4181 | fdiaz | //Read Only
|
102 | 2443 | nbrodin | } |
103 | |||
104 | public void delete() { |
||
105 | //Read Only
|
||
106 | } |
||
107 | 4181 | fdiaz | |
108 | 2443 | nbrodin | public String getPath() { |
109 | if(provider != null) |
||
110 | 4181 | fdiaz | return provider.getURIOfFirstProvider().getPath();
|
111 | 2443 | nbrodin | return null; |
112 | } |
||
113 | } |