gvsig-raster / org.gvsig.raster.tools / trunk / templates / rasterTaskProjectTemplate / alg_with_preview_template / sources / algorithm / ProjectTemplateProcess.java @ 2139
History | View | Annotate | Download (5.22 KB)
1 |
package org.gvsig.raster.projecttemplate.algorithm; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.List; |
5 |
|
6 |
import javax.swing.SwingUtilities; |
7 |
import java.awt.geom.Rectangle2D; |
8 |
|
9 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
10 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
11 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
12 |
import org.gvsig.fmap.dal.coverage.exception.CloneException; |
13 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
14 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
15 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
16 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
17 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
18 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
19 |
import org.gvsig.i18n.Messages; |
20 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
21 |
import org.gvsig.raster.algorithm.process.DataProcess; |
22 |
import org.gvsig.raster.roi.ROI; |
23 |
|
24 |
/**
|
25 |
* Process
|
26 |
*/
|
27 |
public class ProjectTemplateProcess extends DataProcess { |
28 |
public static String RASTER_STORE = "RasterStore"; |
29 |
public static String BUFFER = "RasterStore"; |
30 |
public static String PATH = "Path"; |
31 |
public static String FILENAME = "FileName"; |
32 |
public static String EXPORT = "Export"; |
33 |
|
34 |
public static String TEST_EXTENT = "TestExtent"; |
35 |
public static String TEST_WIDTH = "TestWidth"; |
36 |
public static String TEST_HEIGHT = "TestHeight"; |
37 |
|
38 |
private RasterDataStore store = null; |
39 |
private String filename = null; |
40 |
private boolean export = true; |
41 |
private List<ROI> rois = null; |
42 |
private Extent extentResult = null; |
43 |
|
44 |
private Extent testExtent = null; |
45 |
private int testWidth = 0; |
46 |
private int testHeight = 0; |
47 |
|
48 |
/**
|
49 |
* This buffer is just to test
|
50 |
*/
|
51 |
private Buffer bufferForTest = null; |
52 |
|
53 |
public static void registerParameters() { |
54 |
registerInputParameter(RASTER_STORE, RasterDataStore.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL); |
55 |
registerInputParameter(PATH, String.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL);
|
56 |
registerInputParameter(EXPORT, Boolean.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL);
|
57 |
registerInputParameter(TEST_EXTENT, Extent.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL); |
58 |
registerInputParameter(TEST_WIDTH, Integer.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL);
|
59 |
registerInputParameter(TEST_HEIGHT, Integer.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL);
|
60 |
|
61 |
registerOutputParameter(FILENAME, String.class, ProjectTemplateAlgorithmLibrary.PROCESS_LABEL);
|
62 |
} |
63 |
|
64 |
public void init() { |
65 |
store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null; |
66 |
filename = getStringParam(PATH); |
67 |
export = getBooleanParam(EXPORT);
|
68 |
|
69 |
testExtent = getParam(TEST_EXTENT) != null ? (Extent)getParam(TEST_EXTENT) : null; |
70 |
testWidth = getIntParam(TEST_WIDTH); |
71 |
testHeight = getIntParam(TEST_HEIGHT); |
72 |
} |
73 |
|
74 |
public void process() throws ProcessInterruptedException { |
75 |
insertLineLog(Messages.getText("..."));
|
76 |
try {
|
77 |
if (store == null) |
78 |
throw new ProjectTemplateException("..."); |
79 |
|
80 |
if(getROIEPSG() != null) { |
81 |
try {
|
82 |
rois = store.getRois(getROIEPSG()); |
83 |
} catch (ROIException e2) {
|
84 |
logger.error(Messages.getText("error_getting_rois"), e2);
|
85 |
} |
86 |
} |
87 |
|
88 |
try {
|
89 |
store = ((RasterDataStore)store).cloneDataStore(); |
90 |
} catch (CloneException e) {
|
91 |
new ProjectTemplateException("Error cloning the input DataStore", e); |
92 |
} |
93 |
|
94 |
extentResult = getExtentResult(getOutputWindow(), rois, store); |
95 |
Rectangle2D sourcePxBBox = getSourcePxBox(extentResult, store);
|
96 |
double cellSize = store.getCellSize();
|
97 |
|
98 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
99 |
query.setAllDrawableBands(); |
100 |
query.setAreaOfInterest(testExtent, testWidth, testHeight); |
101 |
Buffer sourceBuffer = null; |
102 |
try {
|
103 |
sourceBuffer = store.query(query); |
104 |
sourceBuffer.setDataExtent(testExtent.toRectangle2D()); |
105 |
} catch (RasterDriverException e) {
|
106 |
throw new ProjectTemplateException(""); |
107 |
} catch (InvalidSetViewException e) {
|
108 |
throw new ProjectTemplateException(""); |
109 |
} |
110 |
bufferForTest = sourceBuffer; |
111 |
|
112 |
//////////////////////////
|
113 |
//TODO:PROCESS!!
|
114 |
|
115 |
//int inDataType = store.getDataType()[0];
|
116 |
//Buffer buf = RasterLocator.getManager().createBuffer(
|
117 |
// inDataType,
|
118 |
// (int)store.getWidth(),
|
119 |
// (int)store.getHeight(),
|
120 |
// store.getBandCount(),
|
121 |
// true);
|
122 |
//updatePercent(row, buf.getHeight());
|
123 |
//////////////////////////
|
124 |
|
125 |
/*if(export) {
|
126 |
super.exportRaster(filename,
|
127 |
buf,
|
128 |
cellSize,
|
129 |
windowExtent.getULX(),
|
130 |
windowExtent.getULY());
|
131 |
}*/
|
132 |
|
133 |
addOutputValue(FILENAME, filename); |
134 |
addOutputValue(BUFFER, bufferForTest); |
135 |
} catch (ProjectTemplateException e) {
|
136 |
if (incrementableTask != null) |
137 |
incrementableTask.processFinalize(); |
138 |
messageBoxError("...", this, e); |
139 |
} |
140 |
} |
141 |
|
142 |
public String getTitle() { |
143 |
return Messages.getText("..."); |
144 |
} |
145 |
} |