Revision 39504 branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/struct/WMTSTileMatrix.java

View differences:

WMTSTileMatrix.java
38 38
 */
39 39
public abstract class WMTSTileMatrix extends WMTSBaseStruct {
40 40
    private double                  scaleDenominator             = 0;
41
    private Rectangle2D             bboxTileMatrixSet            = null;
41 42
    private double[]                topLeftCorner                = null;
42 43
    private int                     tileWidth                    = 0;
43 44
    private int                     tileHeight                   = 0;
......
45 46
    private long                    matrixHeight                 = 0;
46 47
    private static final double     MTS_X_GRADO                  = 111319.490793274;
47 48
    protected boolean               forceLongitudeFirstAxisOrder = false;
49
    private double                  epsilon                      = 1e-6;
48 50
	
49 51
	/**
50 52
	 * Sets longitude first in the axis order read from the capabilities file
......
53 55
	public void setForceLongitudeFirstAxisOrder(boolean force) {
54 56
		this.forceLongitudeFirstAxisOrder = force;
55 57
	}
58
	
59
	public void setBBoxTileMatrixSet(Rectangle2D bbox) {
60
		if(bboxTileMatrixSet == null)
61
			this.bboxTileMatrixSet = bbox;
62
	}
63
	
64
	public Rectangle2D getBBoxTileMatrixSet() {
65
		return bboxTileMatrixSet;
66
	}
56 67

  
57 68
    public class Tile {
58 69
    	public int       wPx, hPx;
......
157 168
    }
158 169
    
159 170
    /**
160
     * Gets the width in meters of a tile
161
     * @param projected
171
     * Gets the width in world coordinates of a tile
162 172
     * @return
163 173
     */
164
    public double getWidthMtsTile(boolean projected) {
174
    public double getWidthWCTile(boolean projected) {
175
    	double pixelSpan = 0;
165 176
    	if(!projected) {
166
    		return (scaleDenominator * tileWidth * 0.28) / (MTS_X_GRADO * 1000);
177
    		if(getBBoxTileMatrixSet() != null)
178
    			return getBBoxTileMatrixSet().getWidth() / matrixWidth;
179
    		else {
180
    			pixelSpan = (scaleDenominator * 0.00028) / MTS_X_GRADO;
181
    		}
167 182
    	} else {
168
    		return (scaleDenominator * tileWidth * 0.28) / 1000;
183
    		pixelSpan = scaleDenominator * 0.00028;
169 184
    	}
185
    	
186
    	double w = pixelSpan * tileWidth;
187
		if(((w - ((int)w)) > (1 - epsilon) || (w - ((int)w)) < epsilon))
188
			return Math.round(w);
189
		return w;
170 190
    }
171 191
    
172 192
    /**
173
     * Gets the height in meters of a tile
174
     * @param projected
193
     * Gets the height in world coordinates of a tile
175 194
     * @return
176 195
     */
177
    public double getHeightMtsTile(boolean projected) {
196
    public double getHeightWCTile(boolean projected) {
197
    	double pixelSpan = 0;
178 198
    	if(!projected) {
179
    		double coord = (scaleDenominator * tileHeight * 0.28) / (MTS_X_GRADO * 1000);
180
    		if(coord > 0.99 || coord < 0.005)
181
    			return Math.round(coord);
182
    		return coord;
199
    		if(getBBoxTileMatrixSet() != null)
200
    			return getBBoxTileMatrixSet().getHeight() / matrixHeight;
201
    		else {
202
    			pixelSpan = (scaleDenominator * 0.00028) / MTS_X_GRADO;
203
    		}
183 204
    	} else {
184
    		return (scaleDenominator * tileHeight * 0.28) / 1000;
205
    		pixelSpan = scaleDenominator * 0.00028;
185 206
    	}
207
    	
208
    	double h = pixelSpan * tileHeight;
209
		if(((h - ((int)h)) > (1 - epsilon) || (h - ((int)h)) < epsilon))
210
			return Math.round(h);
211
		return h;
186 212
    }
187 213
    
188 214
    /**
......
191 217
     * @deprecated this method was for grid subsets.   
192 218
     */
193 219
	public ArrayList intersects(boolean projected, WMTSTileMatrixLimits tileMatrixLimits, Rectangle2D request, Rectangle2D extentLayer) {
194
    	double widthMtsTile = getWidthMtsTile(projected);
195
    	double heightMtsTile = getHeightMtsTile(projected);
220
    	double widthMtsTile = getWidthWCTile(projected);
221
    	double heightMtsTile = getHeightWCTile(projected);
196 222

  
197 223
		double ulx, uly, lrx, lry;
198 224
    	ArrayList list = new ArrayList();
......
232 258
     * intersects then this will be added to the list.  
233 259
     */
234 260
	public ArrayList intersects(boolean projected, Rectangle2D request, Rectangle2D extentLayer) {
235
    	double widthMtsTile = getWidthMtsTile(projected);
236
    	double heightMtsTile = getHeightMtsTile(projected);
261
    	double widthWorldCoordTile = getWidthWCTile(projected);
262
    	double heightWorldCoordTile = getHeightWCTile(projected); 
237 263

  
238 264
		double ulx, uly, lrx, lry;
239 265
    	ArrayList list = new ArrayList();
......
246 272
    	double initX = topLeftCorner[1];
247 273
    	double initY = topLeftCorner[0];
248 274
    	
249
    	int tileInitX = (int)((request.getMinX() - initX) / widthMtsTile);
250
    	int tileInitY = (int)(Math.abs(request.getMaxY() - initY) / heightMtsTile);
251
    	int tileEndX = (int)((request.getMaxX() - initX) / widthMtsTile);
252
    	int tileEndY = (int)(Math.abs(request.getMinY() - initY) / heightMtsTile);
275
    	int tileInitX = (int)((request.getMinX() - initX) / widthWorldCoordTile);
276
    	int tileInitY = (int)(Math.abs(request.getMaxY() - initY) / heightWorldCoordTile);
277
    	int tileEndX = (int)((request.getMaxX() - initX) / widthWorldCoordTile);
278
    	int tileEndY = (int)(Math.abs(request.getMinY() - initY) / heightWorldCoordTile);
253 279
    	
254 280
    	for (int row = tileInitY; row <= tileEndY; row++) {
255
    		uly = initY - (heightMtsTile * row);
256
			lry = uly - heightMtsTile;
281
    		uly = initY - (heightWorldCoordTile * row);
282
			lry = uly - heightWorldCoordTile;
257 283
			for (int col = tileInitX; col <= tileEndX; col++) {
258
				ulx = initX + (widthMtsTile * col);
259
				lrx = ulx + widthMtsTile;
284
				ulx = initX + (widthWorldCoordTile * col);
285
				lrx = ulx + widthWorldCoordTile;
260 286
				r.setRect(Math.min(ulx, lrx), Math.min(uly, lry), Math.abs(ulx - lrx), Math.abs(uly - lry));
261 287
				//El segundo intersects es necesario porque el extent de la capa puede variar por cada nivel de 
262 288
				//resoluci?n en caso de que haya una lista de TileMatrix en el capabilities
......
292 318
     * intersects then this will be added to the list.  
293 319
     */
294 320
	public ArrayList contains(boolean projected, Point2D point, Rectangle2D extentLayer) {
295
		double widthMtsTile = getWidthMtsTile(projected);
296
    	double heightMtsTile = getHeightMtsTile(projected);
321
		double widthMtsTile = getWidthWCTile(projected); //getWidthMtsTile(projected);
322
    	double heightMtsTile = getHeightWCTile(projected); //getHeightMtsTile(projected);
297 323

  
298 324
		double ulx, uly, lrx, lry;
299 325
    	ArrayList list = new ArrayList();
......
332 358
     * intersects then this will be added to the list.  
333 359
     */
334 360
	public ArrayList contains(boolean projected, WMTSTileMatrixLimits tileMatrixLimits, Point2D point, Rectangle2D extentLayer) {
335
		double widthMtsTile = getWidthMtsTile(projected);
336
    	double heightMtsTile = getHeightMtsTile(projected);
361
		double widthMtsTile = getWidthWCTile(projected);
362
    	double heightMtsTile = getHeightWCTile(projected);
337 363

  
338 364
		double ulx, uly, lrx, lry;
339 365
    	ArrayList list = new ArrayList();

Also available in: Unified diff