Revision 3171

View differences:

org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.toolbox.algorithm/src/main/java/org/gvsig/raster/principalcomponents/PrincipalComponentsSextanteAlgorithm.java
31 31
    public static final String RESULT            = "RESULT";
32 32
    public static final String LAYER             = PrincipalComponentsProcess.RASTER_STORE;
33 33
    public static final String USE_ROI           = "USE_ROI";
34
    
34

  
35 35
    private boolean            useROI            = false;
36 36
    private DataProcess        taskStats         = null;
37 37
    private DataProcess        taskPC            = null;
38
    
39 38

  
39

  
40 40
    public void defineCharacteristics() {
41 41
        setName(getTranslation("principalcomponents"));
42 42
        setGroup(getTranslation("multispectral"));
43
       
43

  
44 44
        try {
45 45
            m_Parameters.addInputRasterLayer(LAYER, getTranslation("Input_layer"), true);
46 46
            m_Parameters.addBoolean(USE_ROI, getTranslation("use_roi"), false);
......
55 55
    	if(existsOutPutFile(PrincipalComponentsSextanteAlgorithm.RESULT, 0)) {
56 56
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
57 57
    	}
58
    	
58

  
59 59
    	IRasterLayer input = m_Parameters.getParameterValueAsRasterLayer(LAYER);
60 60
		useROI = m_Parameters.getParameterValueAsBoolean(USE_ROI);
61
    	
61

  
62 62
    	FLyrRaster lyrRaster = ((FLyrRaster)input.getBaseDataObject());
63 63
    	IRasterLayer output = null;
64 64

  
65 65
    	output = getNewRORasterLayer(
66
    			RESULT, 
67
    			Sextante.getText("principalcomponents_description"), 
68
    			input.getDataType(), 
66
    			RESULT,
67
    			Sextante.getText("principalcomponents_description"),
68
    			input.getDataType(),
69 69
    			input.getBandsCount());
70 70

  
71
    	String fileName = ((FLyrRasterIRasterLayer)output).getFileName(); //getOutPutFile(RESULT);
71
    	String fileName = ((FLyrRasterIRasterLayer)output).getName();
72 72

  
73 73
    	try {
74 74
    		setProgressText(getTranslation("stadistics"));
......
76 76
			taskStats.execute();
77 77
			HashMap<String, Object> params = taskStats.getResult();
78 78
			PCStatsDataStructure stats = (PCStatsDataStructure)params.get("STATS_RESULT");
79
			
79

  
80 80
			setProgressText(getTranslation("calc_components"));
81 81
			taskPC = createPCAProcess(lyrRaster.getDataStore(), fileName, stats);
82 82
			taskPC.execute();
83 83
			params = taskPC.getResult();
84
			
84

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

  
92 92
		if(getTaskMonitor().isCanceled())
93 93
			return false;
94 94

  
95 95
        return true;
96 96
    }
97
    
97

  
98 98
    /**
99 99
     * Creates a process to calculate statistics
100 100
     * @param inputStore
......
122 122
    		if(paramName.equals("ROI_EPSG") && useROI) {
123 123
    			taskStats.addParam(paramName, "EPSG:4326");
124 124
    		}
125
    		
125

  
126 126
    		if(paramName.equals("WINDOW")) {
127 127
    			AnalysisExtent ext = getAnalysisExtent();
128 128
    			Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
129 129
    					ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
130 130
    			Extent inputBbox = inputStore.getExtent();
131
    			if(bbox.getULX() != inputBbox.getULX() || 
132
    				bbox.getULY() != inputBbox.getULY() || 
133
    				bbox.getLRX() != inputBbox.getLRX() || 
131
    			if(bbox.getULX() != inputBbox.getULX() ||
132
    				bbox.getULY() != inputBbox.getULY() ||
133
    				bbox.getLRX() != inputBbox.getLRX() ||
134 134
    				bbox.getLRY() != inputBbox.getLRY()) {
135 135
    				taskStats.addParam(paramName, bbox);
136 136
    			}
......
138 138
    	}
139 139
    	return taskStats;
140 140
    }
141
    
141

  
142 142
    private DataProcess createPCAProcess(RasterDataStore inputStore, String fileName, PCStatsDataStructure stats) throws ProcessException {
143 143
    	DataProcess taskPC = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
144 144
    	taskPC.setActions(this);
......
149 149
    		if(paramType == RasterDataStore.class) {
150 150
    			taskPC.addParam(paramName, (RasterDataStore)inputStore);
151 151
    		}
152
			
152

  
153 153
			if(paramType == Boolean[].class) {
154 154
    			boolean[] bands = new boolean[inputStore.getBandCount()];
155 155
    			for (int j = 0; j < bands.length; j++) {
......
157 157
				}
158 158
    			taskPC.addParam(paramName, bands);
159 159
			}
160
			
160

  
161 161
			if(paramType == PCStatsDataStructure.class) {
162 162
				taskPC.addParam(paramName, stats);
163 163
			}
164
			
164

  
165 165
			if(paramName.equals("PATH")) {
166 166
				taskPC.addParam(paramName, fileName);
167 167
			}
168
			
168

  
169 169
			if(paramName.equals("ROI_EPSG") && useROI) {
170 170
				taskPC.addParam(paramName, "EPSG:4326");
171 171
    		}
172
			
172

  
173 173
			if(paramName.equals("WINDOW")) {
174 174
    			AnalysisExtent ext = getAnalysisExtent();
175 175
    			Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(
176 176
    					ext.getXMin(), ext.getYMax(), ext.getXMax(), ext.getYMin());
177 177
    			Extent inputBbox = inputStore.getExtent();
178
    			if(bbox.getULX() != inputBbox.getULX() || 
179
    				bbox.getULY() != inputBbox.getULY() || 
180
    				bbox.getLRX() != inputBbox.getLRX() || 
178
    			if(bbox.getULX() != inputBbox.getULX() ||
179
    				bbox.getULY() != inputBbox.getULY() ||
180
    				bbox.getLRX() != inputBbox.getLRX() ||
181 181
    				bbox.getLRY() != inputBbox.getLRY()) {
182 182
    				taskPC.addParam(paramName, bbox);
183 183
    			}
......
187 187
    }
188 188

  
189 189
	public void interrupted() {
190
		
190

  
191 191
	}
192 192

  
193 193
	public void end(Object param) {
194
		
194

  
195 195
	}
196 196

  
197 197
	public void updateProgress(int current, int total) {
198 198
		boolean cancelled = setProgress(current, total);
199
		
199

  
200 200
		if(!cancelled) {
201 201
			if(taskStats != null)
202 202
				taskStats.actionCanceled(null);
......
204 204
				taskPC.actionCanceled(null);
205 205
		}
206 206
	}
207
    
207

  
208 208
    /*
209 209
     * TODO: Customized panels
210 210
    @Override
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/pom.xml
10 10
	<parent>
11 11
      <groupId>org.gvsig</groupId>
12 12
      <artifactId>org.gvsig.raster</artifactId>
13
      <version>2.2.4</version>
13
      <version>2.2.9</version>
14 14
  </parent>
15
    
15

  
16 16
    <repositories>
17 17
      <repository>
18 18
        <id>gvsig-public-http-repository</id>
......
30 30
        </snapshots>
31 31
      </repository>
32 32
    </repositories>
33
    
33

  
34 34
    <scm>
35 35
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents</connection>
36 36
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents</developerConnection>
......
48 48
            </plugin>
49 49
        </plugins>
50 50
    </build>
51
    		
51

  
52 52
	<dependencyManagement>
53 53
		<dependencies>
54
		
54

  
55 55
			<dependency>
56 56
				<groupId>org.gvsig.legacy</groupId>
57 57
				<artifactId>jama</artifactId>
......
60 60

  
61 61
    	<!--
62 62
    	Versions of other gvSIG projects
63
    	-->   	
63
    	-->
64 64
			<dependency>
65 65
	    	<groupId>org.gvsig</groupId>
66 66
 				<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId>
67
      	<version>2.2.0</version>
67
      	<version>2.2.22</version>
68 68
		  </dependency>
69 69
 			<dependency>
70 70
				<groupId>org.gvsig</groupId>
71 71
				<artifactId>org.gvsig.geoprocess.lib.sextante</artifactId>
72
				<version>2.2.0</version>
72
				<version>2.2.22</version>
73 73
			</dependency>
74 74
			<dependency>
75 75
				<groupId>org.gvsig</groupId>
76 76
				<artifactId>org.gvsig.geoprocess.app.mainplugin</artifactId>
77
				<version>2.2.0</version>
77
				<version>2.2.22</version>
78 78
			</dependency>
79 79

  
80 80
    	<!--
......
100 100
				<artifactId>org.gvsig.raster.principalcomponents.toolbox.algorithm</artifactId>
101 101
				<version>2.2.4-SNAPSHOT</version>
102 102
			</dependency>
103
	
103

  
104 104
		</dependencies>
105 105
	</dependencyManagement>
106 106
	<modules>

Also available in: Unified diff