root / org.gvsig.gpe / library / trunk / org.gvsig.gpe / org.gvsig.gpe.prov / org.gvsig.gpe.prov.gml / src / main / java / org / gvsig / gpe / prov / gml / parser / v2 / geometries / PolygonTypeBinding.java @ 264
History | View | Annotate | Download (5.23 KB)
1 |
package org.gvsig.gpe.prov.gml.parser.v2.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator; |
6 |
import org.gvsig.gpe.prov.gml.parser.GPEDefaultGmlParser; |
7 |
import org.gvsig.gpe.prov.gml.utils.GmlTags; |
8 |
import org.gvsig.xmlpull.lib.api.stream.IQName; |
9 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader; |
10 |
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException; |
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 195 2007-11-26 09:02:22Z jpiera $
|
55 |
* $Log$
|
56 |
* Revision 1.4 2007/05/14 11:18:51 jorpiell
|
57 |
* ProjectionFactory updated
|
58 |
*
|
59 |
* Revision 1.3 2007/05/14 09:31:06 jorpiell
|
60 |
* Add the a new class to compare tags
|
61 |
*
|
62 |
* Revision 1.2 2007/05/08 10:24:16 jorpiell
|
63 |
* Add comments to create javadocs
|
64 |
*
|
65 |
* Revision 1.1 2007/05/07 12:58:42 jorpiell
|
66 |
* Add some methods to manage the multigeometries
|
67 |
*
|
68 |
* Revision 1.1 2007/05/07 07:06:46 jorpiell
|
69 |
* Add a constructor with the name and the description fields
|
70 |
*
|
71 |
*
|
72 |
*/
|
73 |
/**
|
74 |
* It parses a gml:PolygonType object. Example:
|
75 |
* <p>
|
76 |
* <pre>
|
77 |
* <code>
|
78 |
* <Polygon gid="_877789">
|
79 |
* <outerBoundaryIs>
|
80 |
* <LinearRing>
|
81 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
82 |
* </LinearRing>
|
83 |
* </outerBoundaryIs>
|
84 |
* </Polygon>
|
85 |
* </code>
|
86 |
* </pre>
|
87 |
* </p>
|
88 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
89 |
*/
|
90 |
public class PolygonTypeBinding extends GeometryBinding{ |
91 |
protected Object polygon = null; |
92 |
|
93 |
/**
|
94 |
* It parses the gml:Polygon tag
|
95 |
* @param parser
|
96 |
* The XML parser
|
97 |
* @param handler
|
98 |
* The GPE parser that contains the content handler and
|
99 |
* the error handler
|
100 |
* @return
|
101 |
* A polygon
|
102 |
* @throws XmlStreamException
|
103 |
* @throws IOException
|
104 |
*/
|
105 |
public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException { |
106 |
boolean endFeature = false; |
107 |
int currentTag;
|
108 |
|
109 |
super.setAtributtes(parser, handler);
|
110 |
|
111 |
IQName tag = parser.getName(); |
112 |
currentTag = parser.getEventType(); |
113 |
|
114 |
while (!endFeature){
|
115 |
switch(currentTag){
|
116 |
case IXmlStreamReader.START_ELEMENT:
|
117 |
polygon = parseTag(parser, handler, tag, id, srsName); |
118 |
break;
|
119 |
case IXmlStreamReader.END_ELEMENT:
|
120 |
endFeature = parseLastTag(parser, handler, tag); |
121 |
if (endFeature){
|
122 |
polygon = handler.getContentHandler().endPolygon(polygon); |
123 |
} |
124 |
break;
|
125 |
case IXmlStreamReader.CHARACTERS:
|
126 |
|
127 |
break;
|
128 |
} |
129 |
if (!endFeature){
|
130 |
currentTag = parser.next(); |
131 |
tag = parser.getName(); |
132 |
} |
133 |
} |
134 |
|
135 |
return polygon;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* It parses the XML tag
|
140 |
* @param parser
|
141 |
* @param handler
|
142 |
* @param tag
|
143 |
* @param id
|
144 |
* @param srsName
|
145 |
* @return
|
146 |
* @throws XmlStreamException
|
147 |
* @throws IOException
|
148 |
*/
|
149 |
protected Object parseTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, IQName tag, String id, String srsName) throws XmlStreamException, IOException{ |
150 |
if (handler.getQNameComparator().equals(tag,GmlTags.GML_OUTERBOUNDARYIS)){
|
151 |
OuterBoundaryIsTypeBinding coordinatesBinding = handler.getProfile().getOuterBoundaryIsTypeBinding(); |
152 |
ICoordinateIterator coordinatesIterator = coordinatesBinding.parse(parser, handler); |
153 |
this.polygon = handler.getContentHandler().startPolygon(id,
|
154 |
coordinatesIterator, |
155 |
srsName); |
156 |
}else if (handler.getQNameComparator().equals(tag,GmlTags.GML_INNERBOUNDARYIS)){ |
157 |
InnerBoundaryIsTypeBinding coordinatesBinding = handler.getProfile().getInnerBoundaryIsTypeBinding(); |
158 |
ICoordinateIterator coordinatesIterator = coordinatesBinding.parse(parser, handler); |
159 |
Object innerPolygon = handler.getContentHandler().startInnerPolygon(null, |
160 |
coordinatesIterator, |
161 |
srsName); |
162 |
handler.getContentHandler().endInnerPolygon(innerPolygon); |
163 |
handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,this.polygon);
|
164 |
} |
165 |
return polygon;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* Parses the last tag
|
170 |
* @param parser
|
171 |
* @param handler
|
172 |
* @param tag
|
173 |
* @return
|
174 |
*/
|
175 |
protected boolean parseLastTag(IXmlStreamReader parser,GPEDefaultGmlParser handler, IQName tag){ |
176 |
if (handler.getQNameComparator().equals(tag,GmlTags.GML_POLYGON)){
|
177 |
return true; |
178 |
} |
179 |
return false; |
180 |
} |
181 |
} |