Revision 20871 trunk/libraries/libRaster/src/org/gvsig/raster/grid/Grid.java

View differences:

Grid.java
95 95
	public Grid(IRasterDataSource datasets, int[] bands, GridExtent windowExtent)
96 96
			throws RasterBufferInvalidException{
97 97
		BufferFactory bufferFactory = new BufferFactory(datasets);
98
		double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
99
											bufferFactory.getSourceHeight()); 
98 100
		layerExtent = new GridExtent(	bufferFactory.getDataSource().getExtent(), 
99
										calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth()));
101
										cellSize[0],
102
										cellSize[1]);
100 103
		if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
101 104
			dataType = bufferFactory.getDataSource().getDataType()[0];
102 105
		this.bands = bands;
......
154 157
	 * el reader es interpolado o no a partir de los extents de capa y la ventana seleccionada.
155 158
	 */
156 159
	public Grid(BufferFactory bufferFactory, boolean notInterp) {
160
		double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
161
				bufferFactory.getSourceHeight()); 
157 162
		this.layerExtent = new GridExtent(	bufferFactory.getDataSource().getExtent(), 
158
											calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth()));
163
											cellSize[0],
164
											cellSize[1]);
159 165
		if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
160 166
			dataType = bufferFactory.getDataSource().getDataType()[0];
161 167
		bands = bufferFactory.getDrawableBands();
162 168

  
163 169
		this.windowExtent = new GridExtent(	bufferFactory.getDataExtent(), 
164
											calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth()));
170
											cellSize[0],
171
											cellSize[1]);
165 172

  
166 173
		rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf();
167 174

  
......
187 194
	public Grid(BufferFactory bufferFactory, int[] bands)
188 195
			throws RasterBufferInvalidException{
189 196
		//La petici?n es del raster completo
197
		double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
198
				bufferFactory.getSourceHeight()); 
190 199
		windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(), 
191
													calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth()));
200
													cellSize[0],
201
													cellSize[1]);
192 202
		if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
193 203
			dataType = bufferFactory.getDataSource().getDataType()[0];
194 204
		this.bands = bands;
......
209 219
	 */
210 220
	public Grid(BufferFactory bufferFactory) throws RasterBufferInvalidException {
211 221
		//La petici?n es del raster completo
222
		double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
223
				bufferFactory.getSourceHeight()); 
212 224
		windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(), 
213
													calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth()));
225
													cellSize[0],
226
													cellSize[1]);
214 227
		if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
215 228
			dataType = bufferFactory.getDataSource().getDataType()[0];
216 229

  
......
225 238
	}
226 239
	
227 240
	/**
228
	 * Calcula el tama?o de celda a partir de un dataset y un ancho en pixeles
241
	 * Calcula el tama?o de celda a partir de un dataset, un ancho y un alto en pixeles
229 242
	 * @return
230 243
	 */
231
	private double calcCellSize(IRasterDataSource mDataset, double w) {
244
	private double[] calcCellSize(IRasterDataSource mDataset, double w, double h) {
245
		double dCellsize[] = new double[2];
232 246
		try {
233 247
			Extent e = mDataset.getExtent();
234
			double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / w;
248
			dCellsize[0] = (e.getMax().getX() - e.getMin().getX() ) / w;
249
			dCellsize[1] = (e.getMax().getY() - e.getMin().getY() ) / h;
250
			
235 251
			return dCellsize;
236 252
		} catch (NullPointerException e) {
237
			return 1;
253
			dCellsize[0] = 1;
254
			dCellsize[1] = 1;
255
			return dCellsize;
238 256
		}
239 257
	}
240 258

  

Also available in: Unified diff