Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.remoteclient / src / main / java / org / gvsig / remoteclient / wms / wms_1_3_0 / WMSLayer1_3_0.java @ 3325

History | View | Annotate | Download (9.58 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.remoteclient.wms.wms_1_3_0;
26

    
27
import java.io.IOException;
28
import java.util.ArrayList;
29
import java.util.TreeMap;
30

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

    
43

    
44
/**
45
 * <p>WMS Layer for WMS 1.3.0</p>
46
 * 
47
 */
48
public class WMSLayer1_3_0 extends org.gvsig.remoteclient.wms.WMSLayer {
49
    
50
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
51
    
52
    
53
    public ArrayList getDimensions() {   
54
        WMSDimension pDimension;
55
        WMSDimension myDimension;    
56
        ArrayList myDimensions = (ArrayList) this.dimensions.clone();        
57
        ArrayList pDimensions;
58
        
59
        if (parent != null) {
60
                pDimensions = parent.getDimensions();
61
                for (int i= 0; i < pDimensions.size(); i++) {
62
                        pDimension = (WMSDimension)pDimensions.get(i);
63
                        myDimension = getDimension(pDimension.getName());
64
                        if (myDimension != null){
65
                                pDimensions.remove(pDimension);
66
                        }
67
                }
68
                myDimensions.addAll(pDimensions);
69
        }
70
        return myDimensions;
71
    }
72
    
73
    public WMSLayer1_3_0() {
74
        children = new ArrayList();
75
    }
76
    /**
77
     * <p>Parses the contents of the parser(WMSCapabilities)
78
     * to extract the information about an WMSLayer</p>
79
     * 
80
     */
81
    public void parse(KXmlParser parser, TreeMap layerTreeMap) throws IOException, XmlPullParserException {
82
        int currentTag;
83
        boolean end = false;
84
        String value;
85
        BoundaryBox bbox;
86
        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LAYER);
87
        
88
        readLayerAttributes( parser );
89
        
90
        currentTag = parser.nextTag();
91
        
92
        while (!end) {
93
                switch(currentTag) {
94
                case KXmlParser.START_TAG:
95
                        if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) {        
96
                                WMSLayer1_3_0 lyr = new WMSLayer1_3_0();                                                
97
                                //parser.next(); 
98
                                lyr.parse(parser, layerTreeMap);
99
                                lyr.setParent(this);
100
                                this.children.add(lyr);
101
                                // Jaume
102
                                if (lyr.getName()!=null)
103
                                        layerTreeMap.put(lyr.getName(), lyr);
104
                        } else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION) == 0) {
105
                                // TODO comprobar que esto se necesite o se deseche
106
                                parser.skipSubTree();
107
                        } else if (parser.getName().compareTo(CapabilitiesTags.NAME) == 0) {                
108
                                value = parser.nextText();
109
                                if (value != null) setName(value);                                                
110
                        } else if (parser.getName().compareTo(CapabilitiesTags.TITLE) == 0) {
111
                                value = parser.nextText();
112
                                if (value != null) setTitle(value);
113
                        } else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT) == 0) {
114
                                value = parser.nextText();
115
                                if (value != null) setAbstract(value);
116
                        } else if (parser.getName().compareTo(CapabilitiesTags.CRS) == 0) {
117
                                value = parser.nextText();
118
                                if (value != null) {
119
                                        String[] mySRSs = stringUtils.split(value, " ");
120
                                        for (int i = 0; i < mySRSs.length; i++) {
121
                                                addSrs(mySRSs[i]);    
122
                                        }                        
123
                                }
124
                        } else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX) == 0) {
125
                                bbox = new BoundaryBox();
126
                                value = parser.getAttributeValue("",CapabilitiesTags.CRS);
127
                                if (value != null)
128
                                        bbox.setSrs(value);
129
                                value = parser.getAttributeValue("",CapabilitiesTags.MINX);
130
                                if ((value != null) && (Utilities.isNumber(value)))
131
                                        bbox.setXmin(Double.parseDouble(value));        
132
                                value = parser.getAttributeValue("",CapabilitiesTags.MINY);
133
                                if ((value != null) && (Utilities.isNumber(value)))
134
                                        bbox.setYmin(Double.parseDouble(value));        
135
                                value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
136
                                if ((value != null) && (Utilities.isNumber(value)))
137
                                        bbox.setXmax(Double.parseDouble(value));        
138
                                value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
139
                                if ((value != null) && (Utilities.isNumber(value)))
140
                                        bbox.setYmax(Double.parseDouble(value));        
141

    
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();
183
        }
184
        parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
185
    }     
186
    
187
    /**
188
     * <p>Parses the EX_GeographicBoundingBox </p>
189
     */    
190
    private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException {
191
            int currentTag;
192
            boolean end = false;
193
            BoundaryBox bbox = new BoundaryBox ();
194
            String value;
195
            
196
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
197
            currentTag = parser.next();
198
            
199
            while (!end) {
200
                         switch(currentTag) {
201
                                case KXmlParser.START_TAG:
202
                                        if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE) == 0) {
203
                                                value = parser.nextText();                               
204
                            if ((value != null) && (Utilities.isNumber(value)))
205
                                    bbox.setXmin(Double.parseDouble(value));
206
                                        } else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE) == 0) {
207
                                                value = parser.nextText();                               
208
                            if ((value != null) && (Utilities.isNumber(value)))
209
                                    bbox.setXmax(Double.parseDouble(value));
210
                                        } else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE) == 0) {
211
                                                value = parser.nextText();                               
212
                            if ((value != null) && (Utilities.isNumber(value)))
213
                                    bbox.setYmax(Double.parseDouble(value));
214
                                        } else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE) == 0) {
215
                                                value = parser.nextText();                               
216
                            if ((value != null) && (Utilities.isNumber(value)))
217
                                    bbox.setYmin(Double.parseDouble(value));
218
                                        }                                        
219
                                        break;
220
                                case KXmlParser.END_TAG:
221
                                        if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX) == 0)
222
                                                end = true;
223
                                        break;
224
                                case KXmlParser.TEXT:                                        
225
                                        break;
226
                         }
227
             if (!end)
228
                 currentTag = parser.next();
229
            }            
230
            parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
231
            // it is important to set CRS:84 instead of EPSG:4326 to ensure the bbox axis order is
232
            // correctly understood by the protocol handler
233
            bbox.setSrs("CRS:84");
234
            return bbox;
235
    }
236
    
237
    public String toString() {
238
        return super.toString();
239
    }
240
}