gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / raster / process / OverviewsProcess.java @ 4181
History | View | Annotate | Download (4.27 KB)
1 | 2480 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | 4181 | fdiaz | *
|
6 | 2480 | nbrodin | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | 4181 | fdiaz | *
|
11 | 2480 | nbrodin | * This program is distributed in the hope that it will be useful,
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | 4181 | fdiaz | *
|
16 | 2480 | nbrodin | * You should have received a copy of the GNU General Public License
|
17 | * along with this program; if not, write to the Free Software
|
||
18 | 4181 | fdiaz | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 2480 | nbrodin | * MA 02110-1301, USA.
|
20 | 4181 | fdiaz | *
|
21 | 2480 | nbrodin | */
|
22 | package org.gvsig.raster.tools.app.basic.raster.process; |
||
23 | |||
24 | 4181 | fdiaz | import java.net.URI; |
25 | |||
26 | 2480 | nbrodin | import org.gvsig.andami.PluginServices; |
27 | import org.gvsig.fmap.dal.coverage.RasterLocator; |
||
28 | import org.gvsig.fmap.dal.coverage.exception.OverviewException; |
||
29 | import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
||
30 | import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder; |
||
31 | import org.gvsig.raster.fmap.layers.FLyrRaster; |
||
32 | import org.gvsig.raster.mainplugin.config.Configuration; |
||
33 | |||
34 | |||
35 | /**
|
||
36 | * Proceso para la generaci?n de overviews.
|
||
37 | *
|
||
38 | * 10/12/2007
|
||
39 | * @author Nacho Brodin nachobrodin@gmail.com
|
||
40 | */
|
||
41 | public class OverviewsProcess extends RasterProcess implements BaseIncrementableTask { |
||
42 | private FLyrRaster rasterSE = null; |
||
43 | private int value = 0; |
||
44 | private int resamplingAlg = OverviewBuilder.AVERAGE; |
||
45 | private int[] overviews = new int[] { 2, 4, 8, 16 }; |
||
46 | private String builder = "GDAL"; |
||
47 | 4181 | fdiaz | |
48 | 2480 | nbrodin | /*
|
49 | * (non-Javadoc)
|
||
50 | * @see org.gvsig.rastertools.RasterProcess#init()
|
||
51 | */
|
||
52 | public void init() { |
||
53 | rasterSE = getLayerParam("layer");
|
||
54 | builder = getStringParam("builder") != null ? getStringParam("builder") : builder; |
||
55 | |||
56 | int overviewsRate = 2; |
||
57 | int nOverviews = 4; |
||
58 | overviewsRate = Configuration.getValue("overviews_rate", new Integer(overviewsRate)).intValue(); |
||
59 | nOverviews = Configuration.getValue("overviews_number", new Integer(nOverviews)).intValue(); |
||
60 | resamplingAlg = Configuration.getValue("overviews_resampling_algorithm", new Integer(resamplingAlg)).intValue(); |
||
61 | |||
62 | // Leemos de la configuraci?n los valores de algoritmo a usar,
|
||
63 | // n?mero de overviews a generar y proporci?n de la primera overview
|
||
64 | |||
65 | overviews = new int[nOverviews]; |
||
66 | overviews[0] = overviewsRate;
|
||
67 | for (int i = 1; i < nOverviews; i++) |
||
68 | overviews[i] = overviewsRate * overviews[i - 1];
|
||
69 | } |
||
70 | |||
71 | /**
|
||
72 | * M?todo donde se ejecutar? el Thread, aqu? se generaran las
|
||
73 | * overviews
|
||
74 | 4181 | fdiaz | * @throws ProcessException
|
75 | 2480 | nbrodin | */
|
76 | public void process() throws ProcessException { |
||
77 | insertLineLog(PluginServices.getText(this, "overviews_generating")); |
||
78 | OverviewBuilder overviewBuilder = RasterLocator.getManager().getOverviewBuilder(builder); |
||
79 | 4181 | fdiaz | |
80 | 2480 | nbrodin | overviewBuilder.setIncrementListener(this);
|
81 | try {
|
||
82 | 4181 | fdiaz | URI[] uri = rasterSE.getDataStore().getURIByProvider(); |
83 | 2480 | nbrodin | |
84 | for (int i = 0; i < uri.length; i++) { |
||
85 | insertLineLog(" Dataset: " + i);
|
||
86 | 4181 | fdiaz | overviewBuilder.buildOverviews(resamplingAlg, uri[i].getPath(), overviews); |
87 | 2480 | nbrodin | } |
88 | |||
89 | if (externalActions != null) |
||
90 | externalActions.end(rasterSE); |
||
91 | } catch (OverviewException e) {
|
||
92 | if (incrementableTask != null) |
||
93 | incrementableTask.hideWindow(); |
||
94 | throw new ProcessException("error_write_overviews", e); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /*
|
||
99 | * (non-Javadoc)
|
||
100 | * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
|
||
101 | */
|
||
102 | public int getPercent() { |
||
103 | return value;
|
||
104 | } |
||
105 | |||
106 | /*
|
||
107 | * (non-Javadoc)
|
||
108 | * @see org.gvsig.addo.IOverviewIncrement#setPercent(int)
|
||
109 | */
|
||
110 | public void setPercent(int value) { |
||
111 | this.value = value;
|
||
112 | } |
||
113 | |||
114 | /*
|
||
115 | * (non-Javadoc)
|
||
116 | * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
|
||
117 | */
|
||
118 | public String getTitle() { |
||
119 | return PluginServices.getText(this, "incremento_overview"); |
||
120 | } |
||
121 | 4181 | fdiaz | |
122 | 2480 | nbrodin | /*
|
123 | * (non-Javadoc)
|
||
124 | * @see java.lang.Object#finalize()
|
||
125 | */
|
||
126 | protected void finalize() throws Throwable { |
||
127 | rasterSE = null;
|
||
128 | overviews = null;
|
||
129 | super.finalize();
|
||
130 | } |
||
131 | } |