Revision 2821
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/buildNumber.properties | ||
---|---|---|
1 |
#Thu Jun 12 09:21:50 CEST 2014 |
|
2 |
buildNumber=53 |
|
0 | 3 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
org.gvsig.tools packages. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.raster"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="INFO" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
|
0 | 38 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
|
0 | 9 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/test/java/org/gvsig/raster/app/extension/TestNoDataPanel.java | ||
---|---|---|
1 |
package org.gvsig.raster.app.extension; |
|
2 |
|
|
3 |
import javax.swing.JFrame; |
|
4 |
|
|
5 |
import org.gvsig.raster.tools.app.basic.tool.properties.panel.NoDataPanel; |
|
6 |
|
|
7 |
public class TestNoDataPanel { |
|
8 |
private int w = 510; |
|
9 |
private int h = 300; |
|
10 |
private JFrame frame = new JFrame(); |
|
11 |
private NoDataPanel desc = null; |
|
12 |
|
|
13 |
public TestNoDataPanel() { |
|
14 |
desc = new NoDataPanel(); |
|
15 |
frame.getContentPane().add(desc); |
|
16 |
frame.setSize(w, h); |
|
17 |
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
|
18 |
frame.setVisible(true); |
|
19 |
} |
|
20 |
|
|
21 |
public static void main(String[] args) { |
|
22 |
new TestNoDataPanel(); |
|
23 |
} |
|
24 |
} |
|
0 | 25 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/test/java/org/gvsig/raster/app/extension/TestClipPanel.java | ||
---|---|---|
1 |
package org.gvsig.raster.app.extension; |
|
2 |
|
|
3 |
import javax.swing.JFrame; |
|
4 |
|
|
5 |
import org.gvsig.raster.tools.app.basic.tool.clip.ui.ClippingPanel; |
|
6 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
7 |
|
|
8 |
public class TestClipPanel { |
|
9 |
private int w = 510; |
|
10 |
private int h = 300; |
|
11 |
private JFrame frame = new JFrame(); |
|
12 |
private ClippingPanel desc = null; |
|
13 |
|
|
14 |
public TestClipPanel() { |
|
15 |
new DefaultLibrariesInitializer().fullInitialize(true); |
|
16 |
desc = new ClippingPanel(null); |
|
17 |
frame.getContentPane().add(desc); |
|
18 |
frame.setSize(w, h); |
|
19 |
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
|
20 |
frame.setVisible(true); |
|
21 |
} |
|
22 |
|
|
23 |
public static void main(String[] args) { |
|
24 |
new TestClipPanel(); |
|
25 |
} |
|
26 |
} |
|
0 | 27 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
|
|
26 |
<dependencySets> |
|
27 |
<dependencySet> |
|
28 |
<useProjectArtifact>false</useProjectArtifact> |
|
29 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
30 |
<outputDirectory>lib</outputDirectory> |
|
31 |
<includes> |
|
32 |
<include>org.gvsig:org.gvsig.raster.tools.app.basic:jar</include> |
|
33 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.layerdatatype:jar</include> |
|
34 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.saveraster:jar</include> |
|
35 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include> |
|
36 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include> |
|
37 |
<include>org.gvsig:org.gvsig.raster.tools.toolbox.algorithm:jar</include> |
|
38 |
</includes> |
|
39 |
</dependencySet> |
|
40 |
</dependencySets> |
|
41 |
</assembly> |
|
0 | 42 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/package.html | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
4 |
<head> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
6 |
<title>org.gvsig.raster package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>Raster gvSIG extension</p> |
|
11 |
|
|
12 |
<p> |
|
13 |
Shows Raster into gvSIG. |
|
14 |
</p> |
|
15 |
|
|
16 |
</body> |
|
17 |
</html> |
|
0 | 18 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/RasterToolsUtil.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.Point; |
|
27 |
import java.io.File; |
|
28 |
import java.util.ArrayList; |
|
29 |
|
|
30 |
import javax.swing.ImageIcon; |
|
31 |
import javax.swing.JOptionPane; |
|
32 |
|
|
33 |
import org.gvsig.andami.IconThemeHelper; |
|
34 |
import org.gvsig.andami.PluginServices; |
|
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
36 |
import org.gvsig.app.project.Project; |
|
37 |
import org.gvsig.app.project.ProjectManager; |
|
38 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
|
39 |
import org.gvsig.fmap.dal.DALLocator; |
|
40 |
import org.gvsig.fmap.dal.DataManager; |
|
41 |
import org.gvsig.fmap.dal.DataStore; |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
43 |
import org.gvsig.fmap.dal.coverage.datastruct.Param; |
|
44 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
45 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
46 |
import org.gvsig.fmap.dal.coverage.util.ProviderServices; |
|
47 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
48 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
49 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
50 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
51 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
52 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
53 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
54 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
55 |
import org.gvsig.gui.beans.propertiespanel.PropertiesComponent; |
|
56 |
import org.gvsig.gui.beans.propertiespanel.PropertyStruct; |
|
57 |
import org.gvsig.i18n.Messages; |
|
58 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
|
59 |
import org.gvsig.raster.util.RasterNotLoadException; |
|
60 |
|
|
61 |
/** |
|
62 |
* Herramientas de uso general y que son dependientes de gvSIG, FMap o de |
|
63 |
* libUIComponents. En caso de no serlo existe una clase independiente de |
|
64 |
* cualquier proyecto dentro de libRaster para este tipo de funciones. |
|
65 |
* |
|
66 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
67 |
*/ |
|
68 |
public class RasterToolsUtil { |
|
69 |
|
|
70 |
/** |
|
71 |
* Obtiene la lista de capas del TOC y devuelve las raster. Si hay capas agrupadas lo tiene en cuenta y mira |
|
72 |
* dentro de la agrupaci?n. |
|
73 |
* @param srcLyrs FLayers de la vista |
|
74 |
* @param destLyrs Lista de capas |
|
75 |
* @return ArrayList con la lista de capas raster agrupadas o no. El orden en que aparecen |
|
76 |
* en la lista es de abajo a arriba las que aparecen en el TOC. |
|
77 |
*/ |
|
78 |
public static ArrayList<FLayer> getRasterLayerList(FLayers srcLyrs, ArrayList<FLayer> destLyrs) { |
|
79 |
if(destLyrs == null) |
|
80 |
destLyrs = new ArrayList<FLayer>(); |
|
81 |
for (int i = 0; i < srcLyrs.getLayersCount(); i++) { |
|
82 |
if(srcLyrs.getLayer(i) instanceof DefaultFLyrRaster) |
|
83 |
destLyrs.add(srcLyrs.getLayer(i)); |
|
84 |
if(srcLyrs.getLayer(i) instanceof FLayers) |
|
85 |
destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs); |
|
86 |
} |
|
87 |
return destLyrs; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Obtiene la lista de capas del TOC y devuelve las raster. Si hay capas agrupadas lo tiene en cuenta y mira |
|
92 |
* dentro de la agrupaci?n. |
|
93 |
* @param srcLyrs FLayers de la vista |
|
94 |
* @param destLyrs Lista de capas |
|
95 |
* @return ArrayList con la lista de capas raster agrupadas o no. El orden en que aparecen |
|
96 |
* en la lista es de abajo a arriba las que aparecen en el TOC. |
|
97 |
*/ |
|
98 |
public static ArrayList<FLayer> getLayerList(FLayers srcLyrs, ArrayList<FLayer> destLyrs) { |
|
99 |
if(srcLyrs == null) |
|
100 |
return null; |
|
101 |
if(destLyrs == null) |
|
102 |
destLyrs = new ArrayList<FLayer>(); |
|
103 |
for (int i = 0; i < srcLyrs.getLayersCount(); i++) { |
|
104 |
if(srcLyrs.getLayer(i) instanceof FLayers) |
|
105 |
destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs); |
|
106 |
else |
|
107 |
destLyrs.add(srcLyrs.getLayer(i)); |
|
108 |
} |
|
109 |
return destLyrs; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Obtiene el nombre de la vista donde est? cargada la capa que se pasa por par?metro |
|
114 |
* @param layer Capa cargada en una vista |
|
115 |
* @return Nombre de la vista donde est? cargada la capa. |
|
116 |
*/ |
|
117 |
public static String getView(FLayer layer) { |
|
118 |
// Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject(); |
|
119 |
Project p = ProjectManager.getInstance().getCurrentProject(); |
|
120 |
return p.getViewName(layer); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Devuelve la traducci?n de un texto. En caso de no existir la traducci?n al idioma seleccionado |
|
125 |
* devolver? la cadena de entrada. |
|
126 |
* @param parent Ventana padre que contiene el objeto con la traducci?n |
|
127 |
* @param text Texto a traducir |
|
128 |
* @return Texto traducido o cadena de entrada en caso de no encontrar una traducci?n |
|
129 |
*/ |
|
130 |
public static String getText(Object parent, String text) { |
|
131 |
return PluginServices.getText(parent, text); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Obtiene un icono definido por la etiqueta que se especifica en el |
|
136 |
* par?metro |
|
137 |
* @param ico Etiqueta del icono |
|
138 |
* @return Icono |
|
139 |
*/ |
|
140 |
public static ImageIcon getIcon(String ico) { |
|
141 |
return IconThemeHelper.getImageIcon(ico); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* A?ade una ventana al gestor de ventanas |
|
146 |
* @param window |
|
147 |
*/ |
|
148 |
public static void addWindow(IWindow window) { |
|
149 |
PluginServices.getMDIManager().addWindow(window); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Elimina una ventana al gestor de ventanas |
|
154 |
* @param window |
|
155 |
*/ |
|
156 |
public static void closeWindow(IWindow window) { |
|
157 |
PluginServices.getMDIManager().closeWindow(window); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Selecciona los controles del panel de propiedades a partir de los par?mtros |
|
162 |
* obtenidos del driver. Este m?todo realiza una transformaci?n entre Params |
|
163 |
* obtenido del driver de escritura y los par?metros del panel de propiedades. |
|
164 |
* @param panel Panel de propiedades |
|
165 |
* @param params Par?metros del driver |
|
166 |
* @param notTakeIntoAccount Nombre de par?metros que no hay que tener en cuenta. Si es null se tienen en cuenta todos. |
|
167 |
*/ |
|
168 |
public static void loadPropertiesFromWriterParams(PropertiesComponent pComp, Params params, String[] notTakeIntoAccount) { |
|
169 |
for (int i = 0; i < params.getNumParams(); i++) { |
|
170 |
Param p = params.getParam(i); |
|
171 |
String name = getText(null, p.getId()); |
|
172 |
String key = p.getId(); |
|
173 |
|
|
174 |
//Miramos si el par?metro coincide con alguno en la lista de parametros que no hay que |
|
175 |
//tener en cuenta. Si es as? no lo a?adimos |
|
176 |
if(notTakeIntoAccount != null && notTakeIntoAccount.length > 0) { |
|
177 |
boolean jump = false; |
|
178 |
for (int j = 0; j < notTakeIntoAccount.length; j++) { |
|
179 |
if (key.equals(notTakeIntoAccount[j])) |
|
180 |
jump = true; |
|
181 |
} |
|
182 |
if(jump) |
|
183 |
continue; |
|
184 |
} |
|
185 |
|
|
186 |
Object[] types = null; |
|
187 |
int selectedValue = 0; |
|
188 |
|
|
189 |
switch (p.getType()) { |
|
190 |
case Params.CHECK: |
|
191 |
pComp.addValue(name, key, p.getDefaultValue(), types); |
|
192 |
break; |
|
193 |
case Params.CHOICE: |
|
194 |
ArrayList<String> list = new ArrayList<String>(); |
|
195 |
for (int j = 0; j < p.getList().length; j++) { |
|
196 |
list.add(p.getList()[j]); |
|
197 |
if (p.getDefaultValue() instanceof Integer) |
|
198 |
if (((Integer) p.getDefaultValue()).intValue() == j) |
|
199 |
selectedValue = j; |
|
200 |
} |
|
201 |
types = new Object[] { new Integer(PropertiesComponent.TYPE_COMBO), list }; |
|
202 |
pComp.addValue(name, key, new Integer(selectedValue), types); |
|
203 |
break; |
|
204 |
case Params.SLIDER: |
|
205 |
types = new Object[] { new Integer(PropertiesComponent.TYPE_SLIDER), new Integer(p.getList()[0]), new Integer(p.getList()[1]) }; |
|
206 |
pComp.addValue(name, key, p.getDefaultValue(), types); |
|
207 |
break; |
|
208 |
default: |
|
209 |
pComp.addValue(getText(null, ((Param)params.getParam(i)).getId()), params.getParam(i).getId(), params.getParam(i).getDefaultValue(), null); |
|
210 |
break; |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* Carga los par?metros del escritor WriterParams con los valores obtenidos |
|
217 |
* de la ventana de propiedades. |
|
218 |
*/ |
|
219 |
@SuppressWarnings("unchecked") |
|
220 |
public static void loadWriterParamsFromPropertiesPanel(PropertiesComponent pComp, Params params) { |
|
221 |
ArrayList<PropertyStruct> values = pComp.getValues(); |
|
222 |
for (int iParam = 0; iParam < params.getNumParams(); iParam++) { |
|
223 |
Param p = params.getParam(iParam); |
|
224 |
for (int iValue = 0; iValue < values.size(); iValue++) { |
|
225 |
PropertyStruct prop = values.get(iValue); |
|
226 |
if (p.getId().compareTo(prop.getKey()) == 0) { |
|
227 |
switch (p.getType()) { |
|
228 |
case Params.CHECK: |
|
229 |
p.setDefaultValue((Boolean) prop.getNewValue()); |
|
230 |
break; |
|
231 |
case Params.CHOICE: |
|
232 |
p.setDefaultValue(((Integer) prop.getNewValue()));//p.list[((Integer) prop.getNewValue()).intValue()]; |
|
233 |
break; |
|
234 |
case Params.SLIDER: |
|
235 |
try { |
|
236 |
p.setDefaultValue((Integer)prop.getNewValue()); |
|
237 |
} catch (NumberFormatException e) {} |
|
238 |
} |
|
239 |
break; |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Funci?n que devuelve true si se tiene permiso de escritura en la ruta |
|
247 |
* indicada en el par?metro path y false si no los tiene. |
|
248 |
* @param path Ruta a comprobar los permisosv |
|
249 |
* @param pluginObject si es distinto de null se obtiene un mensaje de |
|
250 |
* advertencia y sirve como par?metro para getText de la traducci?n. |
|
251 |
* Si es null no se mostrar? ventana de advertencia |
|
252 |
* @return true si se tiene permiso de escritura en la ruta indicada en el |
|
253 |
* par?metro path y false si no los tiene. |
|
254 |
*/ |
|
255 |
public static boolean canWrite(String path) { |
|
256 |
File f = new File(path); |
|
257 |
if(f.exists() && f.canWrite()) |
|
258 |
return true; |
|
259 |
else { |
|
260 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
|
261 |
Messages.getText("error_writing_raster_file")); |
|
262 |
return false; |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* Carga una capa raster en una vista de gvSIG. |
|
268 |
* @param viewName Nombre de la vista donde ha de cargarse. Si vale null se cargar? en la |
|
269 |
* primera vista que encuentre que est? activa. Si no hay ninguna saltar? una excepci?n. |
|
270 |
* @param fileName Nombre del fichero a cargar. No debe ser nulo nunca. |
|
271 |
* @param layerName Nombre de la capa. Si es null se asignar? el nombre del |
|
272 |
* fichero sin extensi?n. |
|
273 |
* @throws RasterNotLoadException Excepci?n que se lanza cuando no se ha podido cargar la capa |
|
274 |
* por alg?n motivo. |
|
275 |
*/ |
|
276 |
@SuppressWarnings("deprecation") |
|
277 |
public static FLayer loadLayer(String viewName, String fileName, String layerName) throws RasterNotLoadException { |
|
278 |
if(fileName == null) |
|
279 |
return null; |
|
280 |
|
|
281 |
//Seleccionamos la vista de gvSIG |
|
282 |
AbstractViewPanel theView = null; |
|
283 |
try { |
|
284 |
IWindow[] allViews = PluginServices.getMDIManager().getAllWindows(); |
|
285 |
if(viewName != null) { |
|
286 |
for (int i = 0; i < allViews.length; i++) { |
|
287 |
if (allViews[i] instanceof AbstractViewPanel |
|
288 |
&& (((AbstractViewPanel) allViews[i]).getDocument().getName().equals(viewName) || |
|
289 |
PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]).getTitle().equals(viewName))) |
|
290 |
theView = (AbstractViewPanel) allViews[i]; |
|
291 |
} |
|
292 |
} else { |
|
293 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
294 |
for (int i = 0; i < allViews.length; i++) { |
|
295 |
if (allViews[i] instanceof AbstractViewPanel && ((AbstractViewPanel)allViews[i]) == activeWindow) //En la primera vista activa |
|
296 |
theView = (AbstractViewPanel) allViews[i]; |
|
297 |
} |
|
298 |
if(theView == null) { |
|
299 |
for (int i = 0; i < allViews.length; i++) { |
|
300 |
if (allViews[i] instanceof AbstractViewPanel) //En la primera vista |
|
301 |
theView = (AbstractViewPanel) allViews[i]; |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
|
|
306 |
if (theView == null) |
|
307 |
throw new RasterNotLoadException("Imposible cargar la capa."); |
|
308 |
} catch (ClassCastException ex) { |
|
309 |
throw new RasterNotLoadException("No se puede hacer un casting de esa IWindow a View."); |
|
310 |
} |
|
311 |
|
|
312 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
|
313 |
|
|
314 |
DefaultFLyrRaster lyr = null; |
|
315 |
try { |
|
316 |
ProviderServices provServ = RasterLocator.getManager().getProviderServices(); |
|
317 |
RasterDataParameters storeParameters = provServ.createNotTiledParameters(fileName); |
|
318 |
storeParameters.setSRS(theView.getProjection()); |
|
319 |
|
|
320 |
MapContextManager mcm = MapContextLocator.getMapContextManager(); |
|
321 |
DataManager dataManager = DALLocator.getDataManager(); |
|
322 |
DataStore dataStore = null; |
|
323 |
try { |
|
324 |
dataStore = dataManager.createStore(storeParameters); |
|
325 |
} catch (ValidateDataParametersException e) { |
|
326 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
327 |
} catch (InitializeException e) { |
|
328 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
329 |
} catch (ProviderNotRegisteredException e) { |
|
330 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
331 |
} |
|
332 |
|
|
333 |
lyr = new DefaultFLyrRaster(); |
|
334 |
|
|
335 |
if(layerName == null) { |
|
336 |
int endIndex = fileName.lastIndexOf("."); |
|
337 |
if (endIndex < 0) |
|
338 |
endIndex = fileName.length(); |
|
339 |
|
|
340 |
layerName = fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex); |
|
341 |
} |
|
342 |
|
|
343 |
lyr = (DefaultFLyrRaster) mcm.createLayer(layerName, dataStore); |
|
344 |
|
|
345 |
} catch (LoadLayerException e) { |
|
346 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
347 |
} catch (InitializeException e) { |
|
348 |
throw new RasterNotLoadException("Error creating parameters."); |
|
349 |
} catch (ProviderNotRegisteredException e) { |
|
350 |
throw new RasterNotLoadException("Error creating parameters."); |
|
351 |
} |
|
352 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
|
353 |
theView.getMapControl().getMapContext().invalidate(); |
|
354 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
|
355 |
return lyr; |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* Carga una capa raster en una vista de gvSIG. |
|
360 |
* @param viewName Nombre de la vista donde ha de cargarse. Si vale null se cargar? en la |
|
361 |
* primera vista que encuentre que est? activa. Si no hay ninguna saltar? una excepci?n. |
|
362 |
* @param fileName Nombre del fichero a cargar. No debe ser nulo nunca. |
|
363 |
* @param layerName Nombre de la capa. Si es null se asignar? el nombre del |
|
364 |
* fichero sin extensi?n. |
|
365 |
* @throws RasterNotLoadException Excepci?n que se lanza cuando no se ha podido cargar la capa |
|
366 |
* por alg?n motivo. |
|
367 |
*/ |
|
368 |
public static FLayer loadLayer(String viewName, FLayer lyr) throws RasterNotLoadException { |
|
369 |
if(lyr == null) |
|
370 |
return null; |
|
371 |
|
|
372 |
//Seleccionamos la vista de gvSIG |
|
373 |
AbstractViewPanel theView = null; |
|
374 |
try { |
|
375 |
IWindow[] allViews = PluginServices.getMDIManager().getAllWindows(); |
|
376 |
if(viewName != null) { |
|
377 |
for (int i = 0; i < allViews.length; i++) { |
|
378 |
if (allViews[i] instanceof AbstractViewPanel |
|
379 |
&& PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]).getTitle().equals(viewName)) |
|
380 |
theView = (AbstractViewPanel) allViews[i]; |
|
381 |
} |
|
382 |
} else { |
|
383 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
384 |
for (int i = 0; i < allViews.length; i++) { |
|
385 |
if (allViews[i] instanceof AbstractViewPanel && ((AbstractViewPanel)allViews[i]) == activeWindow) //En la primera vista activa |
|
386 |
theView = (AbstractViewPanel) allViews[i]; |
|
387 |
} |
|
388 |
if(theView == null) { |
|
389 |
for (int i = 0; i < allViews.length; i++) { |
|
390 |
if (allViews[i] instanceof AbstractViewPanel) //En la primera vista |
|
391 |
theView = (AbstractViewPanel) allViews[i]; |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
|
|
396 |
if (theView == null) |
|
397 |
throw new RasterNotLoadException("Imposible cargar la capa."); |
|
398 |
} catch (ClassCastException ex) { |
|
399 |
throw new RasterNotLoadException("No se puede hacer un casting de esa IWindow a View."); |
|
400 |
} |
|
401 |
|
|
402 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
|
403 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
|
404 |
theView.getMapControl().getMapContext().invalidate(); |
|
405 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
|
406 |
return lyr; |
|
407 |
} |
|
408 |
|
|
409 |
/** |
|
410 |
* Calculo de las coordenadas de una ventana IWindow para que quede centrada sobre el |
|
411 |
* MainFrame. Estas coordenadas solo valen para un IWindow ya que andami mete las ventanas |
|
412 |
* con coordenadas relativas a su ventanta principal. |
|
413 |
* @param widthWindow Ancho de la ventana a a?adir |
|
414 |
* @param heightWindow Alto de la ventana a a?adir |
|
415 |
* @return Array con el ancho y el alto |
|
416 |
*/ |
|
417 |
public static Point iwindowPosition(int widthWindow, int heightWindow) { |
|
418 |
int posWindowX = 0; |
|
419 |
int posWindowY = 0; |
|
420 |
Dimension dim = null; |
|
421 |
Point pos = null; |
|
422 |
if(PluginServices.getMainFrame() instanceof Component) { |
|
423 |
dim = ((Component)PluginServices.getMainFrame()).getSize(); |
|
424 |
pos = ((Component)PluginServices.getMainFrame()).getLocation(); |
|
425 |
if(dim != null && pos != null) { |
|
426 |
posWindowX = ((dim.width >> 1) - (widthWindow >> 1)); |
|
427 |
posWindowY = ((dim.height >> 1) - (heightWindow >> 1) - 70); |
|
428 |
return new Point(posWindowX, posWindowY); |
|
429 |
} |
|
430 |
} |
|
431 |
return null; |
|
432 |
} |
|
433 |
} |
|
0 | 434 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ProcessException.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
/** |
|
24 |
* This exception is thrown when a problem inside a raster process |
|
25 |
* is detected. |
|
26 |
* |
|
27 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
28 |
*/ |
|
29 |
public class ProcessException extends Exception { |
|
30 |
private static final long serialVersionUID = 666908550965442025L; |
|
31 |
|
|
32 |
public ProcessException(String msg, Throwable e) { |
|
33 |
super(msg, e); |
|
34 |
} |
|
35 |
|
|
36 |
public ProcessException(String msg){ |
|
37 |
super(msg); |
|
38 |
} |
|
39 |
} |
|
0 | 40 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/RasterProcess.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import java.util.Hashtable; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
29 |
import org.gvsig.fmap.dal.coverage.process.CancelEvent; |
|
30 |
import org.gvsig.fmap.dal.coverage.process.TaskEventManager; |
|
31 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
|
32 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
|
33 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
34 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
35 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
36 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
37 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
38 |
import org.gvsig.tools.dispose.Disposable; |
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
/** |
|
42 |
* Clase base de todos los procesos raster. En ella se genstionan todas las |
|
43 |
* funciones comunes como incremento de la tarea, gesti?n de eventos a la tarea, |
|
44 |
* par?metros de la tarea, etc ... |
|
45 |
* |
|
46 |
* 18/12/2007 |
|
47 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
48 |
* @deprecated Use DataProcess in org.gvsig.raster.algorithm |
|
49 |
*/ |
|
50 |
public abstract class RasterProcess implements IIncrementable, IncrementableListener, Runnable, Disposable { |
|
51 |
protected IncrementableTask incrementableTask = null; |
|
52 |
protected volatile Thread blinker = null; |
|
53 |
protected TaskEventManager taskEventManager = null; |
|
54 |
protected IProcessActions externalActions = null; |
|
55 |
protected Hashtable<String, Object> |
|
56 |
taskParams = new Hashtable<String, Object>(); |
|
57 |
|
|
58 |
private String log = ""; |
|
59 |
private String lastLine = ""; |
|
60 |
private long time = 0; |
|
61 |
private boolean progressActive = true; |
|
62 |
private IProcessActions queueActions = null; |
|
63 |
private Logger logger = LoggerFactory.getLogger(RasterProcess.class.toString()); |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* Crea la ventana de IncrementableTask |
|
68 |
*/ |
|
69 |
public IncrementableTask getIncrementableTask() { |
|
70 |
if (incrementableTask == null) { |
|
71 |
incrementableTask = new IncrementableTask(this); |
|
72 |
incrementableTask.addIncrementableListener(this); |
|
73 |
} |
|
74 |
return incrementableTask; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Define si se puede cancelar el proceso. Por defecto es true. |
|
79 |
* @param enabled |
|
80 |
*/ |
|
81 |
public void setCancelable(boolean enabled) { |
|
82 |
getIncrementableTask().getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_CANCEL, enabled); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Muestra la ventana de IncrementableTask |
|
87 |
*/ |
|
88 |
public void showIncrementableWindow() { |
|
89 |
if (progressActive) { |
|
90 |
getIncrementableTask().showWindow(); |
|
91 |
getIncrementableTask().start(); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Arranca el proceso de recorte de un layer |
|
97 |
*/ |
|
98 |
public void start() { |
|
99 |
showIncrementableWindow(); |
|
100 |
if(blinker == null) |
|
101 |
blinker = new Thread(this); |
|
102 |
blinker.start(); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Proceso de carga de par?metros. Puede no hacerse una carga de par?metros |
|
107 |
* explicita y obtenerlos directamente de la tabla Hash cuando vayan a usarse. |
|
108 |
* Esto queda a elecci?n del programador. En caso de hacerse una carga de par?metros |
|
109 |
* explicita esta llamada deber?a hacerse justo despues del constructor de la clase |
|
110 |
* que contendr? el proceso. |
|
111 |
*/ |
|
112 |
public abstract void init(); |
|
113 |
|
|
114 |
/** |
|
115 |
* Proceso |
|
116 |
* @throws InterruptedException |
|
117 |
*/ |
|
118 |
public abstract void process() throws ProcessInterruptedException, ProcessException; |
|
119 |
|
|
120 |
/** |
|
121 |
* Obtenci?n de un objeto de resultado. Este objeto deber? ser el mismo que el que se |
|
122 |
* pasa por par?metro en el "end" de IProcessActions. Este m?todo es util cuando la tarea no se |
|
123 |
* lanza en un Thread (ejecutamos process directamente) y queremos recoger el resultado |
|
124 |
* sin registrarnos al evento de finalizaci?n de tarea. |
|
125 |
* @return objeto resultado de la tarea |
|
126 |
*/ |
|
127 |
public Object getResult() { |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Proceso |
|
133 |
* @throws ProcessException |
|
134 |
*/ |
|
135 |
public void execute() throws ProcessInterruptedException, ProcessException { |
|
136 |
init(); |
|
137 |
process(); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* M?todo donde se ejecutar? el Thread. Este har? las acciones globales para |
|
142 |
* cualquier tarea y llamar? al m?todo execute especifico de una tarea. |
|
143 |
*/ |
|
144 |
public void run() { |
|
145 |
long t1 = new java.util.Date().getTime(); |
|
146 |
|
|
147 |
try { |
|
148 |
taskEventManager = RasterLocator.getManager().createRasterTask(this); |
|
149 |
execute(); |
|
150 |
} catch (ProcessInterruptedException e) { |
|
151 |
if (externalActions != null) |
|
152 |
externalActions.interrupted(); |
|
153 |
Thread.currentThread().interrupt(); |
|
154 |
} catch (ProcessException e) { |
|
155 |
if (progressActive) { |
|
156 |
if (incrementableTask != null) { |
|
157 |
getIncrementableTask().processFinalize(); |
|
158 |
incrementableTask = null; |
|
159 |
} |
|
160 |
} |
|
161 |
logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e)); |
|
162 |
if(e.getMessage() != null && e.getMessage().compareTo("") != 0) |
|
163 |
RasterSwingLibrary.messageBoxError(e.getMessage(), this); |
|
164 |
else |
|
165 |
RasterSwingLibrary.messageBoxError("error_processing", this); |
|
166 |
queueActions = null; |
|
167 |
|
|
168 |
} catch (Exception e) { |
|
169 |
if (progressActive) { |
|
170 |
if (incrementableTask != null) { |
|
171 |
getIncrementableTask().processFinalize(); |
|
172 |
incrementableTask = null; |
|
173 |
} |
|
174 |
} |
|
175 |
logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e)); |
|
176 |
if(e.getMessage() != null && e.getMessage().compareTo("") != 0) |
|
177 |
RasterSwingLibrary.messageBoxError(e.getMessage(), this); |
|
178 |
else |
|
179 |
RasterSwingLibrary.messageBoxError("error_processing", this); |
|
180 |
queueActions = null; |
|
181 |
} finally { |
|
182 |
taskEventManager.removeTask(); |
|
183 |
if (progressActive) { |
|
184 |
if (incrementableTask != null) |
|
185 |
getIncrementableTask().processFinalize(); |
|
186 |
} |
|
187 |
if (queueActions != null) |
|
188 |
queueActions.end(this); |
|
189 |
time = new java.util.Date().getTime() - t1; |
|
190 |
blinker = null; |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Activa o desactiva el interfaz de progreso en el lanzamiento de la tarea como un thread. |
|
196 |
* @param active true para activarlo o false para desactivarlo |
|
197 |
*/ |
|
198 |
public void setProgressActive(boolean active){ |
|
199 |
this.progressActive = active; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Obtiene el tiempo que tard? en ejecutarse la tarea |
|
204 |
* la ?ltima vez que se proces? |
|
205 |
*/ |
|
206 |
public long getTime() { |
|
207 |
return time; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Obtiene el objeto para ejecutar acciones externar. |
|
212 |
* @param IProcessActions |
|
213 |
*/ |
|
214 |
public IProcessActions getActions() { |
|
215 |
return externalActions; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Asigna el objeto para ejecutar acciones externar. |
|
220 |
* @param IProcessActions |
|
221 |
*/ |
|
222 |
public void setActions(IProcessActions actions) { |
|
223 |
this.externalActions = actions; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* Obtiene el objeto para ejecutar acciones de la cola de procesos de ejecuci?n exclusiva. |
|
228 |
* @param IProcessActions |
|
229 |
*/ |
|
230 |
public IProcessActions getUniqueProcessActions() { |
|
231 |
return queueActions; |
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* Asigna el objeto para ejecutar acciones externar. |
|
236 |
* @param IProcessActions |
|
237 |
*/ |
|
238 |
public void setUniqueProcessActions(IProcessActions actions) { |
|
239 |
this.queueActions = actions; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Inserta una nueva l?nea en el log del cuadro de incremento de tarea |
|
244 |
* @param line |
|
245 |
*/ |
|
246 |
protected void insertLineLog(String line) { |
|
247 |
lastLine = line; |
|
248 |
log = log + line + "\n"; |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Obtiene la ?ltima l?nea introducida en el log del cuadro de incremento. |
|
253 |
*/ |
|
254 |
public String getLabel() { |
|
255 |
return lastLine; |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Obtiene el texto de log del cuadro de incremento completo. |
|
260 |
*/ |
|
261 |
public String getLog() { |
|
262 |
return log; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Un evento de cancelado es enviado a la tarea cuando actionCanceled es activado. Para |
|
267 |
* ello se crear? un objeto CancelEvent y se asignar? a la tarea en ejecuci?n. Esta lo |
|
268 |
* procesar? cuando pueda e interrumpir? el proceso. |
|
269 |
*/ |
|
270 |
public void actionCanceled(IncrementableEvent e) { |
|
271 |
taskEventManager.setEvent(new CancelEvent(this)); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* A?ade un par?metro a la tarea |
|
276 |
* @param name Clave del par?metro |
|
277 |
* @param param Objeto pasado como par?metro |
|
278 |
*/ |
|
279 |
public void addParam(String name, Object param) { |
|
280 |
if (param != null) |
|
281 |
taskParams.put(name, param); |
|
282 |
else |
|
283 |
taskParams.remove(name); |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* Elimina un par?metro de la tarea |
|
288 |
* @param name Clave del par?metro a eliminar |
|
289 |
*/ |
|
290 |
public void removeParam(String name) { |
|
291 |
taskParams.remove(name); |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* Obtiene un par?metro a partir de la clave |
|
296 |
* @param name Par?metro |
|
297 |
* @return Par?metro |
|
298 |
*/ |
|
299 |
public Object getParam(String name) { |
|
300 |
return taskParams.get(name); |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Obtiene un par?metro String a partir de la clave |
|
305 |
* @param name Par?metro |
|
306 |
* @return Par?metro |
|
307 |
*/ |
|
308 |
public String getStringParam(String name) { |
|
309 |
Object value = taskParams.get(name); |
|
310 |
return (value != null && value instanceof String) ? (String)value : null; |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Obtiene un par?metro byte a partir de la clave |
|
315 |
* @param name Par?metro |
|
316 |
* @return Par?metro |
|
317 |
*/ |
|
318 |
public byte getByteParam(String name) { |
|
319 |
Object value = taskParams.get(name); |
|
320 |
return (value != null && value instanceof Byte) ? ((Byte)value).byteValue() : 0; |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Obtiene un par?metro float a partir de la clave |
|
325 |
* @param name Par?metro |
|
326 |
* @return Par?metro |
|
327 |
*/ |
|
328 |
public float getFloatParam(String name) { |
|
329 |
Object value = taskParams.get(name); |
|
330 |
return (value != null && value instanceof Float) ? ((Float)value).floatValue() : 0F; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Obtiene un par?metro double a partir de la clave |
|
335 |
* @param name Par?metro |
|
336 |
* @return Par?metro |
|
337 |
*/ |
|
338 |
public double getDoubleParam(String name) { |
|
339 |
Object value = taskParams.get(name); |
|
340 |
return (value != null && value instanceof Double) ? ((Double)value).doubleValue() : 0D; |
|
341 |
} |
|
342 |
|
|
343 |
/** |
|
344 |
* Obtiene un par?metro entero a partir de la clave |
|
345 |
* @param name Par?metro |
|
346 |
* @return Par?metro |
|
347 |
*/ |
|
348 |
public int getIntParam(String name) { |
|
349 |
Object value = taskParams.get(name); |
|
350 |
return (value != null && value instanceof Integer) ? ((Integer)value).intValue() : 0; |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* Obtiene un par?metro boolean a partir de la clave |
|
355 |
* @param name Par?metro |
|
356 |
* @return Par?metro |
|
357 |
*/ |
|
358 |
public boolean getBooleanParam(String name) { |
|
359 |
Object value = taskParams.get(name); |
|
360 |
return (value != null && value instanceof Boolean) ? ((Boolean)value).booleanValue() : false; |
|
361 |
} |
|
362 |
|
|
363 |
/** |
|
364 |
* Obtiene un par?metro int[] a partir de la clave |
|
365 |
* @param name Par?metro |
|
366 |
* @return Par?metro |
|
367 |
*/ |
|
368 |
public int[] getIntArrayParam(String name) { |
|
369 |
Object value = taskParams.get(name); |
|
370 |
return (value != null && value instanceof int[]) ? ((int[])value) : null; |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
374 |
* Obtiene un par?metro double[] a partir de la clave |
|
375 |
* @param name Par?metro |
|
376 |
* @return Par?metro |
|
377 |
*/ |
|
378 |
public double[] getDoubleArrayParam(String name) { |
|
379 |
Object value = taskParams.get(name); |
|
380 |
return (value != null && value instanceof double[]) ? ((double[])value) : null; |
|
381 |
} |
|
382 |
|
|
383 |
/** |
|
384 |
* Obtiene un par?metro capa raster a partir de la clave |
|
385 |
* @param name Par?metro |
|
386 |
* @return Par?metro |
|
387 |
*/ |
|
388 |
public FLyrRaster getLayerParam(String name) { |
|
389 |
Object value = taskParams.get(name); |
|
390 |
return (value != null && value instanceof FLyrRaster) ? ((FLyrRaster)value) : null; |
|
391 |
} |
|
392 |
|
|
393 |
/** |
|
394 |
* Obtiene un par?metro extent a partir de la clave |
|
395 |
* @param name Par?metro |
|
396 |
* @return Par?metro |
|
397 |
*/ |
|
398 |
public Extent getExtentParam(String name) { |
|
399 |
Object value = taskParams.get(name); |
|
400 |
return (value != null && value instanceof Extent) ? ((Extent)value) : null; |
|
401 |
} |
|
402 |
|
|
403 |
/* |
|
404 |
* (non-Javadoc) |
|
405 |
* @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionResumed(org.gvsig.gui.beans.incrementabletask.IncrementableEvent) |
|
406 |
*/ |
|
407 |
public void actionResumed(IncrementableEvent e) { |
|
408 |
} |
|
409 |
|
|
410 |
/* |
|
411 |
* (non-Javadoc) |
|
412 |
* @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionSuspended(org.gvsig.gui.beans.incrementabletask.IncrementableEvent) |
|
413 |
*/ |
|
414 |
public void actionSuspended(IncrementableEvent e) { |
|
415 |
} |
|
416 |
|
|
417 |
/* |
|
418 |
* (non-Javadoc) |
|
419 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#isCancelable() |
|
420 |
*/ |
|
421 |
public boolean isCancelable() { |
|
422 |
return true; |
|
423 |
} |
|
424 |
|
|
425 |
/* |
|
426 |
* (non-Javadoc) |
|
427 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#isPausable() |
|
428 |
*/ |
|
429 |
public boolean isPausable() { |
|
430 |
return false; |
|
431 |
} |
|
432 |
|
|
433 |
public void dispose() { |
|
434 |
try { |
|
435 |
finalize(); |
|
436 |
} catch (Throwable e) { |
|
437 |
} |
|
438 |
} |
|
439 |
|
|
440 |
/* |
|
441 |
* (non-Javadoc) |
|
442 |
* @see java.lang.Object#finalize() |
|
443 |
*/ |
|
444 |
@Override |
|
445 |
protected void finalize() throws Throwable { |
|
446 |
incrementableTask = null; |
|
447 |
blinker = null; |
|
448 |
externalActions = null; |
|
449 |
if(taskParams != null) { |
|
450 |
taskParams.clear(); |
|
451 |
taskParams = null; |
|
452 |
} |
|
453 |
log = null; |
|
454 |
lastLine = null; |
|
455 |
queueActions = null; |
|
456 |
logger = null; |
|
457 |
super.finalize(); |
|
458 |
} |
|
459 |
} |
|
0 | 460 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.2/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ClippingProcess.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import java.awt.Rectangle; |
|
25 |
import java.awt.geom.AffineTransform; |
|
26 |
import java.awt.geom.Point2D; |
|
27 |
import java.io.File; |
|
28 |
import java.io.IOException; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
import org.gvsig.app.project.ProjectManager; |
|
34 |
import org.gvsig.app.project.documents.Document; |
|
35 |
import org.gvsig.app.project.documents.view.BaseViewDocument; |
|
36 |
import org.gvsig.fmap.dal.DALLocator; |
|
37 |
import org.gvsig.fmap.dal.DataManager; |
|
38 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
39 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
40 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
41 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
43 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
44 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
45 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
46 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
47 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
48 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
49 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
50 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
|
51 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
52 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
|
53 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
|
54 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
55 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
56 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
57 |
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters; |
|
58 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
|
59 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
60 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
|
61 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
|
62 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
63 |
import org.gvsig.fmap.dal.exception.DataException; |
|
64 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
65 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
66 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
68 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
69 |
import org.gvsig.i18n.Messages; |
|
70 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
71 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
|
72 |
import org.gvsig.raster.mainplugin.RasterMainPluginUtils; |
|
73 |
import org.gvsig.raster.roi.ROI; |
|
74 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
75 |
import org.gvsig.raster.util.RasterNotLoadException; |
|
76 |
import org.slf4j.LoggerFactory; |
|
77 |
/** |
|
78 |
* <code>ClippingProcess</code> es un proceso que usa un <code>Thread</code> |
|
79 |
* para aplicar un recorte a una capa y guardarlo en disco. Muestra una barra |
|
80 |
* de incremento informativa. |
|
81 |
* |
|
82 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
83 |
*/ |
|
84 |
public class ClippingProcess extends DataProcess { |
|
85 |
public static final String PROCESS_LABEL = "ClippingProcess"; |
|
86 |
public static String FILENAME = "filename"; |
|
87 |
public static String SUFFIX = "suffix"; |
|
88 |
public static String VIEWNAME = "viewname"; |
|
89 |
public static String PX_COORDS = "pixelcoordinates"; |
|
90 |
public static String WORLD_COORDS = "realcoordinates"; |
|
91 |
public static String RASTER_STORE = "layer"; |
|
92 |
public static String DRAWABLE_BANDS = "drawablebands"; |
|
93 |
public static String ONE_LYE_PER_BAND = "onelayerperband"; |
|
94 |
public static String INTERP_METHOD = "interpolationmethod"; |
|
95 |
public static String AT = "affinetransform"; |
|
96 |
public static String COLOR_INTERPR = "colorInterpretation"; |
|
97 |
public static String SELECTED_ROIS = "selectedrois"; |
|
98 |
public static String RESOLUTION = "resolution"; |
|
99 |
public static String DRIVER_PARAMS = "driverparams"; |
|
100 |
public static String VIEW_PROJ = "viewProjection"; |
|
101 |
|
|
102 |
private String fileName = ""; |
|
103 |
private String suffix = ".tif"; |
|
104 |
private RasterDataStore dataStore = null; |
|
105 |
private boolean oneLayerPerBand = false; |
|
106 |
private int[] drawableBands = { 0, 1, 2 }; |
|
107 |
private double[] pValues = null; |
|
108 |
private int interpolationMethod = Buffer.INTERPOLATION_Undefined; |
|
109 |
private String viewName = ""; |
|
110 |
private Params params = null; |
|
111 |
private ColorInterpretation colorInterp = null; |
|
112 |
private ArrayList<ROI> selectedRois = null; |
|
113 |
private AffineTransform affineTransform = null; |
|
114 |
private double[] wcValues = null; |
|
115 |
private RasterManager rManager = RasterLocator.getManager(); |
|
116 |
private BaseIncrementableTask processIncrement = null; |
|
117 |
|
|
118 |
/** |
|
119 |
* Variables de la resoluci?n de salida |
|
120 |
*/ |
|
121 |
private int resolutionWidth = 0; |
|
122 |
private int resolutionHeight = 0; |
|
123 |
|
|
124 |
private Buffer buffer = null; |
|
125 |
private IProjection viewProjection = null; |
|
126 |
|
|
127 |
public static void registerParameters() { |
|
128 |
registerInputParameter(FILENAME, String.class, PROCESS_LABEL); |
|
129 |
registerInputParameter(SUFFIX, String.class, PROCESS_LABEL); |
|
130 |
registerInputParameter(VIEWNAME, String.class, PROCESS_LABEL); |
|
131 |
registerInputParameter(PX_COORDS, Double.class, PROCESS_LABEL); |
|
132 |
registerInputParameter(WORLD_COORDS, Double.class, PROCESS_LABEL); |
|
133 |
registerInputParameter(RASTER_STORE, RasterDataStore.class, PROCESS_LABEL); |
|
134 |
registerInputParameter(DRAWABLE_BANDS, Integer[].class, PROCESS_LABEL); |
|
135 |
registerInputParameter(ONE_LYE_PER_BAND, Boolean.class, PROCESS_LABEL); |
|
136 |
registerInputParameter(INTERP_METHOD, Integer.class, PROCESS_LABEL); |
|
137 |
registerInputParameter(AT, AffineTransform.class, PROCESS_LABEL); |
|
138 |
registerInputParameter(COLOR_INTERPR, ColorInterpretation.class, PROCESS_LABEL); |
|
139 |
registerInputParameter(SELECTED_ROIS, ArrayList.class, PROCESS_LABEL); |
|
140 |
registerInputParameter(RESOLUTION, Integer[].class, PROCESS_LABEL); |
|
141 |
registerInputParameter(DRIVER_PARAMS, Params.class, PROCESS_LABEL); |
|
142 |
registerInputParameter(VIEW_PROJ, IProjection.class, PROCESS_LABEL); |
|
143 |
|
|
144 |
//TODO: Falta definir salidas y asignarlas en el Map |
|
145 |
registerOutputParameter(FILENAME, String.class, PROCESS_LABEL); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Par?metros obligatorios al proceso: |
|
150 |
* <UL> |
|
151 |
* <LI>filename: Nombre del fichero de salida</LI> |
|
152 |
* <LI>datawriter: Escritor de datos</LI> |
|
153 |
* <LI>viewname: Nombre de la vista sobre la que se carga la capa al acabar el proceso</LI> |
|
154 |
* <LI>pixelcoordinates: Coordenadas pixel del recorte (ulx, uly, lrx, lry)</LI> |
|
155 |
* <LI>layer: Capa de entrada para el recorte</LI> |
|
156 |
* <LI>drawablebands: Bandas de entrada</LI> |
|
157 |
* <LI>onelayerperband: booleano que informa de si escribimos una banda por fichero de salida o todas en un fichero</LI> |
|
158 |
* <LI>interpolationmethod: M?todo de interpolaci?n.</LI> |
|
159 |
* <LI>affinetransform: Transformaci?n que informa al dataset de salida de su referencia geografica</LI> |
|
160 |
* <LI>resolution: Ancho y alto de la capa de salida</LI> |
|
161 |
* </UL> |
|
162 |
*/ |
|
163 |
@SuppressWarnings("unchecked") |
|
164 |
public void init() { |
|
165 |
fileName = getStringParam("filename"); |
|
166 |
suffix = getStringParam("suffix"); |
|
167 |
viewName = getStringParam("viewname"); |
|
168 |
pValues = getDoubleArrayParam("pixelcoordinates"); |
|
169 |
wcValues = getDoubleArrayParam("realcoordinates"); |
|
170 |
dataStore = getParam("layer") != null ? (RasterDataStore)getParam("layer") : null; |
|
171 |
drawableBands = getIntArrayParam("drawablebands"); |
|
172 |
oneLayerPerBand = getBooleanParam("onelayerperband"); |
|
173 |
interpolationMethod = getIntParam("interpolationmethod"); |
|
174 |
affineTransform = (AffineTransform)getParam("affinetransform"); |
|
175 |
colorInterp = (ColorInterpretation)getParam("colorInterpretation"); |
|
176 |
selectedRois = (ArrayList<ROI>)getParam("selectedrois"); |
|
177 |
if(getIntArrayParam("resolution") != null) { |
|
178 |
resolutionWidth = getIntArrayParam("resolution")[0]; |
|
179 |
resolutionHeight = getIntArrayParam("resolution")[1]; |
|
180 |
} |
|
181 |
params = (Params) getParam("driverparams"); |
|
182 |
viewProjection = getParam("viewProjection") != null ? (IProjection)getParam("viewProjection") : null; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Salva la tabla de color al fichero rmf. |
|
187 |
* @param fName |
|
188 |
* @throws IOException |
|
189 |
*/ |
|
190 |
private void saveToRmf(String fileName) { |
|
191 |
int limitNumberOfRequests = 20; |
|
192 |
while (dataStore == null && limitNumberOfRequests > 0) { |
|
193 |
try { |
|
194 |
} catch (IndexOutOfBoundsException e) { |
|
195 |
//En ocasiones, sobre todo con servicios remotos al pedir un datasource da una excepci?n de este tipo |
|
196 |
//se supone que es porque hay un refresco en el mismo momento de la petici?n por lo que como es m?s lento de |
|
197 |
//gestionar pilla a la capa sin datasources asociados ya que est? reasignandolo. Si volvemos a pedirlo debe |
|
198 |
//haberlo cargado ya. |
|
199 |
try { |
|
200 |
Thread.sleep(200); |
|
201 |
} catch (InterruptedException e1) { |
|
202 |
} |
|
203 |
} |
|
204 |
limitNumberOfRequests--; |
|
205 |
} |
|
206 |
|
|
207 |
if (dataStore == null) { |
|
208 |
//RasterToolsUtil.messageBoxError("error_load_layer", this, new Exception("Error writing RMF. limitNumberOfRequests=" + limitNumberOfRequests)); |
|
209 |
return; |
|
210 |
} |
|
211 |
|
|
212 |
// Guardamos en el RMF el valor NoData |
|
213 |
if(dataStore.getNoDataValue() != null) { |
Also available in: Unified diff