Revision 2022
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/DefaultWMSIOLibrary.java | ||
---|---|---|
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.wms.io; |
|
23 |
|
|
24 |
import org.gvsig.i18n.Messages; |
|
25 |
import org.gvsig.raster.wms.io.time.DefaultDimension; |
|
26 |
import org.gvsig.raster.wms.io.time.TimeDimension; |
|
27 |
import org.gvsig.tools.library.AbstractLibrary; |
|
28 |
import org.gvsig.tools.library.LibraryException; |
|
29 |
/** |
|
30 |
* |
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
32 |
*/ |
|
33 |
public class DefaultWMSIOLibrary extends AbstractLibrary { |
|
34 |
|
|
35 |
/*public DefaultWMSIOLibrary() { |
|
36 |
super(DefaultWMSIOLibrary.class,Library.TYPE.IMPL); |
|
37 |
require(ToolsLibrary.class); |
|
38 |
require(DALLibrary.class); |
|
39 |
require(DALFileLibrary.class); |
|
40 |
}*/ |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void doInitialize() throws LibraryException { |
|
44 |
//RasterLibrary.wakeUp(); |
|
45 |
WMSLayerNode.registerPersistent(); |
|
46 |
RemoteWMSStyle.registerPersistent(); |
|
47 |
DefaultDimension.registerPersistent(); |
|
48 |
TimeDimension.registerPersistent(); |
|
49 |
WMSDataParametersImpl.registerPersistence(); |
|
50 |
|
|
51 |
Messages.addResourceFamily("org.gvsig.raster.wms.io.i18n.text", |
|
52 |
DefaultWMSIOLibrary.class.getClassLoader(), |
|
53 |
DefaultWMSIOLibrary.class.getClass().getName()); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
protected void doPostInitialize() throws LibraryException { |
|
58 |
WMSServerExplorerParameters.registerDynClass(); |
|
59 |
WMSDataParametersImpl.registerDynClass(); |
|
60 |
WMSProvider.register(); |
|
61 |
} |
|
62 |
} |
|
0 | 63 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/WMSLayerNode.java | ||
---|---|---|
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.wms.io; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.List; |
|
27 |
import java.util.Vector; |
|
28 |
|
|
29 |
import org.gvsig.raster.wms.io.time.DefaultDimension; |
|
30 |
import org.gvsig.raster.wms.io.time.RemoteTimeDimension; |
|
31 |
import org.gvsig.raster.wms.io.time.TimeDimension; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.dynobject.DynStruct; |
|
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
35 |
import org.gvsig.tools.persistence.Persistent; |
|
36 |
import org.gvsig.tools.persistence.PersistentState; |
|
37 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
38 |
|
|
39 |
/** |
|
40 |
* Class defining the node of the layer tree of a common WMS service. |
|
41 |
* @author jaume |
|
42 |
*/ |
|
43 |
@SuppressWarnings("unchecked") |
|
44 |
public class WMSLayerNode implements Persistent { |
|
45 |
private String _name = null; |
|
46 |
private String _title = null; |
|
47 |
private Vector srs = null; |
|
48 |
private boolean queryable; |
|
49 |
private boolean transparency; |
|
50 |
private String lAbstract = null; |
|
51 |
private String latLonBox = null; |
|
52 |
private int selectedStyleIndex = 0; |
|
53 |
private ArrayList<RemoteWMSStyle> styles = new ArrayList<RemoteWMSStyle>(); |
|
54 |
private ArrayList<RemoteTimeDimension> dimensions = null; |
|
55 |
private ArrayList<String> keywords = null; |
|
56 |
private ArrayList children = new ArrayList(); |
|
57 |
private WMSLayerNode _parent = null; |
|
58 |
private Dimension fixedSize = null; |
|
59 |
|
|
60 |
/* |
|
61 |
* (non-Javadoc) |
|
62 |
* @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState) |
|
63 |
*/ |
|
64 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
65 |
this._name = state.getString("_name"); |
|
66 |
this._title = state.getString("_title"); |
|
67 |
|
|
68 |
List<String> srs = state.getList("srs"); |
|
69 |
if(srs != null) { |
|
70 |
this.srs = new Vector(); |
|
71 |
this.srs.addAll(srs); |
|
72 |
} |
|
73 |
|
|
74 |
this.queryable = state.getBoolean("queryable"); |
|
75 |
this.transparency = state.getBoolean("transparency"); |
|
76 |
this.lAbstract = state.getString("lAbstract"); |
|
77 |
this.latLonBox = state.getString("latLonBox"); |
|
78 |
this.selectedStyleIndex = state.getInt("selectedStyleIndex"); |
|
79 |
|
|
80 |
List<RemoteWMSStyle> styles = state.getList("styles"); |
|
81 |
if(styles != null) { |
|
82 |
this.styles = new ArrayList<RemoteWMSStyle>(); |
|
83 |
this.styles.addAll(styles); |
|
84 |
} |
|
85 |
|
|
86 |
List<RemoteTimeDimension> dimensions = state.getList("dimensions"); |
|
87 |
if(dimensions != null) { |
|
88 |
this.dimensions = new ArrayList<RemoteTimeDimension>(); |
|
89 |
this.dimensions.addAll(dimensions); |
|
90 |
} |
|
91 |
|
|
92 |
List<String> keywords = state.getList("keywords"); |
|
93 |
if(keywords != null) { |
|
94 |
this.keywords = new ArrayList<String>(); |
|
95 |
this.keywords.addAll(keywords); |
|
96 |
} |
|
97 |
|
|
98 |
List<WMSLayerNode> children = state.getList("children"); |
|
99 |
if(children != null) { |
|
100 |
this.children = new ArrayList<WMSLayerNode>(); |
|
101 |
this.children.addAll(children); |
|
102 |
} |
|
103 |
|
|
104 |
this._parent = (WMSLayerNode)state.get("_parent"); |
|
105 |
this.fixedSize = (Dimension)state.get("fixedSize"); |
|
106 |
} |
|
107 |
|
|
108 |
/* |
|
109 |
* (non-Javadoc) |
|
110 |
* @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState) |
|
111 |
*/ |
|
112 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
113 |
state.set("_name", _name); |
|
114 |
state.set("_title", _title); |
|
115 |
state.set("srs", srs); |
|
116 |
state.set("queryable", queryable); |
|
117 |
state.set("transparency", transparency); |
|
118 |
state.set("lAbstract", lAbstract); |
|
119 |
state.set("latLonBox", latLonBox); |
|
120 |
state.set("selectedStyleIndex", selectedStyleIndex); |
|
121 |
state.set("styles", styles); |
|
122 |
state.set("dimensions", dimensions); |
|
123 |
state.set("keywords", keywords); |
|
124 |
state.set("children", children); |
|
125 |
state.set("_parent", _parent); |
|
126 |
state.set("fixedSize", fixedSize); |
|
127 |
} |
|
128 |
|
|
129 |
public static void registerPersistent() { |
|
130 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
131 |
DynStruct definition = manager.getDefinition("WMSLayerNode_Persistent"); |
|
132 |
if( definition == null ) { |
|
133 |
definition = manager.addDefinition( |
|
134 |
WMSLayerNode.class, |
|
135 |
"WMSLayerNode_Persistent", |
|
136 |
"WMSLayerNode Persistence", |
|
137 |
null, |
|
138 |
null |
|
139 |
); |
|
140 |
} |
|
141 |
|
|
142 |
definition.addDynFieldString("_name").setMandatory(false); |
|
143 |
definition.addDynFieldString("_title").setMandatory(false); |
|
144 |
definition.addDynFieldList("srs").setClassOfItems(String.class).setMandatory(false); |
|
145 |
definition.addDynFieldBoolean("queryable").setMandatory(false); |
|
146 |
definition.addDynFieldBoolean("transparency").setMandatory(false); |
|
147 |
definition.addDynFieldString("lAbstract").setMandatory(false); |
|
148 |
definition.addDynFieldString("latLonBox").setMandatory(false); |
|
149 |
definition.addDynFieldInt("selectedStyleIndex").setMandatory(false); |
|
150 |
definition.addDynFieldList("styles").setClassOfItems(RemoteWMSStyle.class).setMandatory(false); |
|
151 |
definition.addDynFieldList("dimensions").setClassOfItems(RemoteTimeDimension.class).setMandatory(false); |
|
152 |
definition.addDynFieldList("keywords").setClassOfItems(String.class).setMandatory(false); |
|
153 |
definition.addDynFieldList("children").setClassOfItems(WMSLayerNode.class).setMandatory(false); |
|
154 |
definition.addDynFieldObject("_parent").setClassOfValue(WMSLayerNode.class).setMandatory(false); |
|
155 |
definition.addDynFieldObject("fixedSize").setClassOfValue(Dimension.class).setMandatory(false); |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* @return Returns the name. |
|
160 |
*/ |
|
161 |
public String getName() { |
|
162 |
return _name; |
|
163 |
} |
|
164 |
|
|
165 |
public ArrayList getChildren() { |
|
166 |
return children; |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* @param name The name to set. |
|
171 |
*/ |
|
172 |
public void setName(String name) { |
|
173 |
this._name = name; |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* @return Returns the namedStyles. |
|
178 |
*/ |
|
179 |
public ArrayList<RemoteWMSStyle> getStyles() { |
|
180 |
return styles; |
|
181 |
} |
|
182 |
|
|
183 |
public ArrayList<String> getKeywords() { |
|
184 |
return keywords; |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* @return Returns the queryable. |
|
189 |
*/ |
|
190 |
public boolean isQueryable() { |
|
191 |
return queryable; |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* @param queryable The queryable to set. |
|
196 |
*/ |
|
197 |
public void setQueryable(boolean queryable) { |
|
198 |
this.queryable = queryable; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* @return Returns the srs. |
|
203 |
*/ |
|
204 |
public Vector getAllSrs() { |
|
205 |
if ((srs.size() == 0) && _parent!=null) |
|
206 |
return _parent.getAllSrs(); |
|
207 |
return srs; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* @param srs The srs to set. |
|
212 |
*/ |
|
213 |
public void setSrs(Vector srs) { |
|
214 |
this.srs = srs; |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* @return Returns the title. |
|
219 |
*/ |
|
220 |
public String getTitle() { |
|
221 |
return _title; |
|
222 |
} |
|
223 |
|
|
224 |
/* |
|
225 |
* (non-Javadoc) |
|
226 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setTitle(java.lang.String) |
|
227 |
*/ |
|
228 |
public void setTitle(String title) { |
|
229 |
this._title = title.trim(); |
|
230 |
} |
|
231 |
|
|
232 |
/** |
|
233 |
* @return Returns the transparency. |
|
234 |
*/ |
|
235 |
public boolean isTransparent() { |
|
236 |
return transparency; |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* @param transparency The transparency to set. |
|
241 |
*/ |
|
242 |
public void setTransparency(boolean transparency) { |
|
243 |
this.transparency = transparency; |
|
244 |
} |
|
245 |
|
|
246 |
/** |
|
247 |
* Sets the list of sons of this layer. |
|
248 |
* @param children |
|
249 |
*/ |
|
250 |
public void setChildren(ArrayList children) { |
|
251 |
this.children = children; |
|
252 |
} |
|
253 |
|
|
254 |
/* |
|
255 |
* (non-Javadoc) |
|
256 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getParent() |
|
257 |
*/ |
|
258 |
public WMSLayerNode getParent() { |
|
259 |
return _parent; |
|
260 |
} |
|
261 |
|
|
262 |
/* |
|
263 |
* (non-Javadoc) |
|
264 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setParent(org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode) |
|
265 |
*/ |
|
266 |
public void setParent(WMSLayerNode parentNode) { |
|
267 |
this._parent = parentNode; |
|
268 |
} |
|
269 |
|
|
270 |
/* |
|
271 |
* (non-Javadoc) |
|
272 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getDimensions() |
|
273 |
*/ |
|
274 |
public ArrayList<RemoteTimeDimension> getDimensions() { |
|
275 |
return dimensions; |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* Gets the layer abstract. |
|
280 |
* |
|
281 |
* @return Returns the abstract. |
|
282 |
*/ |
|
283 |
public String getAbstract() { |
|
284 |
return lAbstract; |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* Sets the layer abstract. |
|
289 |
* |
|
290 |
* @param abstract The abstract to set. |
|
291 |
*/ |
|
292 |
public void setAbstract(String _abstract) { |
|
293 |
lAbstract = _abstract; |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* @param name |
|
298 |
* @param units |
|
299 |
* @param unitSymbol |
|
300 |
* @param dimensionExpression |
|
301 |
*/ |
|
302 |
public void addDimension(String name, String units, String unitSymbol, String dimExpression) { |
|
303 |
if (dimensions == null) |
|
304 |
dimensions = new ArrayList<RemoteTimeDimension>(); |
|
305 |
if (name.equalsIgnoreCase("time")) { |
|
306 |
try { |
|
307 |
dimensions.add(new TimeDimension(units, unitSymbol, |
|
308 |
dimExpression)); |
|
309 |
} catch (IllegalArgumentException e) { |
|
310 |
// The TIME class does not yet support this kind of time so it |
|
311 |
// will be treated as a DefaultDimension |
|
312 |
dimensions.add(new DefaultDimension(name.toUpperCase(), |
|
313 |
units, unitSymbol, dimExpression)); |
|
314 |
} |
|
315 |
} else if (name.equalsIgnoreCase("sequence")) { |
|
316 |
// TODO Not yet implemented |
|
317 |
return; |
|
318 |
} else { |
|
319 |
dimensions.add(new DefaultDimension(name.toUpperCase(), units, |
|
320 |
unitSymbol, dimExpression)); |
|
321 |
} |
|
322 |
|
|
323 |
} |
|
324 |
|
|
325 |
|
|
326 |
public void setLatLonBox(String _latLonBox) { |
|
327 |
latLonBox = _latLonBox; |
|
328 |
} |
|
329 |
|
|
330 |
public String getLatLonBox() { |
|
331 |
return latLonBox; |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* When a server cannot renderize images but just server them in constant size and |
|
336 |
* BBox, the layer must have this value set in order to correctly work. |
|
337 |
* |
|
338 |
* @param fixedWidth - the constant value for the image width |
|
339 |
* @param fixedHeight - the constant value for the image height |
|
340 |
*/ |
|
341 |
public void setFixedSize(int fixedWidth, int fixedHeight) { |
|
342 |
fixedSize = new Dimension(fixedWidth, fixedHeight); |
|
343 |
} |
|
344 |
|
|
345 |
/* |
|
346 |
* (non-Javadoc) |
|
347 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getFixedSize() |
|
348 |
*/ |
|
349 |
public Dimension getFixedSize() { |
|
350 |
return fixedSize; |
|
351 |
} |
|
352 |
|
|
353 |
/* |
|
354 |
* (non-Javadoc) |
|
355 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#isSizeFixed() |
|
356 |
*/ |
|
357 |
public boolean isSizeFixed() { |
|
358 |
return fixedSize != null && |
|
359 |
fixedSize.getWidth() > 0 && |
|
360 |
fixedSize.getHeight() > 0; |
|
361 |
} |
|
362 |
|
|
363 |
/** |
|
364 |
* |
|
365 |
* @param _name |
|
366 |
* @param _title |
|
367 |
* @param _abstract |
|
368 |
*/ |
|
369 |
public void addStyle(org.gvsig.remoteclient.wms.WMSStyle style) { |
|
370 |
if (style.getName().equalsIgnoreCase("default")) |
|
371 |
selectedStyleIndex = styles.size(); |
|
372 |
if (styles == null) |
|
373 |
styles = new ArrayList<RemoteWMSStyle>(); |
|
374 |
styles.add(new RemoteWMSStyle(style, this)); |
|
375 |
|
|
376 |
} |
|
377 |
|
|
378 |
/* |
|
379 |
* (non-Javadoc) |
|
380 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getSelectedStyle() |
|
381 |
*/ |
|
382 |
public RemoteWMSStyle getSelectedStyle() { |
|
383 |
if (styles == null || selectedStyleIndex > styles.size() - 1 || selectedStyleIndex == -1) |
|
384 |
return null; |
|
385 |
return (RemoteWMSStyle) styles.get(selectedStyleIndex); |
|
386 |
} |
|
387 |
|
|
388 |
/* |
|
389 |
* (non-Javadoc) |
|
390 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setSelectedStyleByIndex(int) |
|
391 |
*/ |
|
392 |
public void setSelectedStyleByIndex(int index) { |
|
393 |
selectedStyleIndex = index; |
|
394 |
} |
|
395 |
|
|
396 |
/* |
|
397 |
* (non-Javadoc) |
|
398 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setSelectedStyleByName(java.lang.String) |
|
399 |
*/ |
|
400 |
public void setSelectedStyleByName(String styName) { |
|
401 |
if (styName == null || styName.equals("")) |
|
402 |
setSelectedStyleByIndex(-1); |
|
403 |
for (int i = 0; i < styles.size(); i++) { |
|
404 |
RemoteWMSStyle sty = (RemoteWMSStyle) styles.get(i); |
|
405 |
if (sty.name.equals(styName)) { |
|
406 |
setSelectedStyleByIndex(i); |
|
407 |
return; |
|
408 |
} |
|
409 |
|
|
410 |
} |
|
411 |
setSelectedStyleByIndex(-1); |
|
412 |
} |
|
413 |
|
|
414 |
public void addKeyword(String keyword) { |
|
415 |
if (keywords == null) |
|
416 |
keywords = new ArrayList<String>(); |
|
417 |
keywords.add(keyword); |
|
418 |
} |
|
419 |
|
|
420 |
public String toString(){ |
|
421 |
String str; |
|
422 |
if (getName()==null) |
|
423 |
str = getTitle(); |
|
424 |
else |
|
425 |
str = "["+getName()+"] "+getTitle(); |
|
426 |
return str; |
|
427 |
} |
|
428 |
|
|
429 |
/* |
|
430 |
* (non-Javadoc) |
|
431 |
* @see java.lang.Object#clone() |
|
432 |
*/ |
|
433 |
public Object clone() throws CloneNotSupportedException { |
|
434 |
WMSLayerNode clone = new WMSLayerNode(); |
|
435 |
clone._name = this._name; |
|
436 |
clone.queryable = this.queryable; |
|
437 |
clone.srs = this.srs; |
|
438 |
clone._title = this._title; |
|
439 |
clone.transparency = this.transparency; |
|
440 |
clone.styles = new ArrayList<RemoteWMSStyle>(); |
|
441 |
clone.lAbstract = this.lAbstract; |
|
442 |
clone.latLonBox = this.latLonBox; |
|
443 |
clone.selectedStyleIndex = this.selectedStyleIndex; |
|
444 |
|
|
445 |
if (keywords != null) { |
|
446 |
clone.keywords = new ArrayList<String>(keywords.size()); |
|
447 |
for (int i = 0; i < keywords.size(); i++) { |
|
448 |
clone.keywords.add((String) keywords.get(i)); |
|
449 |
} |
|
450 |
} |
|
451 |
if (styles != null) |
|
452 |
for (int i=0; i<styles.size(); i++){ |
|
453 |
RemoteWMSStyle sty = (RemoteWMSStyle) this.styles.get(i).clone(); |
|
454 |
((RemoteWMSStyle)sty).parent = this; |
|
455 |
clone.styles.add(sty); |
|
456 |
} |
|
457 |
|
|
458 |
if (dimensions!=null) |
|
459 |
for (int i = 0; i < dimensions.size(); i++) { |
|
460 |
clone.dimensions = new ArrayList<RemoteTimeDimension>(); |
|
461 |
clone.dimensions.add((RemoteTimeDimension) this.dimensions.get(i)); |
|
462 |
} |
|
463 |
|
|
464 |
return clone; |
|
465 |
} |
|
466 |
|
|
467 |
} |
|
0 | 468 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/WMSServerExplorer.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.raster.wms.io; |
|
29 |
|
|
30 |
import java.awt.geom.Rectangle2D; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStream; |
|
33 |
import java.net.InetAddress; |
|
34 |
import java.net.MalformedURLException; |
|
35 |
import java.net.URL; |
|
36 |
import java.net.URLConnection; |
|
37 |
import java.net.UnknownHostException; |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.Hashtable; |
|
40 |
import java.util.List; |
|
41 |
import java.util.Vector; |
|
42 |
|
|
43 |
import org.gvsig.compat.net.ICancellable; |
|
44 |
import org.gvsig.fmap.dal.DALLocator; |
|
45 |
import org.gvsig.fmap.dal.DataManager; |
|
46 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
47 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
48 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
49 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
50 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
|
51 |
import org.gvsig.fmap.dal.exception.DataException; |
|
52 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
53 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
54 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
|
55 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
56 |
import org.gvsig.i18n.Messages; |
|
57 |
|
|
58 |
/** |
|
59 |
* Explorer for a WMS server |
|
60 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
61 |
*/ |
|
62 |
public class WMSServerExplorer implements DataServerExplorer, DataServerExplorerProvider { |
|
63 |
public static final String NAME = "WMSRemoteServerExplorer"; |
|
64 |
private WMSConnector connector = null; |
|
65 |
private WMSServerExplorerParameters parameters = null; |
|
66 |
|
|
67 |
public WMSServerExplorer( |
|
68 |
WMSServerExplorerParameters parameters, |
|
69 |
DataServerExplorerProviderServices services) |
|
70 |
throws InitializeException { |
|
71 |
this.parameters = parameters; |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Gets the provider's name |
|
76 |
* @return |
|
77 |
*/ |
|
78 |
public String getDataStoreProviderName() { |
|
79 |
return WMSProvider.NAME; |
|
80 |
} |
|
81 |
|
|
82 |
/* |
|
83 |
* (non-Javadoc) |
|
84 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider#getDescription() |
|
85 |
*/ |
|
86 |
public String getDescription() { |
|
87 |
return WMSProvider.DESCRIPTION; |
|
88 |
} |
|
89 |
|
|
90 |
/* |
|
91 |
* (non-Javadoc) |
|
92 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getParameters(java.lang.String, int) |
|
93 |
*/ |
|
94 |
public DataStoreParameters getStoreParameters() { |
|
95 |
DataManager manager = DALLocator.getDataManager(); |
|
96 |
WMSDataParameters params = null; |
|
97 |
try { |
|
98 |
params = (WMSDataParameters) manager.createStoreParameters(this.getDataStoreProviderName()); |
|
99 |
params.setURI(parameters.getHost()); |
|
100 |
|
|
101 |
/*if(WMSProvider.TILED) { |
|
102 |
TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store"); |
|
103 |
tileParams.setDataParameters(params); |
|
104 |
return tileParams; |
|
105 |
} */ |
|
106 |
} catch (InitializeException e) { |
|
107 |
e.printStackTrace(); |
|
108 |
} catch (ProviderNotRegisteredException e) { |
|
109 |
e.printStackTrace(); |
|
110 |
} |
|
111 |
|
|
112 |
return params; |
|
113 |
} |
|
114 |
|
|
115 |
public boolean add(String provider, NewDataStoreParameters parameters, |
|
116 |
boolean overwrite) throws DataException { |
|
117 |
return false; |
|
118 |
} |
|
119 |
|
|
120 |
public boolean canAdd() { |
|
121 |
return false; |
|
122 |
} |
|
123 |
|
|
124 |
public boolean canAdd(String storeName) throws DataException { |
|
125 |
return false; |
|
126 |
} |
|
127 |
|
|
128 |
public NewDataStoreParameters getAddParameters(String storeName) |
|
129 |
throws DataException { |
|
130 |
return null; |
|
131 |
} |
|
132 |
|
|
133 |
public List getDataStoreProviderNames() { |
|
134 |
return null; |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
/* |
|
139 |
* (non-Javadoc) |
|
140 |
* @see org.gvsig.fmap.dal.DataServerExplorer#getParameters() |
|
141 |
*/ |
|
142 |
public DataServerExplorerParameters getParameters() { |
|
143 |
return parameters; |
|
144 |
} |
|
145 |
|
|
146 |
public List list() throws DataException { |
|
147 |
return null; |
|
148 |
} |
|
149 |
|
|
150 |
public List list(int mode) throws DataException { |
|
151 |
return null; |
|
152 |
} |
|
153 |
|
|
154 |
public void remove(DataStoreParameters parameters) throws DataException { |
|
155 |
|
|
156 |
} |
|
157 |
|
|
158 |
public void dispose() { |
|
159 |
|
|
160 |
} |
|
161 |
|
|
162 |
public String getProviderName() { |
|
163 |
return null; |
|
164 |
} |
|
165 |
|
|
166 |
//********************************************** |
|
167 |
//Connector |
|
168 |
//********************************************** |
|
169 |
|
|
170 |
/** |
|
171 |
* Connects to the server and throws a getCapabilities. This loads |
|
172 |
* the basic information to make requests. |
|
173 |
* @throws RemoteServiceException |
|
174 |
*/ |
|
175 |
public void connect(ICancellable cancellable, boolean updateCache) throws RemoteServiceException { |
|
176 |
URL url = null; |
|
177 |
|
|
178 |
try { |
|
179 |
url = new URL(parameters.getHost()); |
|
180 |
} catch (Exception e) { |
|
181 |
throw new RemoteServiceException(Messages.getText("malformed_url"), e); |
|
182 |
} |
|
183 |
try { |
|
184 |
connector = WMSProvider.getConnectorFromURL(url, updateCache); |
|
185 |
if (!connector.connect(updateCache, cancellable)) |
|
186 |
throw new RemoteServiceException(Messages.getText("error_connecting")); |
|
187 |
} catch (IOException e) { |
|
188 |
throw new RemoteServiceException(Messages.getText("error_connecting"), e); |
|
189 |
} |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Checks if the network and host are reachable |
|
195 |
* @param timeout for the host |
|
196 |
* @return true if both are reachable and false if they are not |
|
197 |
*/ |
|
198 |
public boolean isHostReachable(int timeout) { |
|
199 |
URL url = null; |
|
200 |
try { |
|
201 |
url = new URL(parameters.getHost()); |
|
202 |
URLConnection con = url.openConnection(); |
|
203 |
if(con == null) |
|
204 |
return false; |
|
205 |
con.connect(); |
|
206 |
InputStream stream = con.getInputStream(); |
|
207 |
if(stream == null) |
|
208 |
return false; |
|
209 |
} catch (MalformedURLException e) { |
|
210 |
return false; |
|
211 |
} catch (IOException e) { |
|
212 |
return false; |
|
213 |
} |
|
214 |
|
|
215 |
return true; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Checks if the network and host are reachable |
|
220 |
* @return true if both are reachable and false if they are not |
|
221 |
*/ |
|
222 |
public boolean isHostReachable() { |
|
223 |
int timeout = 10000; |
|
224 |
return isHostReachable(timeout); |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Returns true if this provider is connected to the server |
|
229 |
* @return |
|
230 |
*/ |
|
231 |
public boolean isConnected() { |
|
232 |
if(connector != null) |
|
233 |
return true; |
|
234 |
return false; |
|
235 |
} |
|
236 |
|
|
237 |
/** |
|
238 |
* Gets the description of this service |
|
239 |
* @return |
|
240 |
*/ |
|
241 |
public String getAbstract() { |
|
242 |
if(connector != null) |
|
243 |
return connector.getAbstract(); |
|
244 |
return null; |
|
245 |
} |
|
246 |
|
|
247 |
/** |
|
248 |
* Gets the list of raster formats supported by the server |
|
249 |
* @return |
|
250 |
*/ |
|
251 |
@SuppressWarnings("unchecked") |
|
252 |
public String[] getFormats() { |
|
253 |
if(connector != null) { |
|
254 |
Vector f = connector.getFormats(); |
|
255 |
ArrayList formatos = new ArrayList(); |
|
256 |
for (int i = 0; i < f.size(); i++) { |
|
257 |
formatos.add(f.elementAt(i)); |
|
258 |
} |
|
259 |
return (String[]) formatos.toArray(new String[0]); |
|
260 |
} |
|
261 |
return null; |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* Gets the list of raster information formats supported by the server |
|
266 |
* @return |
|
267 |
*/ |
|
268 |
@SuppressWarnings("unchecked") |
|
269 |
public String[] getInfoFormats() { |
|
270 |
if(connector != null) { |
|
271 |
Vector f = connector.getInfoFormats(); |
|
272 |
ArrayList formatos = new ArrayList(); |
|
273 |
for (int i = 0; i < f.size(); i++) { |
|
274 |
formatos.add(f.elementAt(i)); |
|
275 |
} |
|
276 |
return (String[]) formatos.toArray(new String[0]); |
|
277 |
} |
|
278 |
return null; |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Gets a tree of nodes which represents the server information |
|
283 |
* @return |
|
284 |
*/ |
|
285 |
public WMSLayerNode getLayerTree() { |
|
286 |
if(connector != null) { |
|
287 |
return connector.getLayersTree(); |
|
288 |
} |
|
289 |
return null; |
|
290 |
} |
|
291 |
|
|
292 |
/** |
|
293 |
* Gets the server title |
|
294 |
* @return |
|
295 |
*/ |
|
296 |
public String getServerType() { |
|
297 |
if (getVersion() == null) |
|
298 |
return "WMS"; |
|
299 |
return "WMS "+ getVersion(); |
|
300 |
} |
|
301 |
|
|
302 |
/** |
|
303 |
* Gets the online resources |
|
304 |
* @return |
|
305 |
*/ |
|
306 |
public Hashtable getOnlineResources() { |
|
307 |
if(connector != null) { |
|
308 |
return connector.getOnlineResources(); |
|
309 |
} |
|
310 |
return null; |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Gets the protocol supported by the server |
|
315 |
* @return |
|
316 |
*/ |
|
317 |
public String getVersion() { |
|
318 |
if(connector != null) { |
|
319 |
return (connector.getVersion() == null) ? "" : connector.getVersion(); |
|
320 |
} |
|
321 |
return null; |
|
322 |
} |
|
323 |
|
|
324 |
/* |
|
325 |
* (non-Javadoc) |
|
326 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getLayersExtent(java.lang.String[], java.lang.String) |
|
327 |
*/ |
|
328 |
public Rectangle2D getLayersExtent(String[] layerName, String srs) { |
|
329 |
return connector.getLayersExtent(layerName, srs); |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* Gets a layer using its name |
|
334 |
* @param layerName |
|
335 |
* @return |
|
336 |
*/ |
|
337 |
public WMSLayerNode getLayer(String layerName) { |
|
338 |
return connector.getLayer(layerName); |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* Gets the host URI |
|
343 |
* @return |
|
344 |
*/ |
|
345 |
public String getHost() { |
|
346 |
return parameters.getHost(); |
|
347 |
} |
|
348 |
|
|
349 |
/* |
|
350 |
* (non-Javadoc) |
|
351 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getBoundingBox(java.lang.String[], java.lang.String) |
|
352 |
*/ |
|
353 |
public Rectangle2D getBoundingBox(String[] layerNames, String srs) { |
|
354 |
return connector.getLayersExtent(layerNames, srs); |
|
355 |
} |
|
356 |
|
|
357 |
/* |
|
358 |
* (non-Javadoc) |
|
359 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#isQueryable() |
|
360 |
*/ |
|
361 |
public boolean isQueryable() { |
|
362 |
return connector.isQueryable(); |
|
363 |
} |
|
364 |
|
|
365 |
/** |
|
366 |
* Gets the title |
|
367 |
* @return |
|
368 |
*/ |
|
369 |
public String getTitle() { |
|
370 |
return null; |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
374 |
* @return The title of the service offered by the WMS server. |
|
375 |
*/ |
|
376 |
public String getServiceTitle() { |
|
377 |
return connector.getServiceTitle(); |
|
378 |
} |
|
379 |
|
|
380 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() { |
|
381 |
// TODO Auto-generated method stub |
|
382 |
return null; |
|
383 |
} |
|
384 |
|
|
385 |
} |
|
0 | 386 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/downloader/TileDownloaderForWMS.java | ||
---|---|---|
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.wms.io.downloader; |
|
23 |
|
|
24 |
import java.awt.geom.Rectangle2D; |
|
25 |
import java.io.File; |
|
26 |
import java.io.IOException; |
|
27 |
|
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
32 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
33 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
36 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
|
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
38 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
39 |
import org.gvsig.raster.cache.tile.Tile; |
|
40 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
|
41 |
import org.gvsig.raster.impl.DefaultRasterManager; |
|
42 |
import org.gvsig.raster.impl.buffer.DefaultRasterQuery; |
|
43 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
|
44 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
45 |
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader; |
|
46 |
import org.gvsig.raster.util.DefaultProviderServices; |
|
47 |
import org.gvsig.raster.wms.io.WMSConnector; |
|
48 |
import org.gvsig.raster.wms.io.WMSDataParameters; |
|
49 |
import org.gvsig.raster.wms.io.WMSProvider; |
|
50 |
import org.gvsig.remoteclient.utils.Utilities; |
|
51 |
import org.gvsig.remoteclient.wms.WMSStatus; |
|
52 |
import org.gvsig.tools.locator.LocatorException; |
|
53 |
|
|
54 |
/** |
|
55 |
* Tile getter |
|
56 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
57 |
*/ |
|
58 |
public class TileDownloaderForWMS extends BaseTileDownloader { |
|
59 |
private WMSConnector connector = null; |
|
60 |
private Extent lyrExtent = null; |
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
public TileDownloaderForWMS(WMSProvider prov, |
|
65 |
int tilePxWidth, |
|
66 |
int tilePxHeight, |
|
67 |
WMSConnector connector) { |
|
68 |
super(prov, tilePxWidth, tilePxHeight); |
|
69 |
this.connector = connector; |
|
70 |
lyrExtent = prov.getExtent(); |
|
71 |
} |
|
72 |
|
|
73 |
/* |
|
74 |
* (non-Javadoc) |
|
75 |
* @see org.gvsig.raster.cache.tile.provider.Downloader#getTile(org.gvsig.raster.cache.tile.Tile) |
|
76 |
*/ |
|
77 |
public synchronized Tile downloadTile(Tile tile) throws TileGettingException { |
|
78 |
try { |
|
79 |
Rectangle2D r = new Rectangle2D.Double(tile.getExtent().getMinX(), |
|
80 |
tile.getExtent().getMinY() - tile.getExtent().getHeight(), |
|
81 |
tile.getExtent().getWidth(), |
|
82 |
tile.getExtent().getHeight()); |
|
83 |
//Extent tileExtent = RasterLocator.getManager().getDataStructFactory().createExtent(r); |
|
84 |
WMSDataParameters p = ((WMSProvider)prov).getParameters(); |
|
85 |
WMSStatus wmsStatus = new WMSStatus(); |
|
86 |
wmsStatus.setLayerNames(Utilities.createVector(p.getLayerQuery(), ",")); |
|
87 |
wmsStatus.setSrs(p.getSRSCode()); |
|
88 |
wmsStatus.setFormat(p.getFormat()); |
|
89 |
wmsStatus.setStyles(p.getStyles()); |
|
90 |
wmsStatus.setDimensions(p.getDimensions()); |
|
91 |
wmsStatus.setTransparency(p.isWmsTransparent()); |
|
92 |
wmsStatus.setOnlineResource((String) p.getOnlineResource().get("GetMap")); |
|
93 |
wmsStatus.setExtent(r); |
|
94 |
wmsStatus.setHeight(tile.getHeightPx()); |
|
95 |
wmsStatus.setWidth(tile.getWidthPx()); |
|
96 |
IProjection proj = (IProjection)p.getSRS(); |
|
97 |
if(proj != null) |
|
98 |
wmsStatus.setProjected(proj.isProjected()); |
|
99 |
connector.getMap(wmsStatus, tile.getCancelled(), tile.getFile()); |
|
100 |
|
|
101 |
//Si borramos el rmf no se puede leer la etiqueta Alpha. En caso de que se modifique jgdal para |
|
102 |
//poder guardar esta etiqueta deberiamos borrar el rmf para ahorrar ficheros |
|
103 |
//File rmf = new File(tile.getFile().getAbsolutePath() + ".rmf"); |
|
104 |
//if(rmf.exists()) |
|
105 |
//rmf.delete(); |
|
106 |
} catch (RemoteServiceException e) { |
|
107 |
throw new TileGettingException(e); |
|
108 |
} |
|
109 |
readTileFromDisk(tile); |
|
110 |
return tile; |
|
111 |
} |
|
112 |
|
|
113 |
@SuppressWarnings("unused") |
|
114 |
private void fuseFiles(Extent dstExtent, int dstWidth, int dstHeight, File src, File dst, double pixelSize) |
|
115 |
throws RasterDriverException, ProcessInterruptedException, ProviderNotRegisteredException, InitializeException, LocatorException, NotSupportedExtensionException, IOException { |
|
116 |
RasterProvider provider = DefaultProviderServices.loadProvider(src); |
|
117 |
Buffer bufSrc = DefaultRasterManager.getInstance().createMemoryBuffer( |
|
118 |
provider.getDataType()[0], (int)provider.getWidth(), (int)provider.getHeight(), provider.getBandCount(), true); |
|
119 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
120 |
q.setAreaOfInterest(0, 0, (int)provider.getWidth(), (int)provider.getHeight()); |
|
121 |
BandList newBandList = new BandListImpl(provider.getURIOfFirstProvider(), provider.getBandCount(), provider.getDataType()[0]); |
|
122 |
q.setBandList(newBandList); |
|
123 |
q.setBuffer(bufSrc); |
|
124 |
q.setAdjustToExtent(true); |
|
125 |
Buffer bufInput = (Buffer)provider.getDataSet(q); |
|
126 |
|
|
127 |
Buffer bufDst = DefaultRasterManager.getInstance().createMemoryBuffer(provider.getDataType()[0], dstWidth, dstHeight, provider.getBandCount(), true); |
|
128 |
String extension = RasterLocator.getManager().getFileUtils().getExtensionFromFileName(src.getAbsolutePath()); |
|
129 |
RasterLocator.getManager().getRasterUtils().copyToBuffer( |
|
130 |
bufDst, |
|
131 |
dstExtent, |
|
132 |
bufInput, |
|
133 |
lyrExtent, |
|
134 |
pixelSize, |
|
135 |
provider.getColorInterpretation().hasAlphaBand()); |
|
136 |
RasterLocator.getManager().getProviderServices().exportBufferToFile( |
|
137 |
bufDst, |
|
138 |
provider.getCellSize(), |
|
139 |
extension, |
|
140 |
provider.getColorInterpretation().hasAlphaBand(), |
|
141 |
dst, |
|
142 |
dstExtent, |
|
143 |
provider.getColorInterpretation()); |
|
144 |
} |
|
145 |
|
|
146 |
} |
|
0 | 147 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/downloader/WMSTileServer.java | ||
---|---|---|
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.wms.io.downloader; |
|
23 |
|
|
24 |
import org.cresques.cts.IProjection; |
|
25 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
26 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
27 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
|
28 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
|
29 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
|
30 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
|
31 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
|
32 |
import org.gvsig.raster.cache.tile.provider.Downloader; |
|
33 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
34 |
import org.gvsig.raster.wms.io.WMSProvider; |
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
38 |
/** |
|
39 |
* Data server for the tile cache in a WMSProvider |
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
41 |
*/ |
|
42 |
public class WMSTileServer implements TileServer { |
|
43 |
private static Logger logger = LoggerFactory.getLogger(WMSTileServer.class); |
|
44 |
private CacheStruct struct = null; |
|
45 |
private Downloader downloader = null; |
|
46 |
private WMSProvider provider = null; |
|
47 |
private String suffix = ".tif"; |
|
48 |
|
|
49 |
public WMSTileServer(WMSProvider prov) { |
|
50 |
this.provider = prov; |
|
51 |
this.suffix = prov.getFileSuffix(); |
|
52 |
} |
|
53 |
|
|
54 |
/* |
|
55 |
* (non-Javadoc) |
|
56 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#getDownloader() |
|
57 |
*/ |
|
58 |
public Downloader getDownloader() { |
|
59 |
if(downloader == null || |
|
60 |
((TileDownloaderForWMS)downloader).getTileSize()[0] != TileCacheLibrary.ALTERNATIVE_TILESIZE || |
|
61 |
((TileDownloaderForWMS)downloader).getTileSize()[1] != TileCacheLibrary.ALTERNATIVE_TILESIZE) { |
|
62 |
try { |
|
63 |
downloader = new TileDownloaderForWMS( |
|
64 |
provider, |
|
65 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
|
66 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
|
67 |
provider.getConnector()); |
|
68 |
} catch (RemoteServiceException e) { |
|
69 |
return null; |
|
70 |
} |
|
71 |
} |
|
72 |
return downloader; |
|
73 |
} |
|
74 |
|
|
75 |
public CacheStruct getStruct() { |
|
76 |
if(struct == null) { |
|
77 |
TileCacheManager manager = TileCacheLocator.getManager(); |
|
78 |
|
|
79 |
int coordinates = CacheStruct.FLAT; |
|
80 |
if(provider.getProjection() != null) |
|
81 |
coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC; |
|
82 |
else { |
|
83 |
Extent e = provider.getExtent(); |
|
84 |
if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && |
|
85 |
e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) { |
|
86 |
coordinates = CacheStruct.GEOGRAFIC; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
String epsg = null; |
|
91 |
IProjection proj = provider.getProjection(); |
|
92 |
if(proj != null) |
|
93 |
epsg = proj.getAbrev(); |
|
94 |
|
|
95 |
struct = manager.createCacheStructure(coordinates, |
|
96 |
TileCacheLibrary.DEFAULT_LEVELS, |
|
97 |
provider.getExtent().toRectangle2D(), |
|
98 |
Double.POSITIVE_INFINITY,//provider.getCellSize(), |
|
99 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
|
100 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
|
101 |
provider.getURIOfFirstProvider(), |
|
102 |
provider.getParameters().getLayerQuery(), |
|
103 |
TileCacheLibrary.DEFAULT_STRUCTURE, |
|
104 |
RasterLibrary.pathTileCache, |
|
105 |
getFileSuffix(), |
|
106 |
epsg, |
|
107 |
0); |
|
108 |
} |
|
109 |
return struct; |
|
110 |
} |
|
111 |
|
|
112 |
/* |
|
113 |
* (non-Javadoc) |
|
114 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setStruct(org.gvsig.raster.cache.tile.provider.CacheStruct) |
|
115 |
*/ |
|
116 |
public void setStruct(CacheStruct struct) { |
|
117 |
if(struct != null) { |
|
118 |
this.struct = struct; |
|
119 |
if(struct.getTileSizeByLevel(0) != null) { |
|
120 |
try { |
|
121 |
downloader = new TileDownloaderForWMS(provider, |
|
122 |
struct.getTileSizeByLevel(0)[0], |
|
123 |
struct.getTileSizeByLevel(0)[1], |
|
124 |
provider.getConnector()); |
|
125 |
} catch (RemoteServiceException ex) { |
|
126 |
logger.error("Constructing TileDownloaderForWCS: " + ex.getMessage()); |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
/* |
|
133 |
* (non-Javadoc) |
|
134 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#getFileSuffix() |
|
135 |
*/ |
|
136 |
public String getFileSuffix() { |
|
137 |
return suffix; |
|
138 |
} |
|
139 |
|
|
140 |
/* |
|
141 |
* (non-Javadoc) |
|
142 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setFileExtension(java.lang.String) |
|
143 |
*/ |
|
144 |
public void setFileSuffix(String extension) { |
|
145 |
this.suffix = extension; |
|
146 |
} |
|
147 |
} |
|
0 | 148 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/package.html | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
4 |
<head> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
6 |
<title>org.gvsig.raster.wms.io package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>WMS provider</p> |
|
11 |
|
|
12 |
</body> |
|
13 |
</html> |
|
0 | 14 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/time/RemoteTimeDimension.java | ||
---|---|---|
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.wms.io.time; |
|
23 |
|
|
24 |
import org.gvsig.tools.persistence.Persistent; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author jaume |
|
30 |
* |
|
31 |
*/ |
|
32 |
public interface RemoteTimeDimension extends Persistent { |
|
33 |
public static int SINGLE_VALUE = 0; |
|
34 |
public static int MULTIPLE_VALUE = 1; |
|
35 |
public static int INTERVAL = 2; |
|
36 |
/** |
|
37 |
* Return the dimension's name. This value is the value that will be used in |
|
38 |
* a GetMap request. |
|
39 |
* |
|
40 |
* @return String containing the name of this dimension. |
|
41 |
*/ |
|
42 |
public String getName(); |
|
43 |
/** |
|
44 |
* Return the unit used by this dimension. |
|
45 |
* @return |
|
46 |
*/ |
|
47 |
public String getUnit(); |
|
48 |
/** |
|
49 |
* Returns the unit symbol (i.e. 'm', 's', or 'l' for meters, seconds, or liters respectively) |
|
50 |
* @return |
|
51 |
*/ |
|
52 |
public String getUnitSymbol(); |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* This method returns the <b>lowest</b> value of this dimension if this dimension is |
|
57 |
* specified as an interval or as a set of values, or the value specified if it |
|
58 |
* was a single value. |
|
59 |
* @return String containing the coded value. |
|
60 |
*/ |
|
61 |
public String getLowLimit(); |
|
62 |
|
|
63 |
/** |
|
64 |
* This method returns the <b>highest</b> value of this dimension if this dimension is |
|
65 |
* specified as an interval or as a set of values, or the value specified if it |
|
66 |
* was a single value. |
|
67 |
* @return String containing the coded value. |
|
68 |
*/ |
|
69 |
public String getHighLimit(); |
|
70 |
|
|
71 |
/** |
|
72 |
* This method returns the resolution supported by this dimension. This |
|
73 |
* means the step lenght between two consecutive points along the |
|
74 |
* dimension's axis. |
|
75 |
* @return String containing the coded value, or null if no value for resolution. |
|
76 |
* @deprecated |
|
77 |
*/ |
|
78 |
public String getResolution(); |
|
79 |
|
|
80 |
/** |
|
81 |
* Checks if the value represented as string is a valid value by checking |
|
82 |
* if the dimensions supports it. It should be true if one of the following is |
|
83 |
* true: |
|
84 |
* <p> |
|
85 |
* <ol> |
|
86 |
* <li> |
|
87 |
* The dimension <b>supports nearest values</b> and <b>the value is greather |
|
88 |
* or equal than the low limit</b> and <b>less or equal than the high limit</b>. |
|
89 |
* </li> |
|
90 |
* <li> |
|
91 |
* The value matches in one of the points defined by the low and high limits, and |
|
92 |
* the resolution value. |
|
93 |
* </li> |
|
94 |
* </ol> |
|
95 |
* </p> |
|
96 |
* @param value |
|
97 |
* @return |
|
98 |
*/ |
|
99 |
public boolean isValidValue(String value); |
|
100 |
|
|
101 |
/** |
|
102 |
* Return the value of the String passed in the dimension's unit-natural type. |
|
103 |
* @param value |
|
104 |
* @return |
|
105 |
*/ |
|
106 |
public Object valueOf(String value) throws IllegalArgumentException; |
|
107 |
|
|
108 |
/** |
|
109 |
* Returns the value that would be at the position passed as argument. |
|
110 |
* @param pos |
|
111 |
* @return |
|
112 |
* @throws ArrayIndexOutOfBoundsException |
|
113 |
*/ |
|
114 |
public String valueAt(int pos) throws ArrayIndexOutOfBoundsException; |
|
115 |
|
|
116 |
/** |
|
117 |
* The amount of positions that this dimension contains. |
|
118 |
* @return -1 if the dimension is not recognized, the amount otherwise |
|
119 |
*/ |
|
120 |
public int valueCount(); |
|
121 |
|
|
122 |
/** |
|
123 |
* Returns the expression describing this WMS Dimension |
|
124 |
*/ |
|
125 |
public String getExpression(); |
|
126 |
|
|
127 |
/** |
|
128 |
* Sets the expression describing this WMS Dimension |
|
129 |
* @throws IllegalArgumentException |
|
130 |
*/ |
|
131 |
public void setExpression(String expr); |
|
132 |
|
|
133 |
/** |
|
134 |
* Returns the type of the dimension expression.<br> |
|
135 |
* Possible values are: |
|
136 |
* <ol> |
|
137 |
* <li> |
|
138 |
* <b>IFMapWMSDimension.SINGLE_VALUE</b> |
|
139 |
* <b>IFMapWMSDimension.MULTIPLE_VALUE</b> |
|
140 |
* <b>IFMapWMSDimension.INTERVAL</b> |
|
141 |
* </li> |
|
142 |
* </ol> |
|
143 |
* @return int |
|
144 |
*/ |
|
145 |
public int getType(); |
|
146 |
|
|
147 |
/** |
|
148 |
* Analyzes and establishes the starting values for this dimension. No operation of this |
|
149 |
* dimension can be called before the dimension has been compiled. |
|
150 |
* |
|
151 |
* @throws IllegalArgumentException |
|
152 |
*/ |
|
153 |
public void compile() throws IllegalArgumentException; |
|
154 |
} |
|
0 | 155 |
org.gvsig.raster.wms/tags/tagdate_28082013/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/time/TimeDimension.java | ||
---|---|---|
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.wms.io.time; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.Calendar; |
|
26 |
import java.util.GregorianCalendar; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.tools.ToolsLocator; |
|
30 |
import org.gvsig.tools.dynobject.DynStruct; |
|
31 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
32 |
import org.gvsig.tools.persistence.PersistentState; |
|
33 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
34 |
|
|
35 |
/** |
|
36 |
* Class for WMS TIME dimension from a WMS. It allows you to handle the correct |
|
37 |
* values for this kind of dimension. |
|
38 |
* <br> |
|
39 |
* <p> |
|
40 |
* At the moment this class was written the WMS TIME dimension is defined as the |
|
41 |
* ISO8601 standard for expressing times. |
|
42 |
* </p> |
|
43 |
* <br> |
|
44 |
* <p> |
Also available in: Unified diff