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 / WMTSTileMatrixSetLinkImpl.java @ 2613

History | View | Annotate | Download (4.7 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.io.IOException;
25
import java.util.ArrayList;
26
import java.util.List;
27

    
28
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixLimits;
29
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSet;
30
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSetLink;
31
import org.kxml2.io.KXmlParser;
32
import org.xmlpull.v1.XmlPullParserException;
33

    
34
/**
35
 * Set of tiles
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public abstract class WMTSTileMatrixSetLinkImpl implements WMTSTileMatrixSetLink {
39
        private String                       tileMatrixSetId              = null;
40
        private WMTSTileMatrixSetImpl        tileMatrixSet                = null;
41
        private List<WMTSTileMatrixLimits>   tileMatrixLimits             = null;
42
        protected boolean                    forceChangeAxisOrder         = false;
43
        
44
        /**
45
         * Sets longitude first in the axis order read from the capabilities file
46
         * @param force
47
         */
48
        public void setForceChangeAxisOrder(boolean force) {
49
                this.forceChangeAxisOrder = force;
50
        }
51
        
52
    /**
53
     * Parses this service
54
     * @param parser
55
     * @param content
56
     * @throws IOException
57
     * @throws XmlPullParserException
58
     */
59
    public abstract void parse(KXmlParser parser) throws IOException, XmlPullParserException; 
60
    
61
        public String getTileMatrixSetId() {
62
                return tileMatrixSetId;
63
        }
64
        
65
        public void setTileMatrixSetId(String tileMatrixSetId) {
66
                this.tileMatrixSetId = tileMatrixSetId;
67
        }
68
        
69
        public WMTSTileMatrixSet getTileMatrixSet() {
70
                return tileMatrixSet;
71
        }
72
        
73
        public void setTileMatrixSet(WMTSTileMatrixSetImpl tileMatrixSet) {
74
                this.tileMatrixSet = tileMatrixSet;
75
        }
76
        
77
        public List<WMTSTileMatrixLimits> getTileMatrixLimits() {
78
                if(tileMatrixLimits == null)
79
                        tileMatrixLimits = new ArrayList<WMTSTileMatrixLimits>();
80
                return tileMatrixLimits;
81
        }
82
        
83
        /**
84
         * Links the TileMatrixLimits with the TileMatrix
85
         * @param tileMatrixSet
86
         */
87
        public void linkTileMatrix(WMTSTileMatrixSetImpl tileMatrixSet) {
88
                //Recorre la lista de TileMatrixLimits y asigna a cada uno el TileMatrix asociado 
89
                //definido en la etiqueta
90
                if(tileMatrixLimits == null)
91
                        return;
92
                java.util.List<String> idListToRemove = new ArrayList<String>();
93
                for (int i = 0; i < tileMatrixLimits.size(); i++) {
94
                        WMTSTileMatrixLimitsImpl limits = (WMTSTileMatrixLimitsImpl)tileMatrixLimits.get(i);
95
                        String id = limits.getRefToTileMatrix();
96
                        boolean isWithoutReference = true;
97
                        for (int j = 0; j < tileMatrixSet.getTileMatrix().size(); j++) {
98
                                WMTSTileMatrixImpl tileMatrix = (WMTSTileMatrixImpl)tileMatrixSet.getTileMatrix().get(j);
99
                                if(tileMatrix.getIdentifier().compareTo(id) == 0) {
100
                                        limits.setTileMatrix(tileMatrix);
101
                                        isWithoutReference = false;
102
                                        break;
103
                                }
104
                        }
105
                        if(isWithoutReference) {
106
                                idListToRemove.add(id);
107
                        }
108
                }
109
                removeLevelsFromTileMatrix(idListToRemove);
110
        }
111
        
112
        /**
113
         * Removes form the <code>WMTSTileMatrixLimits</code> the elements in the
114
         * ID list. These elements are <code>WMTSTileMatrix</code> without reference
115
         * @param idList 
116
         *        List of identifiers
117
         */
118
        private void removeLevelsFromTileMatrix(java.util.List<String> idList) {
119
                if(tileMatrixLimits == null || idList == null || idList.size() == 0)
120
                        return;
121
                for (int i = 0; i < idList.size(); i++) {
122
                        String id = idList.get(i);
123
                        for (int j = 0; j < tileMatrixLimits.size(); j++) {
124
                                WMTSTileMatrixLimitsImpl limits = (WMTSTileMatrixLimitsImpl)tileMatrixLimits.get(j);
125
                                if(id.equals(limits.getRefToTileMatrix())) {
126
                                        tileMatrixLimits.remove(j);
127
                                        break;
128
                                }
129
                        }
130
                }
131
        }
132
        
133
        
134
        public void print() {
135
                System.out.println(" *****WMTSTileMatrixSetLink******");
136
                System.out.println("TileMatrixSet ID:" + getTileMatrixSetId());
137
                for (int i = 0; i < getTileMatrixLimits().size(); i++) {
138
                        WMTSTileMatrixLimitsImpl limits = ((WMTSTileMatrixLimitsImpl)getTileMatrixLimits().get(i));
139
                        limits.print();
140
                }
141
        }
142
}