svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / raster / impl / DefaultRasterQuery.java @ 43876
History | View | Annotate | Download (5.79 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.dal.raster.impl; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.Collections; |
27 |
import java.util.HashMap; |
28 |
import java.util.List; |
29 |
import java.util.Map; |
30 |
import java.util.Map.Entry; |
31 |
import java.util.Set; |
32 |
|
33 |
import org.gvsig.fmap.dal.raster.BandQuery; |
34 |
import org.gvsig.fmap.dal.raster.RasterQuery; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.dynobject.DynStruct; |
38 |
import org.gvsig.tools.persistence.PersistenceManager; |
39 |
import org.gvsig.tools.persistence.PersistentState; |
40 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
41 |
|
42 |
/**
|
43 |
* Implements RasterQuery
|
44 |
*
|
45 |
* @author dmartinezizquierdo
|
46 |
*
|
47 |
*/
|
48 |
public class DefaultRasterQuery implements RasterQuery { |
49 |
|
50 |
private static final String PERSISTENCE_NAME = "RasterQuery"; |
51 |
private static final String PERSISTENCE_DESCRIPTION = ""; |
52 |
|
53 |
private static final String SCALE_FIELD_NAME = "scale"; |
54 |
private static final String PARAMETERS_FIELD_NAME = "queryParameters"; |
55 |
private static final String BAND_QUERIES_FIELD_NAME = "bandQueries"; |
56 |
private static final String CLIP_FIELD_NAME = "clip"; |
57 |
private static final String PIXEL_SIZE_NAME = "pixelSize"; |
58 |
|
59 |
private double scale; |
60 |
private Map<String, Object> queryParameters; |
61 |
private List<BandQuery> bandQueries; |
62 |
private Envelope clip;
|
63 |
private double pixelSize; |
64 |
|
65 |
/**
|
66 |
* @param store
|
67 |
*
|
68 |
*/
|
69 |
public DefaultRasterQuery() {
|
70 |
this.queryParameters = new HashMap<String, Object>(); |
71 |
this.bandQueries = new ArrayList<BandQuery>(); |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public List<BandQuery> getBands() { |
76 |
return Collections.unmodifiableList(this.bandQueries); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void addBand(BandQuery query) { |
81 |
this.bandQueries.add(query);
|
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void clearBands() { |
86 |
this.bandQueries.clear();
|
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void setScale(double scale) { |
91 |
this.scale = scale;
|
92 |
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public double getScale() { |
97 |
return scale;
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public Object getQueryParameter(String name) { |
102 |
return queryParameters.get(name);
|
103 |
} |
104 |
|
105 |
@Override
|
106 |
public void setQueryParameter(String name, Object value) { |
107 |
queryParameters.put(name, value); |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public Envelope getClip() {
|
112 |
return clip;
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public RasterQuery setClip(Envelope clip) {
|
117 |
this.clip = clip;
|
118 |
return this; |
119 |
} |
120 |
|
121 |
@Override
|
122 |
public double getPixelSize() { |
123 |
return pixelSize;
|
124 |
} |
125 |
|
126 |
@Override
|
127 |
public RasterQuery setPixelSize(double pixelSize) { |
128 |
this.pixelSize = pixelSize;
|
129 |
return this; |
130 |
} |
131 |
|
132 |
public static void registerPersistenceDefinition() { |
133 |
|
134 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
135 |
DynStruct definition = persistenceManager.getDefinition(PERSISTENCE_NAME); |
136 |
if (definition == null) { |
137 |
|
138 |
definition = |
139 |
persistenceManager.addDefinition(RasterQuery.class, PERSISTENCE_NAME, |
140 |
PERSISTENCE_DESCRIPTION, null, null); |
141 |
definition.addDynFieldDouble(SCALE_FIELD_NAME); |
142 |
definition.addDynFieldMap(PARAMETERS_FIELD_NAME); |
143 |
definition.addDynFieldList(BAND_QUERIES_FIELD_NAME).setClassOfItems(BandQuery.class); |
144 |
definition.addDynFieldObject(CLIP_FIELD_NAME).setClassOfValue(Envelope.class); |
145 |
definition.addDynFieldDouble(PIXEL_SIZE_NAME); |
146 |
} |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public void saveToState(PersistentState state) throws PersistenceException { |
151 |
state.set("scale", this.scale); |
152 |
state.set("queryParameters", this.queryParameters); |
153 |
state.set("bands", this.bandQueries); |
154 |
state.set("clip", this.clip); |
155 |
state.set("pixelSize", this.pixelSize); |
156 |
} |
157 |
|
158 |
@Override
|
159 |
public void loadFromState(PersistentState state) throws PersistenceException { |
160 |
this.queryParameters =
|
161 |
new HashMap<String, Object>((Map<String, Object>) state.get("queryParameters")); |
162 |
this.scale = state.getDouble("scale"); |
163 |
this.bandQueries = new ArrayList<BandQuery>((List<BandQuery>) state.get("bands")); |
164 |
this.clip = (Envelope) state.get("clip"); |
165 |
this.pixelSize = state.getDouble("pixelSize"); |
166 |
|
167 |
} |
168 |
|
169 |
@Override
|
170 |
public RasterQuery clone() throws CloneNotSupportedException { |
171 |
RasterQuery rq = new DefaultRasterQuery();
|
172 |
|
173 |
for (BandQuery bandQuery : this.getBands()) { |
174 |
rq.addBand((BandQuery) bandQuery.clone()); |
175 |
} |
176 |
if(this.getClip()!=null){ |
177 |
rq.setClip((Envelope) this.getClip().clone());
|
178 |
} |
179 |
Set<Entry<String, Object>> entries = queryParameters.entrySet(); |
180 |
for (Entry<String, Object> entry : entries) { |
181 |
rq.setQueryParameter(entry.getKey(), entry.getValue()); |
182 |
} |
183 |
rq.setScale(scale); |
184 |
rq.setPixelSize(pixelSize); |
185 |
|
186 |
return rq;
|
187 |
} |
188 |
} |