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