Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / coordinates / LatLonBoxIterator.java @ 19680

History | View | Annotate | Download (4.83 KB)

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

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser;
6
import org.gvsig.gpe.kml.utils.KmlTags;
7
import org.gvsig.gpe.xml.stream.XmlStreamException;
8
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
9

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

    
109
                String tag = parser.getName();
110
                currentTag = parser.getEventType();
111

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

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

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

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