svn-gvsig-desktop / branches / v10 / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / geometries / LatLonAltBoxBinding.java @ 18284
History | View | Annotate | Download (4.5 KB)
1 |
package org.gvsig.gpe.kml.parser.v21.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.kml.GPEDeafultKmlParser; |
6 |
import org.gvsig.gpe.kml.KmlTags; |
7 |
import org.kxml2.io.KXmlParser; |
8 |
import org.xmlpull.v1.XmlPullParser; |
9 |
import org.xmlpull.v1.XmlPullParserException; |
10 |
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
12 |
*
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
14 |
*
|
15 |
* This program is free software; you can redistribute it and/or
|
16 |
* modify it under the terms of the GNU General Public License
|
17 |
* as published by the Free Software Foundation; either version 2
|
18 |
* of the License, or (at your option) any later version.
|
19 |
*
|
20 |
* This program is distributed in the hope that it will be useful,
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
* GNU General Public License for more details.
|
24 |
*
|
25 |
* You should have received a copy of the GNU General Public License
|
26 |
* along with this program; if not, write to the Free Software
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
28 |
*
|
29 |
* For more information, contact:
|
30 |
*
|
31 |
* Generalitat Valenciana
|
32 |
* Conselleria d'Infraestructures i Transport
|
33 |
* Av. Blasco Ib??ez, 50
|
34 |
* 46010 VALENCIA
|
35 |
* SPAIN
|
36 |
*
|
37 |
* +34 963862235
|
38 |
* gvsig@gva.es
|
39 |
* www.gvsig.gva.es
|
40 |
*
|
41 |
* or
|
42 |
*
|
43 |
* IVER T.I. S.A
|
44 |
* Salamanca 50
|
45 |
* 46005 Valencia
|
46 |
* Spain
|
47 |
*
|
48 |
* +34 963163400
|
49 |
* dac@iver.es
|
50 |
*/
|
51 |
/* CVS MESSAGES:
|
52 |
*
|
53 |
* $Id:LatLonAltBoxBinding.java 357 2008-01-09 17:50:08Z jpiera $
|
54 |
* $Log$
|
55 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell
|
56 |
* Refactoring of some package names
|
57 |
*
|
58 |
* Revision 1.1 2007/05/09 08:36:24 jorpiell
|
59 |
* Add the bbox to the layer
|
60 |
*
|
61 |
*
|
62 |
*/
|
63 |
/**
|
64 |
* This class parses a LatLonAltBox tag. Example:
|
65 |
* <p>
|
66 |
* <pre>
|
67 |
* <code>
|
68 |
* <LatLonAltBox>
|
69 |
* <north>43.374</north>
|
70 |
* <south>42.983</south>
|
71 |
* <east>-0.335</east>
|
72 |
* <west>-1.423</west>
|
73 |
* <minAltitude>0</minAltitude>
|
74 |
* <maxAltitude>0</maxAltitude>
|
75 |
* </LatLonAltBox>
|
76 |
* </code>
|
77 |
* </pre>
|
78 |
* </p>
|
79 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
80 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#latlonaltbox
|
81 |
*/
|
82 |
public class LatLonAltBoxBinding { |
83 |
|
84 |
/**
|
85 |
* It parses the LatLonAltBox tag
|
86 |
* @param parser
|
87 |
* The XML parser
|
88 |
* @param handler
|
89 |
* The GPE parser that contains the content handler and
|
90 |
* the error handler
|
91 |
* @return
|
92 |
* A Bounding box
|
93 |
* @throws IOException
|
94 |
* @throws XmlPullParserException
|
95 |
*/
|
96 |
public Object parse(XmlPullParser parser,GPEDeafultKmlParser handler) throws XmlPullParserException, IOException { |
97 |
boolean endFeature = false; |
98 |
int currentTag;
|
99 |
Object bbox = null; |
100 |
double north = 0; |
101 |
double south = 0; |
102 |
double east = 0; |
103 |
double west = 0; |
104 |
double minAltitude = 0; |
105 |
double maxAltitude = 0; |
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 KXmlParser.START_TAG:
|
115 |
if (tag.compareTo(KmlTags.NORTH) == 0){ |
116 |
parser.next(); |
117 |
north = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
118 |
}else if (tag.compareTo(KmlTags.SOUTH) == 0){ |
119 |
parser.next(); |
120 |
south = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
121 |
}else if (tag.compareTo(KmlTags.EAST) == 0){ |
122 |
parser.next(); |
123 |
east = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
124 |
}else if (tag.compareTo(KmlTags.WEST) == 0){ |
125 |
parser.next(); |
126 |
west = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
127 |
}else if (tag.compareTo(KmlTags.MINALTITUDE) == 0){ |
128 |
parser.next(); |
129 |
minAltitude = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
130 |
}else if (tag.compareTo(KmlTags.MAXALTITUDE) == 0){ |
131 |
parser.next(); |
132 |
maxAltitude = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
133 |
} |
134 |
break;
|
135 |
case KXmlParser.END_TAG:
|
136 |
if (tag.compareTo(KmlTags.LATLONALTBOX) == 0){ |
137 |
endFeature = true;
|
138 |
double[] x = {west,east}; |
139 |
double[] y = {south,north}; |
140 |
double[] z = {minAltitude,maxAltitude}; |
141 |
bbox = handler.getContentHandler().startBbox(id, x, y, z, KmlTags.DEFAULT_SRS); |
142 |
handler.getContentHandler().endBbox(bbox); |
143 |
} |
144 |
break;
|
145 |
case KXmlParser.TEXT:
|
146 |
|
147 |
break;
|
148 |
} |
149 |
if (!endFeature){
|
150 |
currentTag = parser.next(); |
151 |
tag = parser.getName(); |
152 |
} |
153 |
} |
154 |
return bbox;
|
155 |
} |
156 |
} |
157 |
|