Statistics
| Revision:

root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / coordinates / LatLonBoxIterator.java @ 37960

History | View | Annotate | Download (5.08 KB)

1
package org.gvsig.gpe.kml.parser.v21.coordinates;
2

    
3
import java.io.IOException;
4

    
5
import javax.xml.namespace.QName;
6

    
7
import org.gvsig.gpe.kml.parser.GPEDefaultKmlParser;
8
import org.gvsig.gpe.kml.utils.Kml2_1_Tags;
9
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
10
import org.gvsig.gpe.xml.stream.XmlStreamException;
11
import org.gvsig.gpe.xml.utils.CompareUtils;
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id:LatLonBoxBinding.java 357 2008-01-09 17:50:08Z jpiera $
56
 * $Log$
57
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
58
 * Refactoring of some package names
59
 *
60
 * Revision 1.1  2007/05/09 08:36:24  jorpiell
61
 * Add the bbox to the layer
62
 *
63
 *
64
 */
65
/**
66
 * This class parses a LatLonBox tag. Example:
67
 * <p>
68
 * <pre>
69
 * <code> 
70
 * &lt;LatLonAltBox&gt;
71
 * &lt;north&gt;43.374&lt;/north&gt;
72
 * &lt;south&gt;42.983&lt;/south&gt;
73
 * &lt;east&gt;-0.335&lt;/east&gt;
74
 * &lt;west&gt;-1.423&lt;/west&gt;
75
 * &lt;rotation&gt;39.37878630116985&lt;/rotation&gt;
76
 * &lt;/LatLonAltBox&gt;
77
 * </code>
78
 * </pre>
79
 * </p> 
80
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
81
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#latlonbox
82
 */
83
public class LatLonBoxIterator extends KmlCoordinatesIterator{
84
        double[] min = null;
85
        double[] max = null;
86
        int iterations = 0;
87
        
88
        /**
89
         * It parses the LatLonAltBox tag
90
         * @param parser
91
         * The XML parser
92
         * @param handler
93
         * The GPE parser that contains the content handler and
94
         * the error handler
95
         * @return
96
         * A Bounding box
97
         * @throws IOException 
98
         * @throws XmlStreamException 
99
         */
100
        public  Object parse(IXmlStreamReader parser,GPEDefaultKmlParser handler) throws XmlStreamException, IOException {
101
                boolean endFeature = false;
102
                int currentTag;
103
                Object bbox = null;
104
                min = new double[3];
105
                max = new double[3];
106
                double rotation;
107
                iterations = 0;
108
                dimension = 2;
109
                
110
                String id = handler.getProfile().getGeometryBinding().getID(parser, handler);
111

    
112
                QName tag = parser.getName();
113
                currentTag = parser.getEventType();
114

    
115
                while (!endFeature){
116
                        switch(currentTag){
117
                        case IXmlStreamReader.START_ELEMENT:
118
                                if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.NORTH)){
119
                                        parser.next();
120
                                        max[1] = handler.getProfile().getDoubleBinding().parse(parser.getText());
121
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.SOUTH)){
122
                                        parser.next();
123
                                        min[1] = handler.getProfile().getDoubleBinding().parse(parser.getText());
124
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.EAST)){
125
                                        parser.next();
126
                                        max[0] = handler.getProfile().getDoubleBinding().parse(parser.getText());
127
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.WEST)){
128
                                        parser.next();
129
                                        min[0] = handler.getProfile().getDoubleBinding().parse(parser.getText());
130
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.ROTATION)){
131
                                        parser.next();
132
                                        rotation = handler.getProfile().getDoubleBinding().parse(parser.getText());
133
                                }
134
                                break;
135
                        case IXmlStreamReader.END_ELEMENT:
136
                                if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.LATLONBOX)){                                                
137
                                        endFeature = true;
138
                                        bbox = handler.getContentHandler().startBbox(id, this, Kml2_1_Tags.DEFAULT_SRS);
139
                                        handler.getContentHandler().endBbox(bbox);
140
                                }
141
                                break;
142
                        case IXmlStreamReader.CHARACTERS:                                        
143

    
144
                                break;
145
                        }
146
                        if (!endFeature){                                        
147
                                currentTag = parser.next();
148
                                tag = parser.getName();
149
                        }
150
                }                        
151
                return bbox;        
152
        }
153

    
154
        /*
155
         * (non-Javadoc)
156
         * @see org.gvsig.gpe.parser.ICoordinateIterator#hasNext()
157
         */
158
        public boolean hasNext() throws IOException {
159
                if (iterations < 2){
160
                        return true;
161
                }
162
                return false;
163
        }
164

    
165
        /*
166
         * (non-Javadoc)
167
         * @see org.gvsig.gpe.parser.ICoordinateIterator#next(double[])
168
         */
169
        public void next(double[] buffer) throws IOException {
170
                if (iterations == 0){
171
                        for (int i=0 ; i<buffer.length ; i++){
172
                                buffer[i] = min[i];
173
                        }
174
                        iterations = 1;
175
                }
176
                if (iterations == 1){
177
                        for (int i=0 ; i<buffer.length ; i++){
178
                                buffer[i] = max[i];
179
                        }
180
                        iterations = 2;
181
                }
182
        }
183
}