Revision 20871
trunk/libraries/libRaster/src/org/gvsig/raster/grid/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 |
|
trunk/libraries/libRaster/src/org/gvsig/raster/grid/GridInterpolated.java | ||
---|---|---|
44 | 44 |
public static final int INTERPOLATION_BSpline = BufferInterpolation.INTERPOLATION_BSpline; |
45 | 45 |
|
46 | 46 |
double m_dXMin , m_dYMax; //coordinates of the layer, not the window |
47 |
double m_dCellSize; //cellsize of the layer, not the window |
|
47 |
double m_dCellSizeX; //cellsize of the layer, not the window |
|
48 |
double m_dCellSizeY; //cellsize of the layer, not the window |
|
48 | 49 |
int m_iInterpolationMethod = INTERPOLATION_BSpline; |
49 | 50 |
|
50 | 51 |
/** |
... | ... | |
63 | 64 |
m_dXMin = layerExtent.minX(); |
64 | 65 |
m_dYMax = layerExtent.maxY(); |
65 | 66 |
|
66 |
m_dCellSize = layerExtent.getCellSize(); |
|
67 |
m_dCellSizeX = layerExtent.getCellSizeX(); |
|
68 |
m_dCellSizeY = layerExtent.getCellSizeY(); |
|
67 | 69 |
} |
68 | 70 |
|
69 | 71 |
/** |
... | ... | |
89 | 91 |
m_dXMin = bufferFactory.getDataSource().getExtent().minX(); |
90 | 92 |
m_dYMax = bufferFactory.getDataSource().getExtent().maxY(); |
91 | 93 |
|
92 |
m_dCellSize = bufferFactory.getDataSource().getCellSize(); |
|
94 |
m_dCellSizeX = bufferFactory.getDataSource().getAffineTransform().getScaleX(); |
|
95 |
m_dCellSizeY = bufferFactory.getDataSource().getAffineTransform().getScaleY(); |
|
93 | 96 |
|
94 | 97 |
bufferFactory.setDrawableBands(bands); |
95 | 98 |
} |
... | ... | |
167 | 170 |
double dx, dy; |
168 | 171 |
double dValue; |
169 | 172 |
|
170 |
x = (int) Math.floor(xPosition = (xPosition - m_dXMin) / m_dCellSize); |
|
171 |
y = (int)Math.floor(yPosition = ( m_dYMax-yPosition) / m_dCellSize); |
|
173 |
x = (int) Math.floor(xPosition = (xPosition - m_dXMin) / m_dCellSizeX);
|
|
174 |
y = (int)Math.floor(yPosition = ( m_dYMax-yPosition) / m_dCellSizeY);
|
|
172 | 175 |
|
173 | 176 |
dValue = _getCellValueInLayerCoords(x,y); |
174 | 177 |
|
trunk/libraries/libRaster/src/org/gvsig/raster/grid/GridExtent.java | ||
---|---|---|
62 | 62 |
cellSizeY = dCellSize; |
63 | 63 |
recalculateNXAndNY(); |
64 | 64 |
} |
65 |
|
|
66 |
/** |
|
67 |
* Assign the extension value and cell size. |
|
68 |
* @param minX minimun value in X coordinate |
|
69 |
* @param minY minimun value in Y coordinate |
|
70 |
* @param maxX maximun value in X coordinate |
|
71 |
* @param maxY maximun value in Y coordinate |
|
72 |
* @param dCellSizeX cell size in X coordinate |
|
73 |
* @param dCellSizeX cell size in X coordinate |
|
74 |
*/ |
|
75 |
public GridExtent(double minX, double minY, double maxX, double maxY, double dCellSizeX, double dCellSizeY) { |
|
76 |
super(minX, minY, maxX, maxY); |
|
77 |
cellSizeX = dCellSizeX; |
|
78 |
cellSizeY = dCellSizeY; |
|
79 |
recalculateNXAndNY(); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Assign the extension value and cell size. |
|
84 |
* @param minX minimun value in X coordinate |
|
85 |
* @param minY minimun value in Y coordinate |
|
86 |
* @param maxX maximun value in X coordinate |
|
87 |
* @param maxY maximun value in Y coordinate |
|
88 |
* @param dCellSizeX cell size in X coordinate |
|
89 |
* @param dCellSizeX cell size in X coordinate |
|
90 |
*/ |
|
91 |
public GridExtent(Extent extent, double dCellSizeX, double dCellSizeY) { |
|
92 |
super(extent); |
|
93 |
cellSizeX = dCellSizeX; |
|
94 |
cellSizeY = dCellSizeY; |
|
95 |
recalculateNXAndNY(); |
|
96 |
} |
|
65 | 97 |
|
66 | 98 |
public void setXRange(double dXMin, double dXMax){ |
67 | 99 |
getMin().setLocation(Math.min(dXMin, dXMax), minY()); |
... | ... | |
129 | 161 |
double dOffsetCols; |
130 | 162 |
double dOffsetRows; |
131 | 163 |
|
132 |
if (extent.getCellSize() != this.getCellSize()){
|
|
164 |
if ((extent.getCellSizeX() != this.getCellSizeX())||(extent.getCellSizeY() != this.getCellSizeY())){
|
|
133 | 165 |
return false; |
134 | 166 |
} |
135 | 167 |
dOffset = Math.abs(extent.minX() - minX()); |
136 |
dOffsetCols = dOffset / getCellSize(); |
|
168 |
dOffsetCols = dOffset / getCellSizeX();
|
|
137 | 169 |
bFitsX = (dOffsetCols == Math.floor(dOffsetCols)); |
138 | 170 |
|
139 | 171 |
dOffset = Math.abs(extent.maxY() - maxY()); |
140 |
dOffsetRows = dOffset / getCellSize(); |
|
172 |
dOffsetRows = dOffset / getCellSizeY();
|
|
141 | 173 |
bFitsY = (dOffsetRows == Math.floor(dOffsetRows)); |
142 | 174 |
|
143 | 175 |
return bFitsX && bFitsY; |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/GridNotInterpolated.java | ||
---|---|---|
91 | 91 |
int iBufMinX, iBufMaxX, iBufMinY, iBufMaxY; |
92 | 92 |
|
93 | 93 |
iWindowMinX = (int) ((windowExtent.minX() - layerExtent.minX() ) |
94 |
/ windowExtent.getCellSize()); |
|
94 |
/ windowExtent.getCellSizeX());
|
|
95 | 95 |
iWindowMinY = (int) ((layerExtent.maxY() - windowExtent.maxY() ) |
96 |
/ windowExtent.getCellSize()); |
|
96 |
/ windowExtent.getCellSizeY());
|
|
97 | 97 |
|
98 | 98 |
dMinX = Math.min(Math.max(windowExtent.minX(), layerExtent.minX()), layerExtent.maxX()); |
99 | 99 |
dMinY = Math.min(Math.max(windowExtent.minY(), layerExtent.minY()), layerExtent.maxY()); |
100 | 100 |
dMaxX = Math.max(Math.min(windowExtent.maxX(), layerExtent.maxX()), layerExtent.minX()); |
101 | 101 |
dMaxY = Math.max(Math.min(windowExtent.maxY(), layerExtent.maxY()), layerExtent.minY()); |
102 | 102 |
|
103 |
iBufMinX = (int) Math.floor((dMinX - windowExtent.minX()) / windowExtent.getCellSize()) |
|
103 |
iBufMinX = (int) Math.floor((dMinX - windowExtent.minX()) / windowExtent.getCellSizeX())
|
|
104 | 104 |
+ iWindowMinX; |
105 |
iBufMinY = (int) Math.floor((windowExtent.maxY() - dMaxY) / windowExtent.getCellSize()) |
|
105 |
iBufMinY = (int) Math.floor((windowExtent.maxY() - dMaxY) / windowExtent.getCellSizeY())
|
|
106 | 106 |
+ iWindowMinY;; |
107 |
iBufMaxX = (int) Math.floor((dMaxX - windowExtent.minX()) / windowExtent.getCellSize()) |
|
107 |
iBufMaxX = (int) Math.floor((dMaxX - windowExtent.minX()) / windowExtent.getCellSizeX())
|
|
108 | 108 |
+ iWindowMinX; |
109 |
iBufMaxY = (int) Math.floor((windowExtent.maxY() - dMinY) / windowExtent.getCellSize()) |
|
109 |
iBufMaxY = (int) Math.floor((windowExtent.maxY() - dMinY) / windowExtent.getCellSizeY())
|
|
110 | 110 |
+ iWindowMinY; |
111 | 111 |
|
112 | 112 |
m_iOffsetX = iBufMinX - iWindowMinX; |
Also available in: Unified diff