svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / coordinates / LatLonAltBoxIterator.java @ 19680
History | View | Annotate | Download (5.04 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:LatLonAltBoxBinding.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 LatLonAltBox tag. Example:
|
64 |
* <p>
|
65 |
* <pre>
|
66 |
* <code>
|
67 |
* <LatLonAltBox>
|
68 |
* <north>43.374</north>
|
69 |
* <south>42.983</south>
|
70 |
* <east>-0.335</east>
|
71 |
* <west>-1.423</west>
|
72 |
* <minAltitude>0</minAltitude>
|
73 |
* <maxAltitude>0</maxAltitude>
|
74 |
* </LatLonAltBox>
|
75 |
* </code>
|
76 |
* </pre>
|
77 |
* </p>
|
78 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
79 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#latlonaltbox
|
80 |
*/
|
81 |
public class LatLonAltBoxIterator extends KmlCoodinatesIterator{ |
82 |
double[] min = null; |
83 |
double[] max = null; |
84 |
int iterations = 0; |
85 |
|
86 |
/**
|
87 |
* It parses the LatLonAltBox tag
|
88 |
* @param parser
|
89 |
* The XML parser
|
90 |
* @param handler
|
91 |
* The GPE parser that contains the content handler and
|
92 |
* the error handler
|
93 |
* @return
|
94 |
* A Bounding box
|
95 |
* @throws IOException
|
96 |
* @throws XmlStreamException
|
97 |
*/
|
98 |
public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException { |
99 |
boolean endFeature = false; |
100 |
int currentTag;
|
101 |
Object bbox = null; |
102 |
min = new double[3]; |
103 |
max = new double[3]; |
104 |
double rotation;
|
105 |
iterations = 0;
|
106 |
dimension = 3;
|
107 |
|
108 |
String id = handler.getProfile().getGeometryBinding().getID(parser, handler);
|
109 |
|
110 |
String tag = parser.getName();
|
111 |
currentTag = parser.getEventType(); |
112 |
|
113 |
while (!endFeature){
|
114 |
switch(currentTag){
|
115 |
case IXmlStreamReader.START_TAG:
|
116 |
if (tag.compareTo(KmlTags.NORTH) == 0){ |
117 |
parser.next(); |
118 |
max[1] = handler.getProfile().getDoubleBinding().parse(parser.getText());
|
119 |
}else if (tag.compareTo(KmlTags.SOUTH) == 0){ |
120 |
parser.next(); |
121 |
min[1] = handler.getProfile().getDoubleBinding().parse(parser.getText());
|
122 |
}else if (tag.compareTo(KmlTags.EAST) == 0){ |
123 |
parser.next(); |
124 |
max[0] = handler.getProfile().getDoubleBinding().parse(parser.getText());
|
125 |
}else if (tag.compareTo(KmlTags.WEST) == 0){ |
126 |
parser.next(); |
127 |
min[0] = handler.getProfile().getDoubleBinding().parse(parser.getText());
|
128 |
}else if (tag.compareTo(KmlTags.MINALTITUDE) == 0){ |
129 |
parser.next(); |
130 |
min[2] = handler.getProfile().getDoubleBinding().parse(parser.getText());
|
131 |
}else if (tag.compareTo(KmlTags.MAXALTITUDE) == 0){ |
132 |
parser.next(); |
133 |
max[2] = handler.getProfile().getDoubleBinding().parse(parser.getText());
|
134 |
} |
135 |
break;
|
136 |
case IXmlStreamReader.END_TAG:
|
137 |
if (tag.compareTo(KmlTags.LATLONALTBOX) == 0){ |
138 |
endFeature = true;
|
139 |
bbox = handler.getContentHandler().startBbox(id, this, KmlTags.DEFAULT_SRS);
|
140 |
handler.getContentHandler().endBbox(bbox); |
141 |
} |
142 |
break;
|
143 |
case IXmlStreamReader.TEXT:
|
144 |
|
145 |
break;
|
146 |
} |
147 |
if (!endFeature){
|
148 |
currentTag = parser.next(); |
149 |
tag = parser.getName(); |
150 |
} |
151 |
} |
152 |
return bbox;
|
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#hasNext()
|
158 |
*/
|
159 |
public boolean hasNext() throws IOException { |
160 |
if (iterations < 2){ |
161 |
return true; |
162 |
} |
163 |
return false; |
164 |
} |
165 |
|
166 |
/*
|
167 |
* (non-Javadoc)
|
168 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#next(double[])
|
169 |
*/
|
170 |
public void next(double[] buffer) throws IOException { |
171 |
if (iterations == 0){ |
172 |
for (int i=0 ; i<buffer.length ; i++){ |
173 |
buffer[i] = min[i]; |
174 |
} |
175 |
iterations = 1;
|
176 |
return;
|
177 |
} |
178 |
if (iterations == 1){ |
179 |
for (int i=0 ; i<buffer.length ; i++){ |
180 |
buffer[i] = max[i]; |
181 |
} |
182 |
iterations = 2;
|
183 |
} |
184 |
} |
185 |
} |