root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / binfings / geometries / PolygonTypeBinding.java @ 10637
History | View | Annotate | Download (5.1 KB)
1 |
package org.gvsig.gpe.kml.binfings.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
7 |
import org.gvsig.gpe.kml.KmlTags; |
8 |
import org.gvsig.gpe.kml.bindings.AbstractComplexBinding; |
9 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
10 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
11 |
import org.kxml2.io.KXmlParser; |
12 |
import org.xmlpull.v1.XmlPullParserException; |
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 10637 2007-03-07 08:19:11Z jorpiell $
|
57 |
* $Log$
|
58 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell
|
59 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML
|
60 |
*
|
61 |
* Revision 1.1 2007/02/28 11:48:31 csanchez
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell
|
65 |
* A?adidos los proyectos de kml y gml antiguos
|
66 |
*
|
67 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell
|
68 |
* A?adido el driver de KML
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
/**
|
73 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
74 |
*/
|
75 |
public class PolygonTypeBinding extends AbstractComplexBinding{ |
76 |
|
77 |
public PolygonTypeBinding(IGeometriesFactory gFactory) {
|
78 |
super(gFactory);
|
79 |
// TODO Auto-generated constructor stub
|
80 |
} |
81 |
|
82 |
public Object parse(IReaderFile reader) throws KmlBodyParseException { |
83 |
boolean endFeature = false; |
84 |
int currentTag;
|
85 |
Object geometry = null; |
86 |
|
87 |
try {
|
88 |
String tag = reader.getName();
|
89 |
currentTag = reader.getEventType(); |
90 |
|
91 |
while (!endFeature){
|
92 |
switch(currentTag){
|
93 |
case KXmlParser.START_TAG:
|
94 |
if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){ |
95 |
geometry = parseOuterBoundaryIsTag(reader); |
96 |
} |
97 |
break;
|
98 |
case KXmlParser.END_TAG:
|
99 |
if (tag.compareTo(KmlTags.POLYGON) == 0){ |
100 |
endFeature = true;
|
101 |
} |
102 |
break;
|
103 |
case KXmlParser.TEXT:
|
104 |
|
105 |
break;
|
106 |
} |
107 |
if (!endFeature){
|
108 |
currentTag = reader.next(); |
109 |
tag = reader.getName(); |
110 |
} |
111 |
} |
112 |
} catch (XmlPullParserException e) {
|
113 |
throw new KmlBodyParseException(e); |
114 |
} catch (IOException e) { |
115 |
throw new KmlBodyParseException(e); |
116 |
} |
117 |
return geometry;
|
118 |
} |
119 |
|
120 |
private Object parseOuterBoundaryIsTag(IReaderFile reader) throws KmlBodyParseException{ |
121 |
boolean endFeature = false; |
122 |
int currentTag;
|
123 |
Object geometry = null; |
124 |
|
125 |
try {
|
126 |
String tag = reader.getName();
|
127 |
currentTag = reader.getEventType(); |
128 |
|
129 |
while (!endFeature){
|
130 |
switch(currentTag){
|
131 |
case KXmlParser.START_TAG:
|
132 |
if (tag.compareTo(KmlTags.LINEARRING) == 0){ |
133 |
geometry = parseLinearRing(reader); |
134 |
} |
135 |
break;
|
136 |
case KXmlParser.END_TAG:
|
137 |
if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){ |
138 |
endFeature = true;
|
139 |
} |
140 |
break;
|
141 |
case KXmlParser.TEXT:
|
142 |
|
143 |
break;
|
144 |
} |
145 |
if (!endFeature){
|
146 |
currentTag = reader.next(); |
147 |
tag = reader.getName(); |
148 |
} |
149 |
} |
150 |
} catch (XmlPullParserException e) {
|
151 |
throw new KmlBodyParseException(e); |
152 |
} catch (IOException e) { |
153 |
throw new KmlBodyParseException(e); |
154 |
} |
155 |
return geometry;
|
156 |
} |
157 |
|
158 |
private Object parseLinearRing(IReaderFile reader) throws KmlBodyParseException { |
159 |
boolean endFeature = false; |
160 |
int currentTag;
|
161 |
Object geometry = null; |
162 |
|
163 |
try {
|
164 |
String tag = reader.getName();
|
165 |
currentTag = reader.getEventType(); |
166 |
|
167 |
while (!endFeature){
|
168 |
switch(currentTag){
|
169 |
case KXmlParser.START_TAG:
|
170 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
171 |
ArrayList coordinates =
|
172 |
(ArrayList)new CoordinatesTypeBinding(getGFactory()).parse(reader); |
173 |
geometry = getGFactory().createPolygon2D( |
174 |
(double[])coordinates.get(0), |
175 |
(double[])coordinates.get(1)); |
176 |
endFeature = true;
|
177 |
} |
178 |
break;
|
179 |
case KXmlParser.END_TAG:
|
180 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
181 |
endFeature = true;
|
182 |
} |
183 |
break;
|
184 |
case KXmlParser.TEXT:
|
185 |
|
186 |
break;
|
187 |
} |
188 |
if (!endFeature){
|
189 |
currentTag = reader.next(); |
190 |
tag = reader.getName(); |
191 |
} |
192 |
} |
193 |
} catch (XmlPullParserException e) {
|
194 |
throw new KmlBodyParseException(e); |
195 |
} catch (IOException e) { |
196 |
throw new KmlBodyParseException(e); |
197 |
} |
198 |
return geometry;
|
199 |
} |
200 |
} |