gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.app / org.gvsig.raster.app.mainplugin / src / main / java / org / gvsig / raster / app / mainplugin / AddTestRasterLayerExtension.java @ 8691
History | View | Annotate | Download (47.4 KB)
1 | 6510 | fdiaz | package org.gvsig.raster.app.mainplugin; |
---|---|---|---|
2 | 6344 | fdiaz | |
3 | import java.io.File; |
||
4 | 6527 | fdiaz | import java.net.MalformedURLException; |
5 | import java.net.URL; |
||
6 | 6552 | fdiaz | import java.util.ArrayList; |
7 | 8596 | fdiaz | import java.util.Iterator; |
8 | 6527 | fdiaz | import java.util.List; |
9 | 6344 | fdiaz | |
10 | import org.slf4j.Logger; |
||
11 | import org.slf4j.LoggerFactory; |
||
12 | |||
13 | import org.gvsig.andami.IconThemeHelper; |
||
14 | 6511 | fdiaz | import org.gvsig.andami.Launcher; |
15 | 6344 | fdiaz | import org.gvsig.andami.plugins.Extension; |
16 | import org.gvsig.app.ApplicationLocator; |
||
17 | import org.gvsig.app.ApplicationManager; |
||
18 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
19 | import org.gvsig.app.project.documents.view.gui.IView; |
||
20 | import org.gvsig.fmap.crs.CRSFactory; |
||
21 | 6527 | fdiaz | import org.gvsig.fmap.dal.DALLocator; |
22 | import org.gvsig.fmap.dal.DataManager; |
||
23 | import org.gvsig.fmap.dal.DataParameters; |
||
24 | 6344 | fdiaz | import org.gvsig.fmap.dal.DataServerExplorer; |
25 | import org.gvsig.fmap.dal.DataServerExplorerParameters; |
||
26 | import org.gvsig.fmap.dal.DataStore; |
||
27 | import org.gvsig.fmap.dal.DataStoreProviderFactory; |
||
28 | import org.gvsig.fmap.dal.exception.DataException; |
||
29 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
30 | import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
||
31 | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
||
32 | 6511 | fdiaz | import org.gvsig.fmap.dal.raster.RasterStoreProviderFactory; |
33 | 6527 | fdiaz | import org.gvsig.fmap.dal.raster.api.NewRasterStoreParameters; |
34 | 6344 | fdiaz | import org.gvsig.fmap.dal.raster.api.RasterStore; |
35 | 6527 | fdiaz | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
36 | 6344 | fdiaz | import org.gvsig.fmap.dal.spi.DALSPILocator; |
37 | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
||
38 | 6547 | fdiaz | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
39 | 6344 | fdiaz | import org.gvsig.fmap.mapcontext.MapContext; |
40 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
41 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
42 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
43 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
44 | import org.gvsig.raster.lib.buffer.api.Buffer; |
||
45 | import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
||
46 | 6508 | fdiaz | import org.gvsig.tools.dispose.DisposeUtils; |
47 | 6344 | fdiaz | import org.gvsig.tools.dynobject.DynObject; |
48 | 6527 | fdiaz | import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
49 | 6547 | fdiaz | import org.gvsig.tools.locator.LocatorException; |
50 | 6344 | fdiaz | |
51 | /**
|
||
52 | * Class for test purpose only. It serves to load a test layer in the active View.
|
||
53 | * @author fdiaz
|
||
54 | *
|
||
55 | */
|
||
56 | public class AddTestRasterLayerExtension extends Extension { |
||
57 | |||
58 | private static final Logger logger = LoggerFactory.getLogger(AddTestRasterLayerExtension.class); |
||
59 | |||
60 | @Override
|
||
61 | public void initialize() { |
||
62 | IconThemeHelper.registerIcon("action", "view-test-layer-add", this); |
||
63 | } |
||
64 | |||
65 | @Override
|
||
66 | public void execute(String actionCommand) { |
||
67 | ApplicationManager application = ApplicationLocator.getManager(); |
||
68 | |||
69 | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
||
70 | if (view == null) { |
||
71 | return;
|
||
72 | } |
||
73 | ViewDocument document = view.getViewDocument(); |
||
74 | |||
75 | MapControl mapControl = view.getMapControl(); |
||
76 | 6547 | fdiaz | MapContext mapContext = mapControl.getMapContext(); |
77 | 6344 | fdiaz | |
78 | final MapContextManager mapContextManager = MapContextLocator.getMapContextManager();
|
||
79 | FLayer layer = null;
|
||
80 | 6508 | fdiaz | DataStore dataStore = null;
|
81 | try {
|
||
82 | 6557 | fdiaz | ////////// FILE
|
83 | /*
|
||
84 | dataStore = openFileCached(new
|
||
85 | File("/home/paco/data/cartography/raster/ecw/valencia_1980_tif.tif"));
|
||
86 | 6547 | fdiaz | // dataStore = openFileCached(new
|
87 | // File("/home/paco/data/Testdata/raster/JPG/relieve_andalucia.png"));
|
||
88 | 6557 | fdiaz | String layerName = dataStore.getName();
|
89 | layer = mapContextManager.createLayer(layerName, dataStore);
|
||
90 | 6552 | fdiaz | |
91 | 6557 | fdiaz | mapContext.getLayers().add(layer);
|
92 | */
|
||
93 | 6552 | fdiaz | ///////////// GoogleMaps
|
94 | 8685 | fdiaz | /*
|
95 | 6557 | fdiaz | dataStore = openGoogleMaps("roadmap");
|
96 | // dataStore = openGoogleMaps("hybrid");
|
||
97 | String layerName = dataStore.getName();
|
||
98 | layer = mapContextManager.createLayer(layerName, dataStore);
|
||
99 | 6552 | fdiaz | |
100 | 6557 | fdiaz | mapContext.getLayers().add(layer);
|
101 | 8685 | fdiaz | */
|
102 | 6674 | fdiaz | ///////////// WMS
|
103 | |||
104 | 8691 | fdiaz | /*
|
105 | 6552 | fdiaz | dataStore = openWMSCatastro();
|
106 | String layerName = dataStore.getName();
|
||
107 | layer = mapContextManager.createLayer(layerName, dataStore);
|
||
108 | mapContext.getLayers().add(layer);
|
||
109 | 8691 | fdiaz | */
|
110 | 6552 | fdiaz | ///////////// OSM
|
111 | |||
112 | /*
|
||
113 | Stamen_Watercolor=Stamen Watercolor*http\://tile.stamen.com/watercolor*17*jpg
|
||
114 | Open_Cycle_Map=Open Cycle Map*http\://tile.opencyclemap.org/cycle/*16*png
|
||
115 | Stamen_Terrain=Stamen Terrain*http\://tile.stamen.com/terrain*17*jpg
|
||
116 | Stamen_Toner=Stamen Toner*http\://tile.stamen.com/toner*17*png
|
||
117 | Mapnik=Mapnik*http\://tile.openstreetmap.org/*18*png
|
||
118 | */
|
||
119 | |||
120 | 8596 | fdiaz | /*
|
121 | 6552 | fdiaz | List<MyOSMServer> servers = new ArrayList<MyOSMServer>();
|
122 | try {
|
||
123 | servers.add(new MyOSMServer("Stamen Watercolor",new URL("http://tile.stamen.com/watercolor"),17,"jpg"));// fixed
|
||
124 | servers.add(new MyOSMServer("Open Cycle Map",new URL("http://tile.opencyclemap.org/cycle"),22,"png"));
|
||
125 | servers.add(new MyOSMServer("Stamen Terrain",new URL("http://tile.stamen.com/terrain"),17,"png"));// fixed
|
||
126 | servers.add(new MyOSMServer("Stamen Toner",new URL("http://tile.stamen.com/toner"),20,"png"));// fixed
|
||
127 | servers.add(new MyOSMServer("Mapnik",new URL("http://tile.openstreetmap.org"),19,"png"));// fixed
|
||
128 | } catch (MalformedURLException e){
|
||
129 | logger.warn("Can't create URL.", e);
|
||
130 | }
|
||
131 | |||
132 | for (Iterator iterator = servers.iterator(); iterator.hasNext();) {
|
||
133 | MyOSMServer MyOSMServer = (MyOSMServer) iterator.next();
|
||
134 | dataStore = openOSM(MyOSMServer);
|
||
135 | if (dataStore == null) {
|
||
136 | 6547 | fdiaz | continue;
|
137 | }
|
||
138 | String layerName = dataStore.getName();
|
||
139 | layer = mapContextManager.createLayer(layerName, dataStore);
|
||
140 | 6344 | fdiaz | |
141 | 6547 | fdiaz | mapContext.getLayers().add(layer);
|
142 | }
|
||
143 | 6552 | fdiaz | |
144 | 6557 | fdiaz | */
|
145 | |||
146 | |||
147 | 6552 | fdiaz | ///////////// WMTS
|
148 | |||
149 | /*
|
||
150 | dataStore = openWMTSPnoa();
|
||
151 | String layerName = dataStore.getName();
|
||
152 | layer = mapContextManager.createLayer(layerName, dataStore);
|
||
153 | mapContext.getLayers().add(layer);
|
||
154 | */
|
||
155 | |||
156 | |||
157 | ///////////// WCS
|
||
158 | |||
159 | 6652 | fdiaz | // for (int i = 0; i < 4; i++) {
|
160 | // logger.info("Abriendo capa: " + i);
|
||
161 | // dataStore = openTestWCS(i);
|
||
162 | // if (dataStore == null) {
|
||
163 | // continue;
|
||
164 | // }
|
||
165 | // String layerName = dataStore.getName();
|
||
166 | // layer = mapContextManager.createLayer(layerName, dataStore);
|
||
167 | // mapContext.getLayers().add(layer);
|
||
168 | // }
|
||
169 | 6557 | fdiaz | |
170 | |||
171 | ////////////// MULTIFILE
|
||
172 | 6674 | fdiaz | /*
|
173 | 6557 | fdiaz | dataStore = openMultifile();
|
174 | String layerName = dataStore.getName();
|
||
175 | layer = mapContextManager.createLayer(layerName, dataStore);
|
||
176 | RasterLayer rasterLayer = (RasterLayer)layer;
|
||
177 | RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager();
|
||
178 | // ColorInterpretation colorInterpretation = rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB);
|
||
179 | ColorInterpretation colorInterpretation =
|
||
180 | rasterLegendManager.createColorInterpretation(new String[] {
|
||
181 | ColorInterpretation.RED_BAND,
|
||
182 | ColorInterpretation.GREEN_BAND,
|
||
183 | 6654 | fdiaz | ColorInterpretation.BLUE_BAND,
|
184 | ColorInterpretation.ALPHA_BAND });
|
||
185 | 6557 | fdiaz | // ColorInterpretation.UNDEFINED_BAND,
|
186 | // ColorInterpretation.UNDEFINED_BAND,
|
||
187 | // ColorInterpretation.UNDEFINED_BAND });
|
||
188 | // ColorInterpretation.ALPHA_BAND,
|
||
189 | |||
190 | RasterLegend legend = rasterLegendManager.createLegend(colorInterpretation);
|
||
191 | rasterLayer.setLegend(legend);
|
||
192 | mapContext.getLayers().add(rasterLayer);
|
||
193 | 6674 | fdiaz | */
|
194 | 6557 | fdiaz | |
195 | 6649 | fdiaz | |
196 | 6547 | fdiaz | mapContext.callLegendChanged(); |
197 | document.setModified(true);
|
||
198 | 6527 | fdiaz | } catch (Exception e) { |
199 | logger.warn("Cant load test layer", e);
|
||
200 | 6508 | fdiaz | } finally {
|
201 | 6527 | fdiaz | // if (dataStore!=null){
|
202 | // DisposeUtils.dispose(dataStore);
|
||
203 | // dataStore = null;
|
||
204 | // }
|
||
205 | 6508 | fdiaz | if (layer!=null){ |
206 | DisposeUtils.dispose(layer); |
||
207 | layer = null;
|
||
208 | } |
||
209 | } |
||
210 | 6344 | fdiaz | } |
211 | |||
212 | @Override
|
||
213 | public boolean isEnabled() { |
||
214 | return true; |
||
215 | } |
||
216 | |||
217 | @Override
|
||
218 | public boolean isVisible() { |
||
219 | ApplicationManager application = ApplicationLocator.getManager(); |
||
220 | |||
221 | return application.getActiveComponent(ViewDocument.class) != null; |
||
222 | } |
||
223 | |||
224 | /**
|
||
225 | * TO TEST ONLY
|
||
226 | *
|
||
227 | * @return
|
||
228 | */
|
||
229 | 6547 | fdiaz | private RasterStore openTestWCS(int index) { |
230 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
231 | DataServerExplorerParameters parameters; |
||
232 | RasterStore store = null;
|
||
233 | DataParameters providerParams = null;
|
||
234 | try {
|
||
235 | parameters = manager.createServerExplorerParameters("WCSRasterServerExplorer");
|
||
236 | // parameters.setDynValue("service", new URL("http://idechg.chguadalquivir.es/inspire/wcs"));
|
||
237 | |||
238 | 6557 | fdiaz | parameters.setDynValue("service", new URL("http://inspire.cop.gva.es/mapserver/wcs")); |
239 | 6547 | fdiaz | // parameters.setDynValue("service", new URL("http://geoservicios.cantabria.es/inspire/services/NDVI/MapServer/WCSServer?service=WCS"));
|
240 | 6557 | fdiaz | // parameters.setDynValue("service", new URL("http://www.juntadeandalucia.es/medioambiente/mapwms/REDIAM_WCS_modelos_meteorologicos_prealertas"));
|
241 | 6547 | fdiaz | // parameters.setDynValue("service", new URL("http://www.idecyl.jcyl.es/IGCyL/services/MedioFisico/MDT/MapServer/WCSServer?request=GetCapabilities&service=WCS"));
|
242 | DataServerExplorer serverExplorer = |
||
243 | (DataServerExplorer) manager.openServerExplorer("WCSRasterServerExplorer", parameters);
|
||
244 | |||
245 | @SuppressWarnings("unchecked") |
||
246 | List<DataParameters> list = serverExplorer.list();
|
||
247 | try{
|
||
248 | providerParams = list.get(index); |
||
249 | } catch (IndexOutOfBoundsException e){ |
||
250 | logger.info("**** index out of bounds *****", e);
|
||
251 | return null; |
||
252 | } |
||
253 | store = (RasterStore) manager.openStore("WCSRaster", providerParams);
|
||
254 | } catch (ValidateDataParametersException | DynFieldNotFoundException | DataException | MalformedURLException e) { |
||
255 | logger.info("**** error opening store *****", e);
|
||
256 | } |
||
257 | if (store != null) { |
||
258 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
259 | } else {
|
||
260 | logger.info("**** K.O ;_( *****");
|
||
261 | } |
||
262 | |||
263 | |||
264 | //Prueba para cacheado de tiles tanto en memoria como en disco
|
||
265 | |||
266 | RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory)manager.getStoreProviderFactory("TileCache");
|
||
267 | // Prueba para cacheado de tiles solo en memoria
|
||
268 | // RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory)manager.getStoreProviderFactory("MemoryTileCache");
|
||
269 | DynObject tileParameters = tileCacheProviderFactory.createParameters(); |
||
270 | |||
271 | // FIXME: Si la prueba es para cacheado solo en memoria es innecesaria la generaci?n de la carpeta, se puede comentarizar
|
||
272 | |||
273 | //FIXME: ?SOBRA?
|
||
274 | // if (tileParameters.getDynClass().getDynField("name") != null) {
|
||
275 | // tileParameters.setDynValue("name", store.getName());
|
||
276 | // }
|
||
277 | |||
278 | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache"); |
||
279 | |||
280 | if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
||
281 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
282 | } |
||
283 | // Prueba para que la cach? utilice una carpeta alternativa
|
||
284 | // if (tileParameters.getDynClass().getDynField("folder") != null) {
|
||
285 | // tileParameters.setDynValue("folder", new File("/home/paco/tmp/WMS_catastro_cache"));
|
||
286 | // }
|
||
287 | |||
288 | try {
|
||
289 | // Prueba para cacheado de tiles tanto en memoria como en disco
|
||
290 | store.useCache("TileCache", tileParameters);
|
||
291 | // Prueba para cacheado de tiles solo en memoria
|
||
292 | // store.useCache("MemoryTileCache", tileParameters);
|
||
293 | } catch (DataException e) {
|
||
294 | logger.warn("Can't cache the layer.", e);
|
||
295 | } |
||
296 | |||
297 | return store;
|
||
298 | |||
299 | } |
||
300 | |||
301 | |||
302 | /**
|
||
303 | * TO TEST ONLY
|
||
304 | *
|
||
305 | * @return
|
||
306 | */
|
||
307 | 6537 | fdiaz | private RasterStore openWMTSPnoa() {
|
308 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
309 | DataServerExplorerParameters parameters; |
||
310 | RasterStore store = null;
|
||
311 | DataParameters providerParams = null;
|
||
312 | try {
|
||
313 | parameters = manager.createServerExplorerParameters("WMTSRasterServerExplorer");
|
||
314 | |||
315 | 6539 | fdiaz | parameters.setDynValue("service", new URL("http://www.ign.es/wmts/pnoa-ma")); //PNOA |
316 | // parameters.setDynValue("service", new URL("http://v2.suite.opengeo.org/geoserver/gwc/service/wmts")); //opengeo
|
||
317 | 6537 | fdiaz | |
318 | DataServerExplorer serverExplorer = |
||
319 | (DataServerExplorer) manager.openServerExplorer("WMTSRasterServerExplorer", parameters);
|
||
320 | |||
321 | |||
322 | |||
323 | // List<String> formats = serverExplorer.getFormats();
|
||
324 | |||
325 | @SuppressWarnings("unchecked") |
||
326 | List<DataParameters> list = serverExplorer.list();
|
||
327 | 6539 | fdiaz | providerParams = list.get(0); //PNOA |
328 | // providerParams = list.get(1); //opengeo
|
||
329 | 6537 | fdiaz | // providerParams.setDynValue("transparency", false);
|
330 | store = (RasterStore) manager.openStore("WMTSRaster", providerParams);
|
||
331 | // for (Iterator iterator = list.iterator(); iterator.hasNext();) {
|
||
332 | // try {
|
||
333 | // providerParams = (DataParameters) iterator.next();
|
||
334 | // providerParams.setDynValue("transparency", true);
|
||
335 | 8685 | fdiaz | // store = (RasterStore) manager.openStore("WMS", providerParams);
|
336 | 6537 | fdiaz | // break;
|
337 | // } catch (Exception e) {
|
||
338 | // continue;
|
||
339 | // }
|
||
340 | // }
|
||
341 | // if(store==null){
|
||
342 | // throw new IllegalArgumentException("Can't open any store from this server.'");
|
||
343 | // }
|
||
344 | } catch (ValidateDataParametersException | DynFieldNotFoundException | DataException | MalformedURLException e) { |
||
345 | logger.info("**** error opening store *****", e);
|
||
346 | } |
||
347 | if (store != null) { |
||
348 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
349 | } else {
|
||
350 | logger.info("**** K.O ;_( *****");
|
||
351 | } |
||
352 | |||
353 | //Prueba para cacheado de tiles tanto en memoria como en disco
|
||
354 | RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory)manager.getStoreProviderFactory("TileCache");
|
||
355 | // Prueba para cacheado de tiles solo en memoria
|
||
356 | // RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory)manager.getStoreProviderFactory("MemoryTileCache");
|
||
357 | DynObject tileParameters = tileCacheProviderFactory.createParameters(); |
||
358 | |||
359 | // FIXME: Si la prueba es para cacheado solo en memoria es innecesaria la generaci?n de la carpeta, se puede comentarizar
|
||
360 | |||
361 | //FIXME: ?SOBRA?
|
||
362 | // if (tileParameters.getDynClass().getDynField("name") != null) {
|
||
363 | // tileParameters.setDynValue("name", store.getName());
|
||
364 | // }
|
||
365 | |||
366 | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache"); |
||
367 | |||
368 | if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
||
369 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
370 | } |
||
371 | // Prueba para que la cach? utilice una carpeta alternativa
|
||
372 | // if (tileParameters.getDynClass().getDynField("folder") != null) {
|
||
373 | // tileParameters.setDynValue("folder", new File("/home/paco/tmp/WMS_catastro_cache"));
|
||
374 | // }
|
||
375 | |||
376 | try {
|
||
377 | // Prueba para cacheado de tiles tanto en memoria como en disco
|
||
378 | store.useCache("TileCache", tileParameters);
|
||
379 | // Prueba para cacheado de tiles solo en memoria
|
||
380 | // store.useCache("MemoryTileCache", tileParameters);
|
||
381 | } catch (DataException e) {
|
||
382 | logger.warn("Can't cache the layer.", e);
|
||
383 | } |
||
384 | |||
385 | return store;
|
||
386 | |||
387 | } |
||
388 | |||
389 | |||
390 | /**
|
||
391 | * TO TEST ONLY
|
||
392 | *
|
||
393 | * @return
|
||
394 | */
|
||
395 | 6527 | fdiaz | private RasterStore openWMSCatastro() {
|
396 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
397 | DataServerExplorerParameters parameters; |
||
398 | RasterStore store = null;
|
||
399 | DataParameters providerParams = null;
|
||
400 | try {
|
||
401 | 8685 | fdiaz | parameters = manager.createServerExplorerParameters("WMS");
|
402 | 6527 | fdiaz | parameters.setDynValue("service", new URL("http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx")); |
403 | 8685 | fdiaz | parameters.setDynValue("override_capabilities", false); |
404 | 6527 | fdiaz | |
405 | // parameters.setDynValue("service", new URL("http://terramapas.icv.gva.es/mapa_topografico_base"));
|
||
406 | // parameters.setDynValue("service", new URL("http://atlas.gc.ca/cgi-bin/atlaswms_en"));
|
||
407 | DataServerExplorer serverExplorer = |
||
408 | 8685 | fdiaz | (DataServerExplorer) manager.openServerExplorer("WMS", parameters);
|
409 | 6527 | fdiaz | |
410 | // List<String> formats = serverExplorer.getFormats();
|
||
411 | |||
412 | @SuppressWarnings("unchecked") |
||
413 | List<DataParameters> list = serverExplorer.list();
|
||
414 | providerParams = list.get(1);
|
||
415 | providerParams.setDynValue("transparency", false); |
||
416 | 8685 | fdiaz | providerParams.setDynValue("override_capabilities", false); |
417 | store = (RasterStore) manager.openStore("WMS", providerParams);
|
||
418 | 6527 | fdiaz | // for (Iterator iterator = list.iterator(); iterator.hasNext();) {
|
419 | // try {
|
||
420 | // providerParams = (DataParameters) iterator.next();
|
||
421 | // providerParams.setDynValue("transparency", true);
|
||
422 | 8685 | fdiaz | // store = (RasterStore) manager.openStore("WMS", providerParams);
|
423 | 6527 | fdiaz | // break;
|
424 | // } catch (Exception e) {
|
||
425 | // continue;
|
||
426 | // }
|
||
427 | // }
|
||
428 | // if(store==null){
|
||
429 | // throw new IllegalArgumentException("Can't open any store from this server.'");
|
||
430 | // }
|
||
431 | } catch (ValidateDataParametersException | DynFieldNotFoundException | DataException | MalformedURLException e) { |
||
432 | logger.info("**** error opening store *****", e);
|
||
433 | } |
||
434 | if (store != null) { |
||
435 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
436 | } else {
|
||
437 | logger.info("**** K.O ;_( *****");
|
||
438 | } |
||
439 | |||
440 | //Prueba para cacheado de tiles tanto en memoria como en disco
|
||
441 | |||
442 | RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory)manager.getStoreProviderFactory("TileCache");
|
||
443 | // Prueba para cacheado de tiles solo en memoria
|
||
444 | // RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory)manager.getStoreProviderFactory("MemoryTileCache");
|
||
445 | DynObject tileParameters = tileCacheProviderFactory.createParameters(); |
||
446 | |||
447 | // FIXME: Si la prueba es para cacheado solo en memoria es innecesaria la generaci?n de la carpeta, se puede comentarizar
|
||
448 | |||
449 | //FIXME: ?SOBRA?
|
||
450 | // if (tileParameters.getDynClass().getDynField("name") != null) {
|
||
451 | // tileParameters.setDynValue("name", store.getName());
|
||
452 | // }
|
||
453 | |||
454 | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache"); |
||
455 | |||
456 | if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
||
457 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
458 | } |
||
459 | // Prueba para que la cach? utilice una carpeta alternativa
|
||
460 | // if (tileParameters.getDynClass().getDynField("folder") != null) {
|
||
461 | // tileParameters.setDynValue("folder", new File("/home/paco/tmp/WMS_catastro_cache"));
|
||
462 | // }
|
||
463 | |||
464 | try {
|
||
465 | // Prueba para cacheado de tiles tanto en memoria como en disco
|
||
466 | store.useCache("TileCache", tileParameters);
|
||
467 | // Prueba para cacheado de tiles solo en memoria
|
||
468 | 8685 | fdiaz | // store.useCache("MemoryTileCache", tileParameters);
|
469 | 6527 | fdiaz | } catch (DataException e) {
|
470 | logger.warn("Can't cache the layer.", e);
|
||
471 | } |
||
472 | return store;
|
||
473 | |||
474 | } |
||
475 | |||
476 | |||
477 | /**
|
||
478 | * TO TEST ONLY
|
||
479 | *
|
||
480 | * @return
|
||
481 | */
|
||
482 | 6510 | fdiaz | private RasterStore openGoogleMaps(String mapType) { |
483 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
484 | DataStoreProviderFactory providerFactory = manager.getStoreProviderFactory("GoogleMapsRaster");
|
||
485 | DynObject params = providerFactory.createParameters(); |
||
486 | |||
487 | if (params.getDynClass().getDynField("mapType") != null) { |
||
488 | params.setDynValue("mapType", mapType);
|
||
489 | } |
||
490 | |||
491 | if (params.getDynClass().getDynField("hasApiKey") != null) { |
||
492 | params.setDynValue("hasApiKey", true); |
||
493 | } |
||
494 | |||
495 | 6674 | fdiaz | if (params.getDynClass().getDynField("crs") != null) { |
496 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:3857")); |
||
497 | } |
||
498 | |||
499 | 6510 | fdiaz | //FIXME:
|
500 | |||
501 | if (params.getDynClass().getDynField("apiKey") != null) { |
||
502 | params.setDynValue("apiKey", "AIzaSyANaBO8KAMiwLosno8ue84efcTNZeqWjIw"); |
||
503 | } |
||
504 | if (params.getDynClass().getDynField("language") != null) { |
||
505 | params.setDynValue("language", "es"); |
||
506 | } |
||
507 | |||
508 | // if (params.getDynClass().getDynField("region") != null) {
|
||
509 | // params.setDynValue("region", "");
|
||
510 | // }
|
||
511 | |||
512 | if (params.getDynClass().getDynField("format") != null) { |
||
513 | params.setDynValue("format", "png32"); |
||
514 | } |
||
515 | |||
516 | RasterStore store = null;
|
||
517 | try {
|
||
518 | store = (RasterStore) manager.openStore("GoogleMapsRaster", params);
|
||
519 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
520 | logger.info("**** error opening store *****", e);
|
||
521 | } |
||
522 | if (store != null) { |
||
523 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
524 | } else {
|
||
525 | logger.info("**** K.O ;_( *****");
|
||
526 | } |
||
527 | 6511 | fdiaz | |
528 | 6516 | fdiaz | //Prueba para cacheado de tiles tanto en memoria como en disco
|
529 | RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory) manager.getStoreProviderFactory("TileCache");
|
||
530 | // Prueba para cacheado de tiles solo en memoria
|
||
531 | // RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory) manager.getStoreProviderFactory("MemoryTileCache");
|
||
532 | 6511 | fdiaz | DynObject tileParameters = tileCacheProviderFactory.createParameters(); |
533 | |||
534 | 6516 | fdiaz | // FIXME: Si la prueba es para cacheado solo en memoria es innecesaria la generaci?n de la carpeta, se puede comentarizar
|
535 | |||
536 | 6511 | fdiaz | // FIXME: Ver qu? datos ser?an los adecuados para generar una carpeta
|
537 | // ?nica para la cach?
|
||
538 | |||
539 | 6527 | fdiaz | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache"); |
540 | 6511 | fdiaz | |
541 | 6527 | fdiaz | if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
542 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
543 | 6511 | fdiaz | } |
544 | |||
545 | |||
546 | try {
|
||
547 | 6516 | fdiaz | //Prueba para cacheado de tiles tanto en memoria como en disco
|
548 | 6511 | fdiaz | store.useCache("TileCache", tileParameters);
|
549 | 6516 | fdiaz | // Prueba para cacheado de tiles solo en memoria
|
550 | // store.useCache("MemoryTileCache", tileParameters);
|
||
551 | 6511 | fdiaz | } catch (DataException e) {
|
552 | logger.warn("Can't cache the layer.", e);
|
||
553 | } |
||
554 | |||
555 | 6510 | fdiaz | return store;
|
556 | |||
557 | } |
||
558 | |||
559 | /**
|
||
560 | * TO TEST ONLY
|
||
561 | *
|
||
562 | * @return
|
||
563 | */
|
||
564 | 6552 | fdiaz | private RasterStore openOSM(MyOSMServer myOSMServer) {
|
565 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
566 | DataStoreProviderFactory providerFactory = manager.getStoreProviderFactory("OSMRaster");
|
||
567 | DynObject params = providerFactory.createParameters(); |
||
568 | |||
569 | if (params.getDynClass().getDynField("name") != null) { |
||
570 | params.setDynValue("name", myOSMServer.name);
|
||
571 | } |
||
572 | |||
573 | if (params.getDynClass().getDynField("service") != null) { |
||
574 | params.setDynValue("service", myOSMServer.service);
|
||
575 | } |
||
576 | |||
577 | if (params.getDynClass().getDynField("maxLevel") != null) { |
||
578 | params.setDynValue("maxLevel", myOSMServer.maxLevel);
|
||
579 | } |
||
580 | |||
581 | if (params.getDynClass().getDynField("suffix") != null) { |
||
582 | params.setDynValue("suffix", myOSMServer.suffix);
|
||
583 | } |
||
584 | |||
585 | 8596 | fdiaz | if (params.getDynClass().getDynField("crs") != null) { |
586 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:3857")); |
||
587 | } |
||
588 | |||
589 | 6552 | fdiaz | RasterStore store = null;
|
590 | |||
591 | try {
|
||
592 | store = (RasterStore) manager.openStore("OSMRaster", params);
|
||
593 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
594 | logger.info("**** error opening store *****", e);
|
||
595 | } |
||
596 | if (store != null) { |
||
597 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
598 | } else {
|
||
599 | logger.info("**** K.O ;_( *****");
|
||
600 | } |
||
601 | |||
602 | //Prueba para cacheado de tiles tanto en memoria como en disco
|
||
603 | RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory) manager.getStoreProviderFactory("TileCache");
|
||
604 | // Prueba para cacheado de tiles solo en memoria
|
||
605 | // RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory) manager.getStoreProviderFactory("MemoryTileCache");
|
||
606 | DynObject tileParameters = tileCacheProviderFactory.createParameters(); |
||
607 | |||
608 | // FIXME: Si la prueba es para cacheado solo en memoria es innecesaria la generaci?n de la carpeta, se puede comentarizar
|
||
609 | |||
610 | // FIXME: Ver qu? datos ser?an los adecuados para generar una carpeta
|
||
611 | // ?nica para la cach?
|
||
612 | |||
613 | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache"); |
||
614 | |||
615 | if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
||
616 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
617 | } |
||
618 | |||
619 | |||
620 | try {
|
||
621 | //Prueba para cacheado de tiles tanto en memoria como en disco
|
||
622 | store.useCache("TileCache", tileParameters);
|
||
623 | // Prueba para cacheado de tiles solo en memoria
|
||
624 | // store.useCache("MemoryTileCache", tileParameters);
|
||
625 | } catch (DataException e) {
|
||
626 | logger.warn("Can't cache the layer.", e);
|
||
627 | } |
||
628 | |||
629 | return store;
|
||
630 | } |
||
631 | |||
632 | |||
633 | /**
|
||
634 | * TO TEST ONLY
|
||
635 | *
|
||
636 | * @return
|
||
637 | */
|
||
638 | 6344 | fdiaz | private RasterStore openWMS() {
|
639 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
640 | DataStoreProviderFactory providerFactory = manager.getStoreProviderFactory("WMS");
|
||
641 | DynObject params = providerFactory.createParameters(); |
||
642 | |||
643 | if (params.getDynClass().getDynField("crs") != null) { |
||
644 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:23030")); |
||
645 | } |
||
646 | |||
647 | RasterStore store = null;
|
||
648 | try {
|
||
649 | store = (RasterStore) manager.openStore("WMS", params);
|
||
650 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
651 | logger.info("**** error opening store *****", e);
|
||
652 | } |
||
653 | if (store != null) { |
||
654 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
655 | } else {
|
||
656 | logger.info("**** K.O ;_( *****");
|
||
657 | } |
||
658 | try {
|
||
659 | exportGTiff(store); |
||
660 | 6547 | fdiaz | } catch (ValidateDataParametersException | DataException | BufferException | LocatorException | CreateEnvelopeException e) {
|
661 | 6344 | fdiaz | logger.info("failed to copy");
|
662 | } |
||
663 | return store;
|
||
664 | |||
665 | } |
||
666 | |||
667 | /**
|
||
668 | * TO TEST ONLY
|
||
669 | *
|
||
670 | * @return
|
||
671 | */
|
||
672 | private RasterStore openWCS() {
|
||
673 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
674 | DataStoreProviderFactory providerFactory = manager.getStoreProviderFactory("WCS");
|
||
675 | DynObject params = providerFactory.createParameters(); |
||
676 | |||
677 | if (params.getDynClass().getDynField("url") != null) { |
||
678 | params.setDynValue("url", "http://inspire.cop.gva.es/mapserver/wcs?"); |
||
679 | } |
||
680 | if (params.getDynClass().getDynField("coverage") != null) { |
||
681 | params.setDynValue("coverage", "MDT"); |
||
682 | } |
||
683 | if (params.getDynClass().getDynField("crs") != null) { |
||
684 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:23030")); |
||
685 | } |
||
686 | |||
687 | RasterStore store = null;
|
||
688 | try {
|
||
689 | store = (RasterStore) manager.openStore("WCS", params);
|
||
690 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
691 | logger.info("**** error opening store *****", e);
|
||
692 | } |
||
693 | if (store != null) { |
||
694 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
695 | } else {
|
||
696 | logger.info("**** K.O ;_( *****");
|
||
697 | } |
||
698 | try {
|
||
699 | exportGTiff(store); |
||
700 | 6547 | fdiaz | } catch (ValidateDataParametersException | DataException | BufferException | LocatorException | CreateEnvelopeException e) {
|
701 | 6344 | fdiaz | logger.info("failed to copy");
|
702 | } |
||
703 | return store;
|
||
704 | |||
705 | } |
||
706 | |||
707 | /**
|
||
708 | * TO TEST ONLY
|
||
709 | *
|
||
710 | * @return
|
||
711 | */
|
||
712 | private RasterStore openPOSTGIS() {
|
||
713 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
714 | DataStoreProviderFactory providerFactory = manager.getStoreProviderFactory("PostGISRaster");
|
||
715 | DynObject params = providerFactory.createParameters(); |
||
716 | // PG:host='gvsig-training.com' port='5432'
|
||
717 | // dbname='andalucia' user='curso' password='curso' schema='public'
|
||
718 | // table='tr_relieve_andalucia2'
|
||
719 | if (params.getDynClass().getDynField("host") != null) { |
||
720 | params.setDynValue("host", "gvsig-training.com"); |
||
721 | } |
||
722 | if (params.getDynClass().getDynField("dbname") != null) { |
||
723 | params.setDynValue("dbname", "andalucia"); |
||
724 | } |
||
725 | if (params.getDynClass().getDynField("table") != null) { |
||
726 | params.setDynValue("table", "tr_relieve_andalucia2"); |
||
727 | } |
||
728 | if (params.getDynClass().getDynField("schema") != null) { |
||
729 | params.setDynValue("schema", "public"); |
||
730 | } |
||
731 | if (params.getDynClass().getDynField("user") != null) { |
||
732 | params.setDynValue("user", "curso"); |
||
733 | } |
||
734 | if (params.getDynClass().getDynField("password") != null) { |
||
735 | params.setDynValue("password", "curso"); |
||
736 | } |
||
737 | if (params.getDynClass().getDynField("port") != null) { |
||
738 | params.setDynValue("port", 5432); |
||
739 | } |
||
740 | if (params.getDynClass().getDynField("crs") != null) { |
||
741 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:23030")); |
||
742 | } |
||
743 | |||
744 | RasterStore store = null;
|
||
745 | try {
|
||
746 | store = (RasterStore) manager.openStore("PostGISRaster", params);
|
||
747 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
748 | logger.info("**** error opening store *****", e);
|
||
749 | } |
||
750 | if (store != null) { |
||
751 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
752 | } else {
|
||
753 | logger.info("**** K.O ;_( *****");
|
||
754 | } |
||
755 | try {
|
||
756 | exportPNG(store); |
||
757 | 6547 | fdiaz | } catch (ValidateDataParametersException | DataException | BufferException | LocatorException | CreateEnvelopeException e) {
|
758 | 6344 | fdiaz | logger.info("failed to copy");
|
759 | } |
||
760 | return store;
|
||
761 | |||
762 | } |
||
763 | |||
764 | /**
|
||
765 | * TO TEST ONLY
|
||
766 | *
|
||
767 | * @return
|
||
768 | */
|
||
769 | private RasterStore openTileCache() {
|
||
770 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
771 | DataStoreProviderFactory providerFactory = manager.getStoreProviderFactory("TileCache");
|
||
772 | DynObject params = providerFactory.createParameters(); |
||
773 | |||
774 | if (params.getDynClass().getDynField("name") != null) { |
||
775 | params.setDynValue("name", "TilecacheTEST"); |
||
776 | } |
||
777 | if (params.getDynClass().getDynField("crs") != null) { |
||
778 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:25830")); |
||
779 | } |
||
780 | |||
781 | RasterStore store = null;
|
||
782 | try {
|
||
783 | store = (RasterStore) manager.openStore("TileCache", params);
|
||
784 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
785 | logger.info("**** error opening store *****", e);
|
||
786 | } |
||
787 | if (store != null) { |
||
788 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
789 | } else {
|
||
790 | logger.info("**** K.O ;_( *****");
|
||
791 | } |
||
792 | // try {
|
||
793 | // exportGTiff(store);
|
||
794 | // } catch (ValidateDataParametersException | DataException
|
||
795 | // | BufferException e) {
|
||
796 | // logger.info("failed to copy");
|
||
797 | // }
|
||
798 | return store;
|
||
799 | } |
||
800 | |||
801 | 6557 | fdiaz | |
802 | private RasterStore openMultifile() throws Exception { |
||
803 | |||
804 | // File redFile = new File("/home/paco/tmp/costa1_R.tif");
|
||
805 | // File greenFile = new File("/home/paco/tmp/costa1_G.tif");
|
||
806 | // File blueFile = new File("/home/paco/tmp/costa1_B.tif");
|
||
807 | |||
808 | |||
809 | // File redFile = new File("/home/paco/tmp/Costa1-rojo.tif");
|
||
810 | // File greenFile = new File("/home/paco/tmp/Costa1-verde.tif");
|
||
811 | // File blueFile = new File("/home/paco/tmp/Costa1-azul.tif");
|
||
812 | |||
813 | DataManager manager = DALLocator.getDataManager(); |
||
814 | |||
815 | |||
816 | //RED
|
||
817 | |||
818 | // File redFile = new File("/home/paco/Descargas/fruit-2021816_640-rojo.tiff");
|
||
819 | File redFile = new File("/home/paco/Documentos/RED.tiff"); |
||
820 | DataServerExplorerParameters redExplorerParams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
821 | FilesystemServerExplorer redExplorer = (FilesystemServerExplorer) manager.openServerExplorer(FilesystemServerExplorer.NAME, redExplorerParams); |
||
822 | String redType = redExplorer.getProviderName(redFile);
|
||
823 | |||
824 | DynObject redParams = manager.createStoreParameters(redType); |
||
825 | |||
826 | if (redParams.getDynClass().getDynField("file") != null) { |
||
827 | redParams.setDynValue("file", redFile);
|
||
828 | } |
||
829 | if (redParams.getDynClass().getDynField("crs") != null) { |
||
830 | redParams.setDynValue("crs", CRSFactory.getCRS("EPSG:25830")); |
||
831 | } |
||
832 | |||
833 | RasterStore redStore = null;
|
||
834 | |||
835 | |||
836 | //GREEN
|
||
837 | |||
838 | // File greenFile = new File("/home/paco/Descargas/fruit-2021816_640-verde.tiff");
|
||
839 | File greenFile = new File("/home/paco/Documentos/GREEN.tiff"); |
||
840 | |||
841 | DataServerExplorerParameters greenExplorerParams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
842 | FilesystemServerExplorer greenExplorer = (FilesystemServerExplorer) manager.openServerExplorer(FilesystemServerExplorer.NAME, greenExplorerParams); |
||
843 | String greenType = greenExplorer.getProviderName(greenFile);
|
||
844 | |||
845 | DynObject greenParams = manager.createStoreParameters(greenType); |
||
846 | |||
847 | if (greenParams.getDynClass().getDynField("file") != null) { |
||
848 | greenParams.setDynValue("file", greenFile);
|
||
849 | } |
||
850 | if (greenParams.getDynClass().getDynField("crs") != null) { |
||
851 | greenParams.setDynValue("crs", CRSFactory.getCRS("EPSG:25830")); |
||
852 | } |
||
853 | |||
854 | RasterStore greenStore = null;
|
||
855 | |||
856 | //BLUE
|
||
857 | |||
858 | // File blueFile = new File("/home/paco/Descargas/fruit-2021816_640-azul.tiff");
|
||
859 | File blueFile = new File("/home/paco/Documentos/BLUE.tiff"); |
||
860 | |||
861 | DataServerExplorerParameters blueExplorerParams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
862 | FilesystemServerExplorer blueExplorer = (FilesystemServerExplorer) manager.openServerExplorer(FilesystemServerExplorer.NAME, blueExplorerParams); |
||
863 | String blueType = blueExplorer.getProviderName(blueFile);
|
||
864 | |||
865 | DynObject blueParams = manager.createStoreParameters(blueType); |
||
866 | |||
867 | if (blueParams.getDynClass().getDynField("file") != null) { |
||
868 | blueParams.setDynValue("file", blueFile);
|
||
869 | } |
||
870 | if (blueParams.getDynClass().getDynField("crs") != null) { |
||
871 | blueParams.setDynValue("crs", CRSFactory.getCRS("EPSG:25830")); |
||
872 | } |
||
873 | |||
874 | RasterStore blueStore = null;
|
||
875 | |||
876 | 6654 | fdiaz | //ALPHA
|
877 | 6557 | fdiaz | |
878 | 6654 | fdiaz | File alphaFile = new File("/home/paco/Documentos/ALPHA.tiff"); |
879 | |||
880 | DataServerExplorerParameters alphaExplorerParams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
881 | FilesystemServerExplorer alphaExplorer = (FilesystemServerExplorer) manager.openServerExplorer(FilesystemServerExplorer.NAME, alphaExplorerParams); |
||
882 | String alphaType = alphaExplorer.getProviderName(alphaFile);
|
||
883 | |||
884 | DynObject alphaParams = manager.createStoreParameters(alphaType); |
||
885 | |||
886 | if (alphaParams.getDynClass().getDynField("file") != null) { |
||
887 | alphaParams.setDynValue("file", alphaFile);
|
||
888 | } |
||
889 | if (alphaParams.getDynClass().getDynField("crs") != null) { |
||
890 | alphaParams.setDynValue("crs", CRSFactory.getCRS("EPSG:25830")); |
||
891 | } |
||
892 | |||
893 | RasterStore alphaStore = null;
|
||
894 | |||
895 | |||
896 | 6557 | fdiaz | try {
|
897 | redStore = (RasterStore) manager.openStore(redType, redParams); |
||
898 | greenStore = (RasterStore) manager.openStore(greenType, greenParams); |
||
899 | blueStore = (RasterStore) manager.openStore(blueType, blueParams); |
||
900 | 6654 | fdiaz | alphaStore = (RasterStore) manager.openStore(alphaType, alphaParams); |
901 | 6557 | fdiaz | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
902 | logger.info("**** error opening store *****", e);
|
||
903 | } |
||
904 | List<Integer> bands = new ArrayList<Integer>(); |
||
905 | bands.add(0);
|
||
906 | // bands.add(1);
|
||
907 | |||
908 | redStore.addBands(greenStore, bands); |
||
909 | redStore.addBands(blueStore, bands); |
||
910 | 6654 | fdiaz | redStore.addBands(alphaStore, bands); |
911 | 6557 | fdiaz | if (redStore != null) { |
912 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
913 | } else {
|
||
914 | logger.info("**** K.O ;_( *****");
|
||
915 | } |
||
916 | |||
917 | 6662 | fdiaz | /*
|
918 | 6557 | fdiaz | //Prueba para cacheado de tiles tanto en memoria como en disco
|
919 | RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory) manager.getStoreProviderFactory("TileCache");
|
||
920 | // Prueba para cacheado de tiles solo en memoria
|
||
921 | // RasterStoreProviderFactory tileCacheProviderFactory = (RasterStoreProviderFactory) manager.getStoreProviderFactory("MemoryTileCache");
|
||
922 | DynObject tileParameters = tileCacheProviderFactory.createParameters();
|
||
923 | |||
924 | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache");
|
||
925 | |||
926 | if (tileParameters.getDynClass().getDynField("rootFolder") != null) {
|
||
927 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
928 | }
|
||
929 | |||
930 | |||
931 | try {
|
||
932 | //Prueba para cacheado de tiles tanto en memoria como en disco
|
||
933 | redStore.useCache("TileCache", tileParameters);
|
||
934 | // greenStore.useCache("TileCache", tileParameters);
|
||
935 | blueStore.useCache("TileCache", tileParameters);
|
||
936 | // Prueba para cacheado de tiles solo en memoria
|
||
937 | // redStore.useCache("MemoryTileCache", tileParameters);
|
||
938 | } catch (DataException e) {
|
||
939 | logger.warn("Can't cache the layer.", e);
|
||
940 | }
|
||
941 | |||
942 | 6662 | fdiaz | */
|
943 | 6557 | fdiaz | return redStore;
|
944 | } |
||
945 | |||
946 | |||
947 | |||
948 | 6527 | fdiaz | private RasterStore openFileCached(File file) throws Exception { |
949 | DataManager manager = DALLocator.getDataManager(); |
||
950 | DataServerExplorerParameters explorerParams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
951 | FilesystemServerExplorer explorer = (FilesystemServerExplorer) manager.openServerExplorer(FilesystemServerExplorer.NAME, explorerParams); |
||
952 | String type = explorer.getProviderName(file);
|
||
953 | 6488 | fdiaz | |
954 | 6527 | fdiaz | |
955 | DynObject params = manager.createStoreParameters(type); |
||
956 | // DynObject params = manager.createStoreParameters("GTiff");
|
||
957 | // DynObject params = manager.createStoreParameters("PNG");
|
||
958 | |||
959 | if (params.getDynClass().getDynField("file") != null) { |
||
960 | params.setDynValue("file", file);
|
||
961 | 6488 | fdiaz | } |
962 | 6527 | fdiaz | if (params.getDynClass().getDynField("crs") != null) { |
963 | params.setDynValue("crs", CRSFactory.getCRS("EPSG:25830")); |
||
964 | } |
||
965 | |||
966 | RasterStore store = null;
|
||
967 | try {
|
||
968 | store = (RasterStore) manager.openStore(type, params); |
||
969 | // store = (RasterStore) manager.openStore("PNG", params);
|
||
970 | } catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
||
971 | logger.info("**** error opening store *****", e);
|
||
972 | } |
||
973 | if (store != null) { |
||
974 | logger.info("**** ??????? O.K !!!!!!! *****");
|
||
975 | } else {
|
||
976 | logger.info("**** K.O ;_( *****");
|
||
977 | } |
||
978 | |||
979 | DynObject tileParameters = manager.createStoreParameters("TileCache");
|
||
980 | |||
981 | File rootFolder = new File(Launcher.getAppHomeDir() + File.separator + "gvsig_rcache"); |
||
982 | |||
983 | if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
||
984 | tileParameters.setDynValue("rootFolder", rootFolder);
|
||
985 | } |
||
986 | |||
987 | try {
|
||
988 | store.useCache("TileCache", tileParameters);
|
||
989 | } catch (DataException e) {
|
||
990 | logger.warn("Can't cache the layer.", e);
|
||
991 | } |
||
992 | |||
993 | return store;
|
||
994 | 6488 | fdiaz | } |
995 | |||
996 | 6527 | fdiaz | // /**
|
997 | // * Converts an array of bytes to hexadecimal string
|
||
998 | // *
|
||
999 | // * @param data
|
||
1000 | // * @return
|
||
1001 | // */
|
||
1002 | // private String convertToHex(byte[] data) {
|
||
1003 | // StringBuffer buf = new StringBuffer();
|
||
1004 | // for (int i = 0; i < data.length; i++) {
|
||
1005 | // int halfbyte = (data[i] >>> 4) & 0x0F;
|
||
1006 | // int two_halfs = 0;
|
||
1007 | // do {
|
||
1008 | // if ((0 <= halfbyte) && (halfbyte <= 9))
|
||
1009 | // buf.append((char) ('0' + halfbyte));
|
||
1010 | // else
|
||
1011 | // buf.append((char) ('a' + (halfbyte - 10)));
|
||
1012 | // halfbyte = data[i] & 0x0F;
|
||
1013 | // } while (two_halfs++ < 1);
|
||
1014 | // }
|
||
1015 | // return buf.toString();
|
||
1016 | // }
|
||
1017 | //
|
||
1018 | 6488 | fdiaz | /**
|
1019 | 6344 | fdiaz | * TO TEST ONLY
|
1020 | 6547 | fdiaz | * @throws CreateEnvelopeException
|
1021 | * @throws LocatorException
|
||
1022 | 6344 | fdiaz | */
|
1023 | private void exportPNG(RasterStore store) throws InitializeException, ProviderNotRegisteredException, |
||
1024 | 6547 | fdiaz | ValidateDataParametersException, DataException, BufferException, LocatorException, CreateEnvelopeException { |
1025 | 6344 | fdiaz | String providerName = "PNG"; |
1026 | String extension = "png"; |
||
1027 | |||
1028 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
1029 | DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer");
|
||
1030 | int count = 0; |
||
1031 | String path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile." + extension; |
||
1032 | File destFile = new File(path); |
||
1033 | while (destFile.exists()) {
|
||
1034 | count++; |
||
1035 | path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile_" + count + "." + extension; |
||
1036 | destFile = new File(path); |
||
1037 | } |
||
1038 | eparams.setDynValue("initialpath", path);
|
||
1039 | DataServerExplorer serverExplorer = manager.createServerExplorer(eparams); |
||
1040 | |||
1041 | NewRasterStoreParameters params = (NewRasterStoreParameters) serverExplorer.getAddParameters(providerName); |
||
1042 | params.setDynValue("file", destFile);
|
||
1043 | |||
1044 | params.setDynValue("worldfile", false); |
||
1045 | params.setDynValue("zlevel", 1); |
||
1046 | |||
1047 | Buffer buffer = store.getRasterSet().clip(store.getEnvelope());
|
||
1048 | params.setBuffer(buffer); |
||
1049 | serverExplorer.add(providerName, params, true);
|
||
1050 | } |
||
1051 | |||
1052 | /**
|
||
1053 | * TO TEST ONLY
|
||
1054 | 6547 | fdiaz | * @throws CreateEnvelopeException
|
1055 | * @throws LocatorException
|
||
1056 | 6344 | fdiaz | */
|
1057 | private void exportGTiff(RasterStore store) throws InitializeException, ProviderNotRegisteredException, |
||
1058 | 6547 | fdiaz | ValidateDataParametersException, DataException, BufferException, LocatorException, CreateEnvelopeException { |
1059 | 6344 | fdiaz | String providerName = "GTiff"; |
1060 | String extension = "tif"; |
||
1061 | |||
1062 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
1063 | DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer");
|
||
1064 | int count = 0; |
||
1065 | String path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile." + extension; |
||
1066 | File destFile = new File(path); |
||
1067 | while (destFile.exists()) {
|
||
1068 | count++; |
||
1069 | path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile_" + count + "." + extension; |
||
1070 | destFile = new File(path); |
||
1071 | } |
||
1072 | eparams.setDynValue("initialpath", path);
|
||
1073 | DataServerExplorer serverExplorer = manager.createServerExplorer(eparams); |
||
1074 | |||
1075 | NewRasterStoreParameters params = (NewRasterStoreParameters) serverExplorer.getAddParameters(providerName); |
||
1076 | params.setDynValue("file", destFile);
|
||
1077 | |||
1078 | params.setDynValue("compress", "NONE"); |
||
1079 | params.setDynValue("tfw", false); |
||
1080 | params.setDynValue("photometric", "RGB"); |
||
1081 | |||
1082 | Buffer buffer = store.getRasterSet().clip(store.getEnvelope());
|
||
1083 | params.setBuffer(buffer); |
||
1084 | serverExplorer.add(providerName, params, true);
|
||
1085 | } |
||
1086 | |||
1087 | /**
|
||
1088 | * TO TEST ONLY
|
||
1089 | 6547 | fdiaz | * @throws CreateEnvelopeException
|
1090 | * @throws LocatorException
|
||
1091 | 6344 | fdiaz | */
|
1092 | private void exportBMP(RasterStore store) throws InitializeException, ProviderNotRegisteredException, |
||
1093 | 6547 | fdiaz | ValidateDataParametersException, DataException, BufferException, LocatorException, CreateEnvelopeException { |
1094 | 6344 | fdiaz | String providerName = "BMP"; |
1095 | String extension = "bmp"; |
||
1096 | |||
1097 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
1098 | DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer");
|
||
1099 | int count = 0; |
||
1100 | String path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile." + extension; |
||
1101 | File destFile = new File(path); |
||
1102 | while (destFile.exists()) {
|
||
1103 | count++; |
||
1104 | path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile_" + count + "." + extension; |
||
1105 | destFile = new File(path); |
||
1106 | } |
||
1107 | eparams.setDynValue("initialpath", path);
|
||
1108 | DataServerExplorer serverExplorer = manager.createServerExplorer(eparams); |
||
1109 | |||
1110 | NewRasterStoreParameters params = (NewRasterStoreParameters) serverExplorer.getAddParameters(providerName); |
||
1111 | params.setDynValue("file", destFile);
|
||
1112 | |||
1113 | params.setDynValue("worldfile", true); |
||
1114 | |||
1115 | Buffer buffer = store.getRasterSet().clip(store.getEnvelope());
|
||
1116 | params.setBuffer(buffer); |
||
1117 | serverExplorer.add(providerName, params, true);
|
||
1118 | } |
||
1119 | |||
1120 | /**
|
||
1121 | * TO TEST ONLY
|
||
1122 | 6547 | fdiaz | * @throws CreateEnvelopeException
|
1123 | * @throws LocatorException
|
||
1124 | 6344 | fdiaz | */
|
1125 | private void exportNetCDF(RasterStore store) throws InitializeException, ProviderNotRegisteredException, |
||
1126 | 6547 | fdiaz | ValidateDataParametersException, DataException, BufferException, LocatorException, CreateEnvelopeException { |
1127 | 6344 | fdiaz | String providerName = "netCDF"; |
1128 | String extension = "nc"; |
||
1129 | |||
1130 | DataManagerProviderServices manager = DALSPILocator.getDataManagerProviderServices(); |
||
1131 | DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer");
|
||
1132 | int count = 0; |
||
1133 | String path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile." + extension; |
||
1134 | File destFile = new File(path); |
||
1135 | while (destFile.exists()) {
|
||
1136 | count++; |
||
1137 | path = "/home/daniel/pruebas/datosPruebaRaster/copiedFile_" + count + "." + extension; |
||
1138 | destFile = new File(path); |
||
1139 | } |
||
1140 | eparams.setDynValue("initialpath", path);
|
||
1141 | DataServerExplorer serverExplorer = manager.createServerExplorer(eparams); |
||
1142 | |||
1143 | NewRasterStoreParameters params = (NewRasterStoreParameters) serverExplorer.getAddParameters(providerName); |
||
1144 | params.setDynValue("file", destFile);
|
||
1145 | // params.setDynValue("format", "NC4C");
|
||
1146 | // params.setDynValue("pixeltype", "DEFAULT");
|
||
1147 | params.setDynValue("chunking", false); |
||
1148 | |||
1149 | Buffer buffer = store.getRasterSet().clip(store.getEnvelope());
|
||
1150 | params.setBuffer(buffer); |
||
1151 | serverExplorer.add(providerName, params, true);
|
||
1152 | } |
||
1153 | |||
1154 | 6552 | fdiaz | private class MyOSMServer { |
1155 | public String name; |
||
1156 | public URL service; |
||
1157 | public int maxLevel; |
||
1158 | public String suffix; |
||
1159 | |||
1160 | public MyOSMServer(String name, URL service, int maxLevel, String suffix) { |
||
1161 | this.name = name;
|
||
1162 | this.service = service;
|
||
1163 | this.maxLevel = maxLevel;
|
||
1164 | this.suffix = suffix;
|
||
1165 | } |
||
1166 | } |
||
1167 | 6344 | fdiaz | } |