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