gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / data / DefaultElevationModel.java @ 474
History | View | Annotate | Download (4.55 KB)
1 |
package org.gvsig.view3d.swing.impl.data; |
---|---|
2 |
|
3 |
import gov.nasa.worldwind.avlist.AVKey; |
4 |
import gov.nasa.worldwind.avlist.AVList; |
5 |
import gov.nasa.worldwind.data.RasterServer; |
6 |
import gov.nasa.worldwind.retrieve.RetrievalPostProcessor; |
7 |
import gov.nasa.worldwind.retrieve.Retriever; |
8 |
import gov.nasa.worldwind.retrieve.RetrieverFactory; |
9 |
import gov.nasa.worldwind.terrain.BasicElevationModel; |
10 |
import gov.nasa.worldwind.util.WWUtil; |
11 |
|
12 |
import org.gvsig.fmap.mapcontext.MapContext; |
13 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
14 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
15 |
import org.slf4j.Logger; |
16 |
import org.slf4j.LoggerFactory; |
17 |
import org.w3c.dom.Element; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
22 |
*
|
23 |
*/
|
24 |
public class DefaultElevationModel extends BasicElevationModel { |
25 |
|
26 |
private static final Logger LOG = LoggerFactory |
27 |
.getLogger(DefaultElevationModel.class); |
28 |
|
29 |
/**
|
30 |
*
|
31 |
* @param params
|
32 |
*/
|
33 |
public DefaultElevationModel(AVList params) {
|
34 |
super(params);
|
35 |
|
36 |
this.createRasterServer(params);
|
37 |
} |
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @param domElement
|
42 |
* @param params
|
43 |
*/
|
44 |
public DefaultElevationModel(Element domElement, AVList params) { |
45 |
super(domElement, params);
|
46 |
|
47 |
this.createRasterServer(params != null ? params : (AVList) this |
48 |
.getValue(AVKey.CONSTRUCTION_PARAMETERS)); |
49 |
} |
50 |
|
51 |
private void createRasterServer(AVList params) { |
52 |
|
53 |
if (params == null) { |
54 |
LOG.error("Can not create raster server, parameters is null");
|
55 |
throw new IllegalArgumentException(); |
56 |
} |
57 |
|
58 |
if (this.getDataFileStore() == null) { |
59 |
LOG.error("Can not create raster server, file store is null");
|
60 |
throw new IllegalArgumentException(); |
61 |
} |
62 |
|
63 |
String datasetName = params.getStringValue(AVKey.DATASET_NAME);
|
64 |
if (WWUtil.isEmpty(datasetName)) {
|
65 |
LOG.error( |
66 |
"Can not create raster server, missing required parameter: {}",
|
67 |
AVKey.DATASET_NAME); |
68 |
throw new IllegalArgumentException(); |
69 |
} |
70 |
|
71 |
String dataCacheName = params.getStringValue(AVKey.DATA_CACHE_NAME);
|
72 |
if (WWUtil.isEmpty(dataCacheName)) {
|
73 |
LOG.error( |
74 |
"Can not create raster server, missing required parameter: {}",
|
75 |
AVKey.DATA_CACHE_NAME); |
76 |
throw new IllegalArgumentException(); |
77 |
} |
78 |
|
79 |
MapContext mapContext = |
80 |
(MapContext) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
81 |
|
82 |
if (mapContext == null) { |
83 |
LOG.error( |
84 |
"Can not create raster server, missing required parameter: {}",
|
85 |
DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
86 |
throw new IllegalArgumentException(); |
87 |
} |
88 |
|
89 |
FLayer layer = |
90 |
(FLayer) params.getValue(DefaultMapControl3D.GVSIG_LAYER); |
91 |
|
92 |
if (layer == null) { |
93 |
LOG.error( |
94 |
"Can not create raster server, missing required parameter: {}",
|
95 |
"GVSIG_LAYER");
|
96 |
throw new IllegalArgumentException(); |
97 |
} |
98 |
|
99 |
final AVList rasterServerParams = params.copy();
|
100 |
|
101 |
rasterServerParams.setValue(AVKey.FILE_STORE, this.getDataFileStore());
|
102 |
|
103 |
RetrieverFactory retrieverFactory = new RetrieverFactory() {
|
104 |
|
105 |
final protected RasterServer rasterServer = |
106 |
new DefaultRasterServer(rasterServerParams);
|
107 |
|
108 |
public Retriever createRetriever(AVList tileParams,
|
109 |
RetrievalPostProcessor postProcessor) { |
110 |
DefaultRasterServerRetriever retriever = |
111 |
new DefaultRasterServerRetriever(tileParams, rasterServer,
|
112 |
postProcessor); |
113 |
|
114 |
// copy only values that do not exist in destination AVList
|
115 |
// from rasterServerParams (source) to retriever (destination)
|
116 |
String[] keysToCopy = |
117 |
new String[] { AVKey.DATASET_NAME, AVKey.DISPLAY_NAME, |
118 |
AVKey.FILE_STORE, AVKey.BYTE_ORDER, AVKey.IMAGE_FORMAT, |
119 |
AVKey.DATA_TYPE, AVKey.FORMAT_SUFFIX, |
120 |
AVKey.MISSING_DATA_SIGNAL, |
121 |
AVKey.MISSING_DATA_REPLACEMENT, AVKey.ELEVATION_MIN, |
122 |
AVKey.ELEVATION_MAX, }; |
123 |
|
124 |
WWUtil.copyValues(rasterServerParams, retriever, keysToCopy, |
125 |
false);
|
126 |
|
127 |
return retriever;
|
128 |
} |
129 |
}; |
130 |
|
131 |
params.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
132 |
this.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory);
|
133 |
} |
134 |
} |