Revision 3170 org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.toolbox.algorithm/src/main/java/org/gvsig/raster/tools/LayerDatatypeSextanteAlgorithm.java

View differences:

LayerDatatypeSextanteAlgorithm.java
35 35
	public static final String DATATYPE          = "Datatype";
36 36
	public static final String ADJUST_DEC2INT    = "AdjustDec2Int";
37 37
	public static final String ADJUST_BIG2SMALL  = "AdjustBig2Small";
38
	
38

  
39 39
	public static String[]    DEC2INT_OPTIONS    = new String[]{"Trunk", "Round", "Ceil", "Floor"};
40 40
	public static String[]    BIG2SMALL_OPTIONS  = new String[]{"Trunk", "Maxvalue", "NoData"};
41 41
	public static String[]    DATATYPES          = new String[]{"Byte", "UShort", "Short", "Integer", "Float", "Double"};
42
	
42

  
43 43
    private DataProcess        task            = null;
44
    
45 44

  
45

  
46 46
    public void defineCharacteristics() {
47 47
        setName(getTranslation("layer_datatype"));
48 48
        setGroup(getTranslation("raster_layer"));
49
       
49

  
50 50
        try {
51 51
            m_Parameters.addInputRasterLayer(LAYER, getTranslation("Input_layer"), true);
52 52
            m_Parameters.addSelection(DATATYPE, getTranslation("dst_datatype"), DATATYPES);
......
63 63
    	if(existsOutPutFile(LayerDatatypeSextanteAlgorithm.RESULT, 0)) {
64 64
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
65 65
    	}
66
    	
66

  
67 67
    	IRasterLayer input = m_Parameters.getParameterValueAsRasterLayer(LAYER);
68
    	
68

  
69 69
    	FLyrRaster lyrRaster = ((FLyrRaster)input.getBaseDataObject());
70 70
    	IRasterLayer output = null;
71 71

  
72 72
    	output = getNewRORasterLayer(
73
    			RESULT, 
74
    			Sextante.getText("layerdatatype_description"), 
75
    			input.getDataType(), 
73
    			RESULT,
74
    			Sextante.getText("layerdatatype_description"),
75
    			input.getDataType(),
76 76
    			input.getBandsCount());
77 77

  
78
    	String fileName = ((FLyrRasterIRasterLayer)output).getFileName(); //getOutPutFile(RESULT);
78
    	String fileName = ((FLyrRasterIRasterLayer)output).getName();
79 79

  
80 80
    	try {
81 81
    		setProgressText(getTranslation("convert_datatype"));
......
83 83
			task.execute();
84 84
			HashMap<String, Object> params = task.getResult();
85 85
			fileName = (String)params.get("FileName");
86
			
86

  
87 87
			((FLyrRasterIRasterLayer)output).setBaseDataObject(fileName);
88 88
		} catch (ProcessInterruptedException e) {
89 89
			Sextante.addErrorToLog(e);
90 90
		} catch (ProcessException e) {
91 91
			Sextante.addErrorToLog(e);
92
		} 
92
		}
93 93

  
94 94
		if(getTaskMonitor().isCanceled())
95 95
			return false;
96 96

  
97 97
        return true;
98 98
    }
99
    
99

  
100 100
    /**
101 101
     * Creates a process to calculate statistics
102 102
     * @param inputStore
103 103
     * @return
104 104
     * @throws ProcessException
105
     * @throws NullParameterAdditionalInfoException 
106
     * @throws NullParameterValueException 
107
     * @throws WrongParameterIDException 
108
     * @throws WrongParameterTypeException 
105
     * @throws NullParameterAdditionalInfoException
106
     * @throws NullParameterValueException
107
     * @throws WrongParameterIDException
108
     * @throws WrongParameterTypeException
109 109
     */
110 110
    private DataProcess createLayerDatatypeProcess(RasterDataStore inputStore, String fileName) throws ProcessException, WrongParameterTypeException, WrongParameterIDException, NullParameterValueException, NullParameterAdditionalInfoException {
111 111
    	DataProcess taskStats = RasterBaseAlgorithmLibrary.getManager().createRasterTask("LayerDatatypeProcess");
......
117 117
    		if(paramType == RasterDataStore.class) {
118 118
    			taskStats.addParam(paramName, (RasterDataStore)inputStore);
119 119
    		}
120
    		
120

  
121 121
    		if(paramName.equals("Path")) {
122 122
    			taskStats.addParam(paramName, fileName);
123 123
    		}
124
    		
124

  
125 125
    		if(paramName.equals(DATATYPE)) {
126 126
    			String value = m_Parameters.getParameterValueAsString(DATATYPE);
127 127
    			int position = 0;
......
131 131
				}
132 132
    			taskStats.addParam(paramName, position);
133 133
    		}
134
    		
134

  
135 135
    		if(paramName.equals(ADJUST_DEC2INT)) {
136 136
    			String value = m_Parameters.getParameterValueAsString(ADJUST_DEC2INT);
137 137
    			int position = 0;
......
141 141
				}
142 142
    			taskStats.addParam(paramName, position);
143 143
    		}
144
    		
144

  
145 145
    		if(paramName.equals(ADJUST_BIG2SMALL)) {
146 146
    			String value = m_Parameters.getParameterValueAsString(ADJUST_BIG2SMALL);
147 147
    			int position = 0;
......
157 157
    			Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
158 158
    					ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
159 159
    			Extent inputBbox = inputStore.getExtent();
160
    			if(bbox.getULX() != inputBbox.getULX() || 
161
    				bbox.getULY() != inputBbox.getULY() || 
162
    				bbox.getLRX() != inputBbox.getLRX() || 
160
    			if(bbox.getULX() != inputBbox.getULX() ||
161
    				bbox.getULY() != inputBbox.getULY() ||
162
    				bbox.getLRX() != inputBbox.getLRX() ||
163 163
    				bbox.getLRY() != inputBbox.getLRY()) {
164 164
    				taskStats.addParam(paramName, bbox);
165 165
    			}
......
167 167
    	}
168 168
    	return taskStats;
169 169
    }
170
    
170

  
171 171
	public void interrupted() {
172
		
172

  
173 173
	}
174 174

  
175 175
	public void end(Object param) {
176
		
176

  
177 177
	}
178 178

  
179 179
	public void updateProgress(int current, int total) {
180 180
		boolean cancelled = setProgress(current, total);
181
		
181

  
182 182
		if(!cancelled) {
183 183
			if(task != null)
184 184
				task.actionCanceled(null);
185 185
		}
186 186
	}
187
    
187

  
188 188
    /*
189 189
     * TODO: Customized panels
190 190
    @Override

Also available in: Unified diff