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