Revision 41242

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/wms/WMSLayer.java
66 66

  
67 67
    private ArrayList keywordList = new ArrayList();
68 68
    /**
69
     * <p>Layer srs.</p>
69
     * <p>CRS list of this layer (Tag CRS)</p>
70 70
     */
71 71
    protected Vector srs = new Vector();
72 72

  
73 73
    /**
74
     * <p>extents for each srs the layer can be reproyected to</p>
74
     * <p>Bounding box por CRS (Tag BoundingBox)</p>
75 75
     */
76 76
    private Hashtable bBoxes  = new Hashtable();
77 77

  
......
199 199
     * @param id
200 200
     */
201 201
    public BoundaryBox getBbox(String id) {
202
    	//Si hay una bounding box definida para esa capa y ese crs, se usa esa
203
    	BoundaryBox b = (BoundaryBox) bBoxes.get(id);
204
    	if(b != null)
205
    		return b;
206
    	
202 207
    	if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0)
203
    		||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
204
    	{
208
    		||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0)) {
205 209
    		if (latLonBbox != null)
206 210
    		return (BoundaryBox)latLonBbox;
207 211
    	}
208
        BoundaryBox b = (BoundaryBox) bBoxes.get(id);
209
        if (b == null && parent!=null)
212
        
213
        if (parent!=null)
210 214
            return parent.getBbox(id);
211
        return (BoundaryBox)bBoxes.get(id);
215
        return null;
212 216
    }
213 217

  
214 218
    /**
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/wms/WMSClient.java
227 227
    /**
228 228
     * Returns the max extent that envolves the requested layers
229 229
     * */
230
    public Rectangle2D getLayersExtent(String[]layerNames, String srs)
231
    {
232
        try
233
        {
234
        	if (layerNames == null) return null;
235
            BoundaryBox bbox;
230
    public Rectangle2D getLayersExtent(String[]layerNames, String srs) {
231
        try {
232
        	if (layerNames == null) {
233
        		return null;
234
        	}
235
        	
236
            BoundaryBox bbox = null;
236 237
            WMSLayer layer = getLayer(layerNames[0]);
237 238
            
238 239
            bbox = layer.getBbox(srs);
239
            if (bbox == null) return null;
240
            if (bbox == null) {
241
            	return null;
242
            }
240 243
            double xmin = bbox.getXmin();
241 244
            double xmax = bbox.getXmax();
242 245
            double ymin = bbox.getYmin();
243 246
            double ymax = bbox.getYmax();
244 247
            
245
            for(int i=1; i<layerNames.length; i++)
246
            {
248
            for(int i = 1; i < layerNames.length; i++) {
247 249
                layer = getLayer(layerNames[i]);
248 250
                bbox = layer.getBbox(srs);
249 251
                if (bbox == null) return null;
250
                if (bbox.getXmin() < xmin)
251
                {
252
                if (bbox.getXmin() < xmin) {
252 253
                    xmin = bbox.getXmin();
253 254
                }
254
                if (bbox.getYmin() < ymin)
255
                {
255
                if (bbox.getYmin() < ymin) {
256 256
                    ymin = bbox.getYmin();
257 257
                }
258
                if (bbox.getXmax() > xmax)
259
                {
258
                if (bbox.getXmax() > xmax) {
260 259
                    xmax = bbox.getXmax();
261 260
                }
262
                if (bbox.getYmax() > ymax)
263
                {
261
                if (bbox.getYmax() > ymax) {
264 262
                    ymax = bbox.getYmax();
265 263
                }
266 264
            }	
267 265
            
268
            Rectangle2D extent = new Rectangle2D.Double(xmin,ymin,Math.abs(xmax-xmin),Math.abs(ymax-ymin));
266
            Rectangle2D extent = new Rectangle2D.Double(xmin, ymin, Math.abs(xmax-xmin), Math.abs(ymax-ymin));
269 267
            return extent;
270
        }
271
        catch(Exception e)
272
        {
268
        } catch(Exception e) {
273 269
            e.printStackTrace();
274 270
            return null;
275 271
        }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/wms/wms_1_1_0/WMSProtocolHandler1_1_0.java
253 253
        return fakeRootLayer;
254 254
    }
255 255
    
256
    /* (non-Javadoc)
257
     * @see org.gvsig.remoteClient.wms.WMSProtocolHandler#parseException(byte[])
258
     */
259 256
    protected String parseException(byte[] data) {
260 257
        ArrayList errors = new ArrayList();
261 258
        KXmlParser kxmlParser = new KXmlParser();
......
304 301
        return message;
305 302
    }
306 303

  
307
    /*
308
     * (non-Javadoc)
309
     * @see org.gvsig.remoteClient.wms.WMSProtocolHandler#createGetFeatureInfoRequest(org.gvsig.remoteClient.wms.WMSStatus, int, int)
310
     */
311 304
	protected WMSGetFeatureInfoRequest createGetFeatureInfoRequest(
312 305
			WMSStatus status, int x, int y) {
313 306
		return new WMSGetFeatureInfoRequest1_1_0(status, this, x, y);
314 307
	}
315 308

  
316
	/*
317
	 * (non-Javadoc)
318
	 * @see org.gvsig.remoteClient.wms.WMSProtocolHandler#createGetMapRequest(org.gvsig.remoteClient.wms.WMSStatus)
319
	 */
320 309
	protected WMSGetMapRequest createGetMapRequest(WMSStatus status) {
321 310
		return new WMSGetMapRequest1_1_0(status, this);
322 311
	}
323 312

  
324
	/*
325
	 * (non-Javadoc)
326
	 * @see org.gvsig.remoteClient.wms.WMSProtocolHandler#createGetLegendGraphicRequest(org.gvsig.remoteClient.wms.WMSStatus, java.lang.String)
327
	 */
328 313
	protected WMSGetLegendGraphicRequest createGetLegendGraphicRequest(
329 314
			WMSStatus status, String layerName) {
330 315
		return new WMSGetLegendGraphicRequest1_1_0(status, this, layerName);
331 316
	}
332 317

  
333
	/* (non-Javadoc)
334
	 * @see org.gvsig.remoteclient.wms.WMSProtocolHandler#createGetCapabilitiesRequest(org.gvsig.remoteclient.wms.WMSStatus)
335
	 */	
336 318
	protected WMSGetCapabilitiesRequest createGetCapabilitiesRequest(
337 319
			WMSStatus status) {
338 320
		return new WMSGetCapabilitiesRequest1_1_0(status, this);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/wms/wms_1_3_0/WMSLayer1_3_0.java
28 28
import java.util.ArrayList;
29 29
import java.util.TreeMap;
30 30

  
31
import org.kxml2.io.KXmlParser;
32
import org.xmlpull.v1.XmlPullParserException;
33

  
31
import org.cresques.cts.IProjection;
34 32
import org.gvsig.compat.CompatLocator;
35 33
import org.gvsig.compat.lang.StringUtils;
34
import org.gvsig.fmap.crs.CRSFactory;
36 35
import org.gvsig.remoteclient.utils.BoundaryBox;
37 36
import org.gvsig.remoteclient.utils.CapabilitiesTags;
38 37
import org.gvsig.remoteclient.utils.Utilities;
39 38
import org.gvsig.remoteclient.wms.WMSDimension;
39
import org.kxml2.io.KXmlParser;
40
import org.xmlpull.v1.XmlPullParserException;
40 41

  
41 42

  
42 43
/**
......
47 48
    
48 49
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
49 50
    
50
    public ArrayList getDimensions()
51
    {   
51
    
52
    public ArrayList getDimensions() {   
52 53
        WMSDimension pDimension;
53 54
        WMSDimension myDimension;    
54 55
        ArrayList myDimensions = (ArrayList) this.dimensions.clone();        
55 56
        ArrayList pDimensions;
56 57
        
57
        if (parent!=null)
58
        {
58
        if (parent != null) {
59 59
        	pDimensions = parent.getDimensions();
60
        	for (int i= 0; i < pDimensions.size(); i++){
60
        	for (int i= 0; i < pDimensions.size(); i++) {
61 61
        		pDimension = (WMSDimension)pDimensions.get(i);
62 62
        		myDimension = getDimension(pDimension.getName());
63 63
        		if (myDimension != null){
......
69 69
        return myDimensions;
70 70
    }
71 71
    
72
    public WMSLayer1_3_0()
73
    {
72
    public WMSLayer1_3_0() {
74 73
        children = new ArrayList();
75 74
    }
76 75
    /**
......
78 77
     * to extract the information about an WMSLayer</p>
79 78
     * 
80 79
     */
81
    public void parse(KXmlParser parser, TreeMap layerTreeMap)
82
    throws IOException, XmlPullParserException
83
    {
80
    public void parse(KXmlParser parser, TreeMap layerTreeMap) throws IOException, XmlPullParserException {
84 81
        int currentTag;
85 82
        boolean end = false;
86 83
        String value;
......
91 88
        
92 89
        currentTag = parser.nextTag();
93 90
        
94
        while (!end) 
95
        {
96
            switch(currentTag)
97
            {
98
                case KXmlParser.START_TAG:
99
                    if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0)
100
                    {	
101
                        WMSLayer1_3_0 lyr = new WMSLayer1_3_0();						
102
                        //parser.next(); 
103
                        lyr.parse(parser, layerTreeMap);
104
                        lyr.setParent(this);
105
                        this.children.add(lyr);
106
                        // Jaume
107
                        if (lyr.getName()!=null)
108
                            layerTreeMap.put(lyr.getName(), lyr);
109
                    }
110
                    else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){
111
                        // TODO comprobar que esto se necesite o se deseche
112
                        parser.skipSubTree();
113
                    }
114
                    else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
115
                    {		
116
                        value = parser.nextText();
117
                        if (value != null) setName(value);						
118
                    }	
119
                    else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0)
120
                    {
121
                        value = parser.nextText();
122
                        if (value != null) setTitle(value);
123
                    }
124
                    else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
125
                    {
126
                        value = parser.nextText();
127
                        if (value != null) setAbstract(value);
128
                    }
129
                    else if (parser.getName().compareTo(CapabilitiesTags.CRS)==0)
130
                    {
131
                        value = parser.nextText();
132
                        if (value != null){
133
                            String[] mySRSs = stringUtils.split(value, " ");
134
                            for (int i = 0; i < mySRSs.length; i++) {
135
                                addSrs(mySRSs[i]);    
136
                            }                        
137
                        }
138
                    }					
139
                    else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0)
140
                    {
141
                        bbox = new BoundaryBox();
142
                        value = parser.getAttributeValue("",CapabilitiesTags.CRS);
143
                        if (value != null)
144
                            bbox.setSrs(value);
145
                        value = parser.getAttributeValue("",CapabilitiesTags.MINX);
146
                        if ((value != null) && (Utilities.isNumber(value)))
147
                            bbox.setXmin(Double.parseDouble(value));	
148
                        value = parser.getAttributeValue("",CapabilitiesTags.MINY);
149
                        if ((value != null) && (Utilities.isNumber(value)))
150
                            bbox.setYmin(Double.parseDouble(value));	
151
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
152
                        if ((value != null) && (Utilities.isNumber(value)))
153
                            bbox.setXmax(Double.parseDouble(value));	
154
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
155
                        if ((value != null) && (Utilities.isNumber(value)))
156
                            bbox.setYmax(Double.parseDouble(value));	
157
                        
158
                        //X and Y spatial resolution in the units if that CRS.
159
                        //value = parser.getAttributeValue("",CapabilitiesTags.RESX);
160
                        //if ((value != null) && (Utilities.isNumber(value)))
161
                            //bbox.setYmax(Double.parseDouble(value));
162
                        //value = parser.getAttributeValue("",CapabilitiesTags.RESY);
163
                        //if ((value != null) && (Utilities.isNumber(value)))
164
                            //bbox.setYmax(Double.parseDouble(value));
165
                        
166
                        addBBox(bbox);
167
                        addSrs(bbox.getSrs());
168
                    }	
169
                    else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX)==0)
170
                    {
171
                    	//minimum bounding rectangle in decimal degrees of the area covered by the layer.
172
                        bbox = parseEXGeographicBBTag(parser);	
173
                        addBBox(bbox);
174
                        setLatLonBox(bbox);
175
                        addSrs(bbox.getSrs());
176
                    }						
177
                    else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0)
178
                    {
179
                        value = parser.getAttributeValue("",CapabilitiesTags.MIN);
180
                        if ((value != null) && (Utilities.isNumber(value)))
181
                            setScaleMin(Double.parseDouble(value));
182
                        value = parser.getAttributeValue("",CapabilitiesTags.MAX);
183
                        if ((value != null) && (Utilities.isNumber(value)))
184
                            setScaleMax(Double.parseDouble(value));																	
185
                    }						
186
                    else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0)
187
                    {
188
                        WMSStyle1_3_0 style = new WMSStyle1_3_0();
189
                        style.parse(parser);
190
                        if ((style != null) && (style.getName() != null))
191
                        {
192
                            styles.add(style);
193
                        }
194
                    }
195
                    else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0)
196
                    {
197
                        WMSDimension dim = new WMSDimension();
198
                        dim.parse(parser);
199
                        if ((dim != null) && (dim.getName() != null))
200
                        {
201
                            addDimension(dim);
202
                            
203
                        }
204
                    }                
205
                    else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0)
206
                    {
207
                    	parseKeywordList(parser);
208
                    }                     
209
                    break;
210
                case KXmlParser.END_TAG:
211
                    if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0)
212
                        end = true;
213
                    break;
214
                case KXmlParser.TEXT:					
215
                    break;
216
            }
217
            if (!end)
218
            	currentTag = parser.next();
91
        while (!end) {
92
        	switch(currentTag) {
93
        	case KXmlParser.START_TAG:
94
        		if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) {	
95
        			WMSLayer1_3_0 lyr = new WMSLayer1_3_0();						
96
        			//parser.next(); 
97
        			lyr.parse(parser, layerTreeMap);
98
        			lyr.setParent(this);
99
        			this.children.add(lyr);
100
        			// Jaume
101
        			if (lyr.getName()!=null)
102
        				layerTreeMap.put(lyr.getName(), lyr);
103
        		} else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION) == 0) {
104
        			// TODO comprobar que esto se necesite o se deseche
105
        			parser.skipSubTree();
106
        		} else if (parser.getName().compareTo(CapabilitiesTags.NAME) == 0) {		
107
        			value = parser.nextText();
108
        			if (value != null) setName(value);						
109
        		} else if (parser.getName().compareTo(CapabilitiesTags.TITLE) == 0) {
110
        			value = parser.nextText();
111
        			if (value != null) setTitle(value);
112
        		} else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT) == 0) {
113
        			value = parser.nextText();
114
        			if (value != null) setAbstract(value);
115
        		} else if (parser.getName().compareTo(CapabilitiesTags.CRS) == 0) {
116
        			value = parser.nextText();
117
        			if (value != null) {
118
        				String[] mySRSs = stringUtils.split(value, " ");
119
        				for (int i = 0; i < mySRSs.length; i++) {
120
        					addSrs(mySRSs[i]);    
121
        				}                        
122
        			}
123
        		} else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX) == 0) {
124
        			bbox = new BoundaryBox();
125
        			value = parser.getAttributeValue("",CapabilitiesTags.CRS);
126
        			if (value != null)
127
        				bbox.setSrs(value);
128
        			value = parser.getAttributeValue("",CapabilitiesTags.MINX);
129
        			if ((value != null) && (Utilities.isNumber(value)))
130
        				bbox.setXmin(Double.parseDouble(value));	
131
        			value = parser.getAttributeValue("",CapabilitiesTags.MINY);
132
        			if ((value != null) && (Utilities.isNumber(value)))
133
        				bbox.setYmin(Double.parseDouble(value));	
134
        			value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
135
        			if ((value != null) && (Utilities.isNumber(value)))
136
        				bbox.setXmax(Double.parseDouble(value));	
137
        			value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
138
        			if ((value != null) && (Utilities.isNumber(value)))
139
        				bbox.setYmax(Double.parseDouble(value));	
140

  
141
        			bbox = changeAxis(bbox.getSrs(), bbox);
142
        			addBBox(bbox);
143
        			addSrs(bbox.getSrs());
144
        		} else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX) == 0) {
145
        			//minimum bounding rectangle in decimal degrees of the area covered by the layer.
146
        			bbox = parseEXGeographicBBTag(parser);	
147
        			addBBox(bbox);
148
        			setLatLonBox(bbox);
149
        			addSrs(bbox.getSrs());
150
        		} else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT) == 0) {
151
        			value = parser.getAttributeValue("",CapabilitiesTags.MIN);
152
        			if ((value != null) && (Utilities.isNumber(value)))
153
        				setScaleMin(Double.parseDouble(value));
154
        			value = parser.getAttributeValue("",CapabilitiesTags.MAX);
155
        			if ((value != null) && (Utilities.isNumber(value)))
156
        				setScaleMax(Double.parseDouble(value));																	
157
        		} else if (parser.getName().compareTo(CapabilitiesTags.STYLE) == 0) {
158
        			WMSStyle1_3_0 style = new WMSStyle1_3_0();
159
        			style.parse(parser);
160
        			if ((style != null) && (style.getName() != null)) {
161
        				styles.add(style);
162
        			}
163
        		} else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION) == 0) {
164
        			WMSDimension dim = new WMSDimension();
165
        			dim.parse(parser);
166
        			if ((dim != null) && (dim.getName() != null)) {
167
        				addDimension(dim);
168

  
169
        			}
170
        		} else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0) {
171
        			parseKeywordList(parser);
172
        		}                     
173
        		break;
174
        	case KXmlParser.END_TAG:
175
        		if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0)
176
        			end = true;
177
        		break;
178
        	case KXmlParser.TEXT:					
179
        		break;
180
        	}
181
        	if (!end)
182
        		currentTag = parser.next();
219 183
        }
220 184
        parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
221
    }      
185
    }     
186
    
187
    /**
188
     * Protocol 1.3 needs change axis in some cases.
189
     * If coordinates are read from the tag BoundingBox (where the bounding box is
190
     * defined for each specific CRS) then the axis needs to change its axis order in 
191
     * geographic projections. If coordinates are read from EX_GeographicBoundingBox 
192
     * then the axis are in right position.
193
     * 
194
     * There is to take into account that the request will have to change the axis order again
195
     * in cases which those had been changed.
196
     */
197
    private BoundaryBox changeAxis(String epsg, BoundaryBox oldbbox) {
198
    	if(epsg.contains("CRS:84") || epsg.contains("CRS84"))
199
    		return oldbbox;
200
        IProjection projSrc = CRSFactory.getCRS(epsg);
201
        if(projSrc != null && !projSrc.isProjected()) {
202
        	BoundaryBox bbox = new BoundaryBox();
203
        	bbox.setXmin(oldbbox.getYmin());	
204
            bbox.setYmin(oldbbox.getXmin());	
205
            bbox.setXmax(oldbbox.getYmax());	
206
            bbox.setYmax(oldbbox.getXmax());
207
            bbox.setSrs(oldbbox.getSrs());
208
            return bbox;
209
        }
210
        return oldbbox;
211
    }
222 212
  
223 213
    
224 214
    /**
225 215
     * <p>Parses the EX_GeographicBoundingBox </p>
226 216
     */    
227
    private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException 
228
    {
217
    private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException {
229 218
    	int currentTag;
230 219
    	boolean end = false;
231 220
    	BoundaryBox bbox = new BoundaryBox ();
......
234 223
    	parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
235 224
    	currentTag = parser.next();
236 225
    	
237
    	while (!end) 
238
    	{
239
			 switch(currentTag)
240
			 {
226
    	while (!end) {
227
			 switch(currentTag) {
241 228
				case KXmlParser.START_TAG:
242
					if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE)==0)
243
					{
229
					if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE) == 0) {
244 230
						value = parser.nextText();	                       
245 231
	                    if ((value != null) && (Utilities.isNumber(value)))
246 232
	                    	bbox.setXmin(Double.parseDouble(value));
247
					}	
248
					else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE)==0)
249
					{
233
					} else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE) == 0) {
250 234
						value = parser.nextText();	                       
251 235
	                    if ((value != null) && (Utilities.isNumber(value)))
252 236
	                    	bbox.setXmax(Double.parseDouble(value));
253
					}
254
					else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE)==0)
255
					{
237
					} else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE) == 0) {
256 238
						value = parser.nextText();	                       
257 239
	                    if ((value != null) && (Utilities.isNumber(value)))
258 240
	                    	bbox.setYmax(Double.parseDouble(value));
259
					}
260
					else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE)==0)
261
					{
241
					} else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE) == 0) {
262 242
						value = parser.nextText();	                       
263 243
	                    if ((value != null) && (Utilities.isNumber(value)))
264 244
	                    	bbox.setYmin(Double.parseDouble(value));
......
281 261
    	return bbox;
282 262
    }
283 263
    
284
    public String toString(){
264
    public String toString() {
285 265
        return super.toString();
286 266
    }
287 267
}

Also available in: Unified diff