Revision 39504

View differences:

branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/struct/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();
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/struct/WMTSTileMatrixSetLink.java
36 36
	private WMTSTileMatrixSet tileMatrixSet                = null;
37 37
	private ArrayList         tileMatrixLimits             = null;
38 38
	protected boolean         forceLongitudeFirstAxisOrder = false;
39
	
39
	//protected WMTSBoundingBox layerBBox                    = null;
40 40
	/**
41 41
	 * Sets longitude first in the axis order read from the capabilities file
42 42
	 * @param force
......
98 98
		}
99 99
	}
100 100
	
101
	/*public void setLayerBBox(WMTSBoundingBox bbox) {
102
		if(tileMatrixSet != null)
103
			tileMatrixSet.setLayerBBox(layerBBox);
104
		this.layerBBox = bbox;
105
	}*/
106
	
101 107
	public void print() {
102 108
		System.out.println(" *****WMTSTileMatrixSetLink******");
103 109
		System.out.println("TileMatrixSet ID:" + getTileMatrixSetId());
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/struct/WMTSBoundingBox.java
96 96
				Math.abs(upperCorner[1] - lowerCorner[1]));
97 97
	}
98 98
	
99
	public boolean isValid() {
100
		return lowerCorner[0] != 0 || lowerCorner[1] != 0 || upperCorner[0] != 0 || upperCorner[1] != 0;
101
	}
102
	
99 103
	public void print() {
100 104
		System.out.println("*****WMTSBoundingBox******");
101 105
		System.out.println("LowerCorner:" + getLowerCorner()[0] + "," + getLowerCorner()[1]);
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/struct/WMTSTileMatrixSet.java
57 57
     */
58 58
	public abstract void parse(KXmlParser parser, ArrayList list) throws IOException, XmlPullParserException; 
59 59
    
60
	public void setLayerBBox(WMTSBoundingBox bbox) {
61
		if(bbox != null) {
62
			this.bbox = bbox;
63
			for (int i = 0; i < getTileMatrix().size(); i++) {
64
				((WMTSTileMatrix)getTileMatrix().get(i)).setBBoxTileMatrixSet(bbox.toRectangle2D());
65
			}
66
		}
67
	}
60 68
    
61 69
    public abstract WMTSBoundingBox getBoundingBox();
62 70
    
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/request/WMTSRequest.java
110 110
		String symbol = getSymbol(onlineResource);
111 111
		onlineResource = onlineResource + symbol;
112 112
		URL url = new URL(stringUtils.replaceAll(getHttpGetRequest(onlineResource), " ", "%20"));
113
		//System.out.println(url.toString());
113 114
		downloadFile(url, file, cancel);	
114 115
		
115 116
		//downloadFile(new URL(protocolHandler.getHost()), getHttpGetRequest(onlineResource), file, cancel);	
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/wmts_1_0_0/struct/WMTSTileMatrixSet_1_0_0.java
63 63
						setWellKnownScaleSet(nextText(parser));
64 64
					} else if (compareName(parser, CapabilitiesTags.WMTS_TILEMATRIX)) {
65 65
						WMTSTileMatrix tileMatrix = new WMTSTileMatrix_1_0_0();
66
						if(bbox != null)
67
							tileMatrix.setBBoxTileMatrixSet(bbox.toRectangle2D());
66 68
						tileMatrix.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder);
67 69
						tileMatrix.parse(parser, getTileMatrix()); 
68 70
					}

Also available in: Unified diff