svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / reader / bindings / geometries / PolygonTypeBinding.java @ 11573
History | View | Annotate | Download (4.64 KB)
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
6 |
import org.gvsig.gpe.kml.KmlTags; |
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
8 |
import org.kxml2.io.KXmlParser; |
9 |
import org.xmlpull.v1.XmlPullParser; |
10 |
import org.xmlpull.v1.XmlPullParserException; |
11 |
|
12 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
13 |
*
|
14 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
15 |
*
|
16 |
* This program is free software; you can redistribute it and/or
|
17 |
* modify it under the terms of the GNU General Public License
|
18 |
* as published by the Free Software Foundation; either version 2
|
19 |
* of the License, or (at your option) any later version.
|
20 |
*
|
21 |
* This program is distributed in the hope that it will be useful,
|
22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
* GNU General Public License for more details.
|
25 |
*
|
26 |
* You should have received a copy of the GNU General Public License
|
27 |
* along with this program; if not, write to the Free Software
|
28 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
29 |
*
|
30 |
* For more information, contact:
|
31 |
*
|
32 |
* Generalitat Valenciana
|
33 |
* Conselleria d'Infraestructures i Transport
|
34 |
* Av. Blasco Ib??ez, 50
|
35 |
* 46010 VALENCIA
|
36 |
* SPAIN
|
37 |
*
|
38 |
* +34 963862235
|
39 |
* gvsig@gva.es
|
40 |
* www.gvsig.gva.es
|
41 |
*
|
42 |
* or
|
43 |
*
|
44 |
* IVER T.I. S.A
|
45 |
* Salamanca 50
|
46 |
* 46005 Valencia
|
47 |
* Spain
|
48 |
*
|
49 |
* +34 963163400
|
50 |
* dac@iver.es
|
51 |
*/
|
52 |
/* CVS MESSAGES:
|
53 |
*
|
54 |
* $Id: PolygonTypeBinding.java 11573 2007-05-11 07:06:29Z jorpiell $
|
55 |
* $Log$
|
56 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell
|
57 |
* Refactoring of some package names
|
58 |
*
|
59 |
* Revision 1.5 2007/05/08 08:22:37 jorpiell
|
60 |
* Add comments to create javadocs
|
61 |
*
|
62 |
* Revision 1.4 2007/05/02 11:46:50 jorpiell
|
63 |
* Writing tests updated
|
64 |
*
|
65 |
* Revision 1.3 2007/04/20 08:38:59 jorpiell
|
66 |
* Tests updating
|
67 |
*
|
68 |
* Revision 1.2 2007/04/14 16:08:07 jorpiell
|
69 |
* Kml writing support added
|
70 |
*
|
71 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell
|
72 |
* Add KML reading support
|
73 |
*
|
74 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell
|
75 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML
|
76 |
*
|
77 |
* Revision 1.1 2007/02/28 11:48:31 csanchez
|
78 |
* *** empty log message ***
|
79 |
*
|
80 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell
|
81 |
* A?adidos los proyectos de kml y gml antiguos
|
82 |
*
|
83 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell
|
84 |
* A?adido el driver de KML
|
85 |
*
|
86 |
*
|
87 |
*/
|
88 |
/**
|
89 |
* It writes a Polygon tag. Example:
|
90 |
* <p>
|
91 |
* <pre>
|
92 |
* <code>
|
93 |
* <Polygon gid="_877789">
|
94 |
* <outerBoundaryIs>
|
95 |
* <LinearRing>
|
96 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
97 |
* </LinearRing>
|
98 |
* </outerBoundaryIs>
|
99 |
* </Polygon>
|
100 |
* </code>
|
101 |
* </pre>
|
102 |
* </p>
|
103 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
104 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#polygon
|
105 |
*/
|
106 |
public class PolygonTypeBinding { |
107 |
|
108 |
/**
|
109 |
* It parses the Polygon tag
|
110 |
* @param parser
|
111 |
* The XML parser
|
112 |
* @param handler
|
113 |
* The GPE parser that contains the content handler and
|
114 |
* the error handler
|
115 |
* @return
|
116 |
* A polygon
|
117 |
* @throws IOException
|
118 |
* @throws XmlPullParserException
|
119 |
* @throws XmlPullParserException
|
120 |
* @throws IOException
|
121 |
*/
|
122 |
public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException { |
123 |
boolean endFeature = false; |
124 |
int currentTag;
|
125 |
Object polygon = null; |
126 |
|
127 |
String id = GeometryBinding.getID(parser, handler);
|
128 |
|
129 |
String tag = parser.getName();
|
130 |
currentTag = parser.getEventType(); |
131 |
|
132 |
while (!endFeature){
|
133 |
switch(currentTag){
|
134 |
case KXmlParser.START_TAG:
|
135 |
if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){ |
136 |
double[][] coordinates = OuterBoundaryIsBinding.parse(parser, handler); |
137 |
polygon = handler.getContentHandler().startPolygon(id, |
138 |
coordinates[0],
|
139 |
coordinates[1],
|
140 |
coordinates[2],
|
141 |
KmlTags.DEFAULT_SRS); |
142 |
}else if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){ |
143 |
double[][] coordinates = InnerBoundaryIsBinding.parse(parser, handler); |
144 |
Object innerPolygon = handler.getContentHandler().startInnerPolygon(null, |
145 |
coordinates[0],
|
146 |
coordinates[1],
|
147 |
coordinates[2],
|
148 |
KmlTags.DEFAULT_SRS); |
149 |
handler.getContentHandler().endInnerPolygon(innerPolygon); |
150 |
handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,polygon); |
151 |
} |
152 |
break;
|
153 |
case KXmlParser.END_TAG:
|
154 |
if (tag.compareTo(KmlTags.POLYGON) == 0){ |
155 |
endFeature = true;
|
156 |
handler.getContentHandler().endPolygon(polygon); |
157 |
} |
158 |
break;
|
159 |
case KXmlParser.TEXT:
|
160 |
|
161 |
break;
|
162 |
} |
163 |
if (!endFeature){
|
164 |
currentTag = parser.next(); |
165 |
tag = parser.getName(); |
166 |
} |
167 |
} |
168 |
|
169 |
return polygon;
|
170 |
} |
171 |
} |