Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.ogc / org.gvsig.raster.wmts.ogc.impl / src / main / java / org / gvsig / raster / wmts / ogc / impl / struct / WMTSLayerImpl.java @ 2613

History | View | Annotate | Download (9.07 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22
package org.gvsig.raster.wmts.ogc.impl.struct;
23

    
24
import java.awt.geom.Rectangle2D;
25
import java.util.ArrayList;
26
import java.util.List;
27

    
28
import org.cresques.cts.ICoordTrans;
29
import org.cresques.cts.IProjection;
30
import org.gvsig.fmap.crs.CRSFactory;
31
import org.gvsig.raster.wmts.ogc.WMTSStatus;
32
import org.gvsig.raster.wmts.ogc.impl.base.WMTSServerDescription;
33
import org.gvsig.raster.wmts.ogc.struct.WMTSBoundingBox;
34
import org.gvsig.raster.wmts.ogc.struct.WMTSDimension;
35
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer;
36
import org.gvsig.raster.wmts.ogc.struct.WMTSResourceURL;
37
import org.gvsig.raster.wmts.ogc.struct.WMTSStyle;
38
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrix;
39
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixLimits;
40
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSet;
41
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSetLink;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

    
45
/**
46
 * Describes the attributes of a layer in a WMTS server
47
 *
48
 * @author Nacho Brodin (nachobrodin@gmail.com)
49
 */
50
public abstract class WMTSLayerImpl extends WMTSBaseStruct implements WMTSLayer {
51
        protected WMTSBoundingBox           wgs84bbox                    = null;
52
        protected WMTSBoundingBox           bbox                         = null;
53
        private List<WMTSStyle>             style                        = null;
54
        private List<String>                imageFormat                  = null;
55
        private List<String>                infoFormat                   = null;
56
        private List<String>                keywords                     = null;
57
        private List<WMTSDimension>         dimension                    = null;
58
        private String                      metadata                     = null;
59
        private List<WMTSTileMatrixSetLink> tileMatrixSetLinkList        = null;
60
        private List<WMTSResourceURL>       resourceURL                  = null;
61
        protected WMTSServerDescription     status                       = null;
62
        private Logger                      log                          = LoggerFactory.getLogger(WMTSLayerImpl.class);
63
        protected boolean                   forceChangeAxisOrder         = false;
64
        
65
        /**
66
         * Sets longitude first in the axis order read from the capabilities file
67
         * @param force
68
         */
69
        public void setForceChangeAxisOrder(boolean force) {
70
                this.forceChangeAxisOrder = force;
71
        }
72
        
73
        public WMTSLayerImpl(WMTSServerDescription status) {
74
                this.status = status;
75
        }
76
        
77
        public String getMetadata() {
78
                return metadata;
79
        }
80
        
81
        public void setMetadata(String metadata) {
82
                this.metadata = metadata;
83
        }
84
        
85
        public List<String> getFormat() {
86
                if(imageFormat == null)
87
                        imageFormat = new ArrayList<String>();
88
                return imageFormat;
89
        }
90
        
91
        public List<String> getInfoFormat() {
92
                if(infoFormat == null)
93
                        infoFormat = new ArrayList<String>();
94
                return infoFormat;
95
        }
96
        
97
        public List<String> getKeywords() {
98
                return keywords;
99
        }
100
        
101
        public void setKeywords(List<String> k) {
102
                this.keywords = k;
103
        }
104
        
105
        public WMTSBoundingBox getWGS84BBox() {
106
                return wgs84bbox;
107
        }
108
        
109
        public Rectangle2D getWGS84BBoxTransformed(String epsg) {
110
                IProjection projSrc = CRSFactory.getCRS("EPSG:4326");
111
                try {
112
                        IProjection projDst = CRSFactory.getCRS(epsg);
113
                        if(projDst != null) {
114
                                try {
115
                                        ICoordTrans t = projSrc.getCT(projDst);
116
                                        return t.convert(wgs84bbox.toRectangle2D());
117
                                } catch (Exception e) {
118
                                        log.info("I cannot get the transformation between EPSG:4326 and " + epsg, e);
119
                                }
120
                        }
121
                } catch (Exception e1) {
122
                        log.info("I cannot get " + epsg, e1);
123
                }
124
                return null;
125
        }
126
        
127
        public WMTSBoundingBox getBBox() {
128
                return bbox;
129
        }
130
        
131
        public void setWGS84BBox(WMTSBoundingBox wgs84bbox) {
132
                this.wgs84bbox = wgs84bbox;
133
        }
134
        
135
        public void setBBox(WMTSBoundingBox bbox) {
136
                this.bbox = bbox;
137
        }
138
        
139
        public List<WMTSResourceURL> getResourceURL() {
140
                if(resourceURL == null)
141
                        resourceURL = new ArrayList<WMTSResourceURL>();//resourceURL = (WMTSResourceURL)status.createVersionObject("WMTSResourceURL");
142
                return resourceURL;
143
        }
144

    
145
        public List<WMTSDimension> getDimensions() {
146
                if(dimension == null)
147
                        dimension = new ArrayList<WMTSDimension>(); //(WMTSDimension)status.createVersionObject("WMTSDimension");
148
                return dimension;
149
        }
150

    
151
        public List<WMTSStyle> getStyle() {
152
                if(style == null)
153
                        style = new ArrayList<WMTSStyle>();//(WMTSStyle)status.createVersionObject("WMTSStyle");
154
                return style;
155
        }
156

    
157
        public List<WMTSTileMatrixSetLink> getTileMatrixSetLink() {
158
                if(tileMatrixSetLinkList == null)
159
                        tileMatrixSetLinkList = new ArrayList<WMTSTileMatrixSetLink>();
160
                return tileMatrixSetLinkList;
161
        }
162
        
163
        /**
164
         * Returns the initial level of this layer inside the matrix set. 
165
         * @return
166
         */
167
        public int getInitialLevel(String tileMatrixSetId) {
168
                int initialLevel = 0;
169
                for (int i = 0; i < tileMatrixSetLinkList.size(); i++) {
170
                        WMTSTileMatrixSetLinkImpl tileMatrixSetLink = (WMTSTileMatrixSetLinkImpl)tileMatrixSetLinkList.get(i);
171
                        String id = tileMatrixSetLink.getTileMatrixSetId();
172
                        if(tileMatrixSetId.compareTo(id) == 0) {
173
                                List<WMTSTileMatrixLimits> tileMatrixLimits = tileMatrixSetLink.getTileMatrixLimits();
174
                                if(tileMatrixLimits != null && tileMatrixLimits.size() > 0) {
175
                                        String ref = ((WMTSTileMatrixLimitsImpl)tileMatrixLimits.get(0)).getRefToTileMatrix();
176
                                        List<WMTSTileMatrix> tileMatrixList = ((WMTSTileMatrixSetImpl)tileMatrixSetLink.getTileMatrixSet()).getTileMatrix();
177
                                        for (int j = 0; j < tileMatrixList.size(); j++) {
178
                                                String idTileMatrix = ((WMTSTileMatrixImpl)tileMatrixList.get(j)).getIdentifier();
179
                                                if(idTileMatrix.compareTo(ref) == 0)
180
                                                        return initialLevel;
181
                                                initialLevel ++;
182
                                        }
183
                                }
184
                        }
185
                }
186
                return initialLevel;
187
        }
188
        
189
        /**
190
         * Links the TileMatrixSet with the limits inside the layer structure
191
         * @param tileMatrixSetList
192
         */
193
        public void linkTileMatrixSets(List<WMTSTileMatrixSet> tileMatrixSetList) {
194
                //Recorre la lista de TileMatrixSetLink y a cada uno le asigna su TileMatrixSet
195
                //Para cada TileMatrixLimits contenido en el TileMatrixSetLimits asociado le asigna
196
                //el objeto TileMatrix a partir de su referencia.
197
                if(tileMatrixSetLinkList == null)
198
                        return;
199
                for (int i = 0; i < tileMatrixSetLinkList.size(); i++) {
200
                        WMTSTileMatrixSetLinkImpl tileMatrixSetLink = (WMTSTileMatrixSetLinkImpl)tileMatrixSetLinkList.get(i);
201
                        String id = tileMatrixSetLink.getTileMatrixSetId();
202
                        for (int j = 0; j < tileMatrixSetList.size(); j++) {
203
                                WMTSTileMatrixSetImpl tileMatrixSet = (WMTSTileMatrixSetImpl)tileMatrixSetList.get(j);
204
                                if(tileMatrixSet.getIdentifier().compareTo(id) == 0) {
205
                                        tileMatrixSetLink.setTileMatrixSet(tileMatrixSet);
206
                                        tileMatrixSetLink.linkTileMatrix(tileMatrixSet);
207
                                        break;
208
                                }
209
                        }
210
                }
211
        }
212
        
213
        /**
214
         * Gets the list of srs's supported
215
         * @return
216
         */
217
        public List<String> getSrsList() {
218
                List<String> list = new ArrayList<String>();
219
                for (int i = 0; i < tileMatrixSetLinkList.size(); i++) {
220
                        WMTSTileMatrixSetLinkImpl link = (WMTSTileMatrixSetLinkImpl)tileMatrixSetLinkList.get(i);
221
                        WMTSTileMatrixSetImpl tileMatrixSet = (WMTSTileMatrixSetImpl)link.getTileMatrixSet();
222
                        list.add(tileMatrixSet.getSupportedCRS());
223
                }
224
                return list;
225
        }
226
        
227
        /**
228
         * Builds the list of URL whether the capabilities file uses templates.
229
         */
230
        public void buildResourceURLListFromTemplate(WMTSStatus status) {
231
                TemplateSupport templateSupport = new TemplateSupport(getDimensions(), getResourceURL());
232
                templateSupport.buildResourceURLListFromTemplate(status);
233
        }
234
        
235
        public void print() {
236
                System.out.println("*****WMTSLayer******");
237
                System.out.println("Abstract:" + getAbstract());
238
                System.out.println("Identifier:" + getIdentifier());
239
                System.out.println("Keywords:");
240
                for (int i = 0; i < keywords.size(); i++) {
241
                        System.out.println("Keyword:" + keywords.get(i));
242
                }
243
                System.out.println("Title:" + getTitle());
244
                for (int i = 0; i < getFormat().size(); i++) {
245
                        System.out.println("Format:" + getFormat().get(i));
246
                }
247
                for (int i = 0; i < getInfoFormat().size(); i++) {
248
                        System.out.println("InfoFormat:" + getInfoFormat().get(i));
249
                }
250
                ((WMTSBoundingBoxImpl)getBBox()).print();
251
                ((WMTSBoundingBoxImpl)getWGS84BBox()).print();
252
                for (int i = 0; i < getDimensions().size(); i++) {
253
                        ((WMTSDimensionImpl)getDimensions().get(i)).print();                        
254
                }
255
                System.out.println("Metadata:" + getMetadata());
256
                for (int i = 0; i < getTileMatrixSetLink().size(); i++) {
257
                        ((WMTSTileMatrixSetLinkImpl)getTileMatrixSetLink().get(i)).print();
258
                }
259
        }
260

    
261
}