gvsig-raster / org.gvsig.raster.tools / trunk / templates / rasterTaskProjectTemplate / alg_template / sources / algorithm / ProjectTemplateProcess.java @ 1908
History | View | Annotate | Download (3.51 KB)
1 |
package org.gvsig.raster.projecttemplate.algorithm; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
|
5 |
import javax.swing.SwingUtilities; |
6 |
|
7 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
8 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
9 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
10 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
11 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
12 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
13 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
14 |
import org.gvsig.i18n.Messages; |
15 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
16 |
import org.gvsig.raster.algorithm.process.RasterProcess; |
17 |
|
18 |
/**
|
19 |
* Process
|
20 |
*/
|
21 |
public class ProjectTemplateProcess extends RasterProcess { |
22 |
public static String RASTER_STORE1 = "RasterStore1"; |
23 |
public static String PATH = "Path"; |
24 |
public static String FILENAME = "FileName"; |
25 |
public static String TIME = "Time"; |
26 |
|
27 |
private RasterDataStore store = null; |
28 |
private String filename = null; |
29 |
private long millis = 0; |
30 |
|
31 |
public static void registerParameters() { |
32 |
RASTER_STORE1 = RasterBaseAlgorithmLibrary.registerInputParameter(RASTER_STORE1, RasterDataStore.class); |
33 |
PATH = RasterBaseAlgorithmLibrary.registerInputParameter(PATH, String.class);
|
34 |
FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class);
|
35 |
TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class);
|
36 |
} |
37 |
|
38 |
public void init() { |
39 |
store = getParam(RASTER_STORE1) != null ? (RasterDataStore)getParam(RASTER_STORE1) : null; |
40 |
filename = getStringParam(PATH); |
41 |
} |
42 |
|
43 |
public void process() throws ProcessInterruptedException { |
44 |
long t1 = new java.util.Date().getTime(); |
45 |
insertLineLog(Messages.getText("..."));
|
46 |
try {
|
47 |
if (store == null) |
48 |
throw new ProjectTemplateException("..."); |
49 |
|
50 |
int inDataType = store.getDataType()[0]; |
51 |
Buffer buf = RasterLocator.getManager().createBuffer(
|
52 |
inDataType, |
53 |
(int)store.getWidth(),
|
54 |
(int)store.getHeight(),
|
55 |
store.getBandCount(), |
56 |
true);
|
57 |
|
58 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
59 |
query.setAllDrawableBands(); |
60 |
query.setAreaOfInterest(); |
61 |
Buffer sourceBuffer = null; |
62 |
try {
|
63 |
sourceBuffer = store.query(query); |
64 |
} catch (RasterDriverException e) {
|
65 |
throw new ProjectTemplateException(""); |
66 |
} catch (InvalidSetViewException e) {
|
67 |
throw new ProjectTemplateException(""); |
68 |
} |
69 |
|
70 |
//updatePercent(row, buf.getHeight());
|
71 |
|
72 |
//super.exportRaster(filename, buf, cellsize, ulx, uly);
|
73 |
|
74 |
long t2 = new java.util.Date().getTime(); |
75 |
millis = t2 - t1; |
76 |
|
77 |
SwingUtilities.invokeLater(new Runnable() { |
78 |
public void run() { |
79 |
if (externalActions != null) { |
80 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
81 |
map.put(FILENAME, filename); |
82 |
map.put(TIME, new Long(millis)); |
83 |
externalActions.end(map); |
84 |
} |
85 |
} |
86 |
}); |
87 |
} catch (ProjectTemplateException e) {
|
88 |
if (incrementableTask != null) |
89 |
incrementableTask.processFinalize(); |
90 |
messageBoxError("...", this, e); |
91 |
} |
92 |
} |
93 |
|
94 |
public Object getResult() { |
95 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
96 |
map.put(FILENAME, filename); |
97 |
map.put(TIME, new Long(millis)); |
98 |
return map;
|
99 |
} |
100 |
|
101 |
public int getPercent() { |
102 |
return percent;
|
103 |
} |
104 |
|
105 |
public String getTitle() { |
106 |
return Messages.getText("..."); |
107 |
} |
108 |
} |