gvsig-raster / org.gvsig.raster.tools / trunk / templates / rasterTaskProjectTemplate / alg_with_preview_template / sources / algorithm / ProjectTemplateProcess.java @ 1927
History | View | Annotate | Download (5.27 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.algorithm.RasterBaseAlgorithmLibrary; |
17 |
import org.gvsig.raster.algorithm.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 |
public static String EXPORT = "Export"; |
29 |
|
30 |
public static String TEST_EXTENT = "TestExtent"; |
31 |
public static String TEST_WIDTH = "TestWidth"; |
32 |
public static String TEST_HEIGHT = "TestHeight"; |
33 |
|
34 |
private RasterDataStore store = null; |
35 |
private String filename = null; |
36 |
private long millis = 0; |
37 |
private boolean export = true; |
38 |
|
39 |
private Extent testExtent = null; |
40 |
private int testWidth = 0; |
41 |
private int testHeight = 0; |
42 |
|
43 |
/**
|
44 |
* This buffer is just to test
|
45 |
*/
|
46 |
private Buffer bufferForTest = null; |
47 |
|
48 |
public static void registerParameters() { |
49 |
RASTER_STORE1 = RasterBaseAlgorithmLibrary.registerInputParameter(RASTER_STORE1, RasterDataStore.class); |
50 |
PATH = RasterBaseAlgorithmLibrary.registerInputParameter(PATH, String.class);
|
51 |
EXPORT = RasterBaseAlgorithmLibrary.registerInputParameter(EXPORT, Boolean.class);
|
52 |
TEST_EXTENT = RasterBaseAlgorithmLibrary.registerInputParameter(TEST_EXTENT, Extent.class); |
53 |
TEST_WIDTH = RasterBaseAlgorithmLibrary.registerInputParameter(TEST_WIDTH, Integer.class);
|
54 |
TEST_HEIGHT = RasterBaseAlgorithmLibrary.registerInputParameter(TEST_HEIGHT, Integer.class);
|
55 |
|
56 |
FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class);
|
57 |
TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class);
|
58 |
} |
59 |
|
60 |
public void init() { |
61 |
store = getParam(RASTER_STORE1) != null ? (RasterDataStore)getParam(RASTER_STORE1) : null; |
62 |
filename = getStringParam(PATH); |
63 |
export = getBooleanParam(EXPORT);
|
64 |
|
65 |
testExtent = getParam(TEST_EXTENT) != null ? (Extent)getParam(TEST_EXTENT) : null; |
66 |
testWidth = getIntParam(TEST_WIDTH); |
67 |
testHeight = getIntParam(TEST_HEIGHT); |
68 |
} |
69 |
|
70 |
public void process() throws ProcessInterruptedException { |
71 |
long t1 = new java.util.Date().getTime(); |
72 |
insertLineLog(Messages.getText("..."));
|
73 |
try {
|
74 |
if (store == null) |
75 |
throw new ProjectTemplateException("..."); |
76 |
|
77 |
Extent windowExtent = store.getExtent(); |
78 |
int w = (int)store.getWidth(); |
79 |
int h = (int)store.getHeight(); |
80 |
double cellSize = store.getCellSize();
|
81 |
|
82 |
if(testExtent != null) { |
83 |
windowExtent = testExtent; |
84 |
w = testWidth; |
85 |
h = testHeight; |
86 |
cellSize = testExtent.width() / w; |
87 |
} |
88 |
|
89 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
90 |
query.setAllDrawableBands(); |
91 |
query.setAreaOfInterest(testExtent, testWidth, testHeight); |
92 |
Buffer sourceBuffer = null; |
93 |
try {
|
94 |
sourceBuffer = store.query(query); |
95 |
sourceBuffer.setDataExtent(testExtent.toRectangle2D()); |
96 |
} catch (RasterDriverException e) {
|
97 |
throw new ProjectTemplateException(""); |
98 |
} catch (InvalidSetViewException e) {
|
99 |
throw new ProjectTemplateException(""); |
100 |
} |
101 |
bufferForTest = sourceBuffer; |
102 |
|
103 |
//////////////////////////
|
104 |
//TODO:PROCESS!!
|
105 |
|
106 |
//int inDataType = store.getDataType()[0];
|
107 |
//Buffer buf = RasterLocator.getManager().createBuffer(
|
108 |
// inDataType,
|
109 |
// (int)store.getWidth(),
|
110 |
// (int)store.getHeight(),
|
111 |
// store.getBandCount(),
|
112 |
// true);
|
113 |
//updatePercent(row, buf.getHeight());
|
114 |
//////////////////////////
|
115 |
|
116 |
/*if(export) {
|
117 |
super.exportRaster(filename,
|
118 |
buf,
|
119 |
cellSize,
|
120 |
windowExtent.getULX(),
|
121 |
windowExtent.getULY());
|
122 |
}*/
|
123 |
|
124 |
long t2 = new java.util.Date().getTime(); |
125 |
millis = t2 - t1; |
126 |
|
127 |
SwingUtilities.invokeLater(new Runnable() { |
128 |
public void run() { |
129 |
if (externalActions != null) { |
130 |
externalActions.end(getResult()); |
131 |
} |
132 |
} |
133 |
}); |
134 |
} catch (ProjectTemplateException e) {
|
135 |
if (incrementableTask != null) |
136 |
incrementableTask.processFinalize(); |
137 |
messageBoxError("...", this, e); |
138 |
} |
139 |
} |
140 |
|
141 |
public Object getResult() { |
142 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
143 |
map.put(FILENAME, filename); |
144 |
map.put(TIME, new Long(millis)); |
145 |
map.put(BUFFER, bufferForTest); |
146 |
return map;
|
147 |
} |
148 |
|
149 |
public int getPercent() { |
150 |
return percent;
|
151 |
} |
152 |
|
153 |
public String getTitle() { |
154 |
return Messages.getText("..."); |
155 |
} |
156 |
} |