Statistics
| Revision:

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 / store / properties / RemoteStoreHistogram.java @ 1081

History | View | Annotate | Download (6 KB)

1
/* 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.store.properties;
23

    
24
import org.gvsig.fmap.dal.coverage.RasterLocator;
25
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
26
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
27
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
32
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters;
33
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
34
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
35
import org.gvsig.fmap.dal.exception.CloseException;
36
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
37
import org.gvsig.tools.locator.LocatorException;
38

    
39
/**
40
 * Class to get histograms from a remote service. If the image has a fixed
41
 * size then a MultiDataStoreHistogram will build the histogram.
42
 * 
43
 * @author Nacho Brodin (nachobrodin@gmail.com)
44
 */
45
public class RemoteStoreHistogram extends MultiProviderHistogramComputer {
46
        private RemoteRasterProvider                provider            = null;
47
        private HistogramComputer                   lastBufferHistogram = null;
48
        
49
        /**
50
         * Constructor
51
         * @param dataset
52
         */
53
        public RemoteStoreHistogram(RemoteRasterProvider prov) {
54
                super(prov);
55
                this.provider = prov;
56
        }
57
        
58
        /**
59
         * Obtiene el histograma. Pregunta a todos los datasets que forman el multidataset
60
         * por su histograma y luego los fusiona.
61
         * @return histograma 
62
         * @throws HistogramException 
63
         */
64
        public BufferHistogram getBufferHistogram()
65
                throws ProcessInterruptedException, HistogramException {
66
                if(((RemoteStoreParameters)provider.getDataParameters()).isSizeFixed()) 
67
                        return super.getBufferHistogram();
68
                else {
69
                        ProviderServices provServ = RasterLocator.getManager().getProviderServices();
70
                        RasterDataParameters storeParameters = provServ.createParameters(
71
                                        provider.getLastRequest().getPath());
72
                        storeParameters.setSRS(provider.getProjection());
73
                        
74
                        try {
75
                                RasterDataStore mrs = RasterLocator.getManager().open(storeParameters);
76
                                lastBufferHistogram = mrs.getHistogramComputer();
77
                                BufferHistogram bh = lastBufferHistogram.getBufferHistogram();
78
                                mrs.close();
79
                                return bh;
80
                        } catch (LocatorException e) {
81
                                throw new HistogramException(e.getMessage(), e);
82
                        } catch (NotSupportedExtensionException e) {
83
                                throw new HistogramException(e.getMessage(), e);
84
                        } catch (RasterDriverException e) {
85
                                throw new HistogramException(e.getMessage(), e);
86
                        } catch (CloseException e) {
87
                                throw new HistogramException(e.getMessage(), e);
88
                        } 
89
                }
90
        }
91

    
92
        /**
93
         * Pone a cero el porcentaje de progreso del proceso de calculo de histograma
94
         */
95
        public void resetPercent() {
96
                if(((RemoteStoreParameters)provider.getDataParameters()).isSizeFixed()) 
97
                        super.resetPercent();
98
                else {
99
                        if(lastBufferHistogram != null)
100
                                lastBufferHistogram.resetPercent();
101
                }
102
        }
103

    
104
        /**
105
         * Obtiene el porcentaje de proceso en la construcci?n del histograma,
106
         * @return porcentaje de progreso
107
         */
108
        public int getPercent() {
109
                if(((RemoteStoreParameters)provider.getDataParameters()).isSizeFixed()) 
110
                        return super.getPercent();
111
                else {
112
                        if(lastBufferHistogram != null)
113
                                return lastBufferHistogram.getPercent();
114
                }
115
                return 0;
116
        }
117

    
118
        /*
119
         * (non-Javadoc)
120
         * @see org.gvsig.fmap.dal.coverage.dataset.Histogram#getMaximum()
121
         */
122
        public double getMaximum() {
123
                if(((RemoteStoreParameters)provider.getDataParameters()).isSizeFixed()) 
124
                        return super.getMaximum();
125
                else {
126
                        ProviderServices provServ = RasterLocator.getManager().getProviderServices();
127
                        RasterDataParameters storeParameters = provServ.createParameters(
128
                                        provider.getLastRequest().getPath());
129
                        storeParameters.setSRS(provider.getProjection());
130
                        
131
                        try {
132
                                RasterDataStore mrs = RasterLocator.getManager().open(storeParameters);
133
                                double res = mrs.getHistogramComputer().getMaximum();
134
                                mrs.close();
135
                                return res;
136
                        } catch (LocatorException e) {
137
                                return 0;
138
                        } catch (NotSupportedExtensionException e) {
139
                                return 0;
140
                        } catch (RasterDriverException e) {
141
                                return 0;
142
                        } catch (CloseException e) {
143
                                return 0;
144
                        } 
145
                }
146
        }
147

    
148
        /*
149
         * (non-Javadoc)
150
         * @see org.gvsig.fmap.dal.coverage.dataset.Histogram#getMinimum()
151
         */
152
        public double getMinimum() {
153
                if(((RemoteStoreParameters)provider.getDataParameters()).isSizeFixed()) 
154
                        return super.getMinimum();
155
                else {
156
                        ProviderServices provServ = RasterLocator.getManager().getProviderServices();
157
                        RasterDataParameters storeParameters = provServ.createParameters(
158
                                        provider.getLastRequest().getPath());
159
                        storeParameters.setSRS(provider.getProjection());
160
                        
161
                        try {
162
                                RasterDataStore mrs = RasterLocator.getManager().open(storeParameters);
163
                                double res = mrs.getHistogramComputer().getMinimum();
164
                                mrs.close();
165
                                return res;
166
                        } catch (LocatorException e) {
167
                                return 0;
168
                        } catch (NotSupportedExtensionException e) {
169
                                return 0;
170
                        } catch (RasterDriverException e) {
171
                                return 0;
172
                        } catch (CloseException e) {
173
                                return 0;
174
                        }
175
                }
176
        }
177
}