gvsig-raster / org.gvsig.raster.tools / trunk / templates / rasterTaskProjectTemplate / alg_with_preview_template / sources / algorithm / ProjectTemplateProcess.java @ 1843
History | View | Annotate | Download (4.66 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.datastruct.Extent; |
10 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
11 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
12 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
13 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
14 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
15 |
import org.gvsig.i18n.Messages; |
16 |
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary; |
17 |
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess; |
18 |
|
19 |
/**
|
20 |
* Process
|
21 |
*/
|
22 |
public class ProjectTemplateProcess extends RasterProcess { |
23 |
public static String RASTER_STORE1 = "RasterStore1"; |
24 |
public static String BUFFER = "RasterStore1"; |
25 |
public static String PATH = "Path"; |
26 |
public static String FILENAME = "FileName"; |
27 |
public static String TIME = "Time"; |
28 |
|
29 |
public static String TEST_EXTENT = "TestExtent"; |
30 |
public static String TEST_WIDTH = "TestWidth"; |
31 |
public static String TEST_HEIGHT = "TestHeight"; |
32 |
|
33 |
private RasterDataStore store = null; |
34 |
private String filename = null; |
35 |
private long millis = 0; |
36 |
|
37 |
private Extent testExtent = null; |
38 |
private int testWidth = 0; |
39 |
private int testHeight = 0; |
40 |
|
41 |
/**
|
42 |
* This buffer is just to test
|
43 |
*/
|
44 |
private Buffer bufferForTest = null; |
45 |
|
46 |
public static void registerParameters() { |
47 |
RASTER_STORE1 = RasterBaseAlgorithmLibrary.registerInputParameter(RASTER_STORE1, RasterDataStore.class); |
48 |
PATH = RasterBaseAlgorithmLibrary.registerInputParameter(PATH, String.class);
|
49 |
TEST_EXTENT = RasterBaseAlgorithmLibrary.registerInputParameter(TEST_EXTENT, Extent.class); |
50 |
TEST_WIDTH = RasterBaseAlgorithmLibrary.registerInputParameter(TEST_WIDTH, Integer.class);
|
51 |
TEST_HEIGHT = RasterBaseAlgorithmLibrary.registerInputParameter(TEST_HEIGHT, Integer.class);
|
52 |
|
53 |
FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class);
|
54 |
TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class);
|
55 |
} |
56 |
|
57 |
public void init() { |
58 |
store = getParam(RASTER_STORE1) != null ? (RasterDataStore)getParam(RASTER_STORE1) : null; |
59 |
filename = getStringParam(PATH); |
60 |
|
61 |
testExtent = getParam(TEST_EXTENT) != null ? (Extent)getParam(TEST_EXTENT) : null; |
62 |
testWidth = getIntParam(TEST_WIDTH); |
63 |
testHeight = getIntParam(TEST_HEIGHT); |
64 |
} |
65 |
|
66 |
public void process() throws ProcessInterruptedException { |
67 |
long t1 = new java.util.Date().getTime(); |
68 |
insertLineLog(Messages.getText("..."));
|
69 |
try {
|
70 |
if (store == null) |
71 |
throw new ProjectTemplateException("..."); |
72 |
|
73 |
|
74 |
//////////////////////////
|
75 |
//TODO:PROCESS!!
|
76 |
|
77 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
78 |
query.setAllDrawableBands(); |
79 |
query.setAreaOfInterest(testExtent, testWidth, testHeight); |
80 |
Buffer sourceBuffer = null; |
81 |
try {
|
82 |
sourceBuffer = store.query(query); |
83 |
sourceBuffer.setDataExtent(testExtent.toRectangle2D()); |
84 |
} catch (RasterDriverException e) {
|
85 |
throw new ProjectTemplateException(""); |
86 |
} catch (InvalidSetViewException e) {
|
87 |
throw new ProjectTemplateException(""); |
88 |
} |
89 |
bufferForTest = sourceBuffer; |
90 |
//int inDataType = store.getDataType()[0];
|
91 |
//Buffer buf = RasterLocator.getManager().createBuffer(
|
92 |
// inDataType,
|
93 |
// (int)store.getWidth(),
|
94 |
// (int)store.getHeight(),
|
95 |
// store.getBandCount(),
|
96 |
// true);
|
97 |
//updatePercent(row, buf.getHeight());
|
98 |
//super.exportRaster(filename, buf, cellsize, ulx, uly);
|
99 |
//////////////////////////
|
100 |
|
101 |
|
102 |
long t2 = new java.util.Date().getTime(); |
103 |
millis = t2 - t1; |
104 |
|
105 |
SwingUtilities.invokeLater(new Runnable() { |
106 |
public void run() { |
107 |
if (externalActions != null) { |
108 |
externalActions.end(getResult()); |
109 |
} |
110 |
} |
111 |
}); |
112 |
} catch (ProjectTemplateException e) {
|
113 |
if (incrementableTask != null) |
114 |
incrementableTask.processFinalize(); |
115 |
messageBoxError("...", this, e); |
116 |
} |
117 |
} |
118 |
|
119 |
public Object getResult() { |
120 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
121 |
map.put(FILENAME, filename); |
122 |
map.put(TIME, new Long(millis)); |
123 |
map.put(BUFFER, bufferForTest); |
124 |
return map;
|
125 |
} |
126 |
|
127 |
public int getPercent() { |
128 |
return percent;
|
129 |
} |
130 |
|
131 |
public String getTitle() { |
132 |
return Messages.getText("..."); |
133 |
} |
134 |
} |