root / branches / Mobile1.0 / org.gvsig.gpe.gml / src / org / gvsig / gpe / gml / parser / v2 / geometries / LinearRingTypeBinding.java @ 79
History | View | Annotate | Download (5.64 KB)
1 |
package org.gvsig.gpe.gml.parser.v2.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import javax.xml.namespace.QName; |
6 |
|
7 |
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser; |
8 |
import org.gvsig.gpe.gml.parser.v2.coordinates.CoordTypeIterator; |
9 |
import org.gvsig.gpe.gml.parser.v2.coordinates.CoordinatesTypeIterator; |
10 |
import org.gvsig.gpe.gml.utils.GMLTags; |
11 |
import org.gvsig.gpe.parser.ICoordinateIterator; |
12 |
import org.gvsig.gpe.warnings.PolygonNotClosedWarning; |
13 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
14 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
15 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
16 |
|
17 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
18 |
*
|
19 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
20 |
*
|
21 |
* This program is free software; you can redistribute it and/or
|
22 |
* modify it under the terms of the GNU General Public License
|
23 |
* as published by the Free Software Foundation; either version 2
|
24 |
* of the License, or (at your option) any later version.
|
25 |
*
|
26 |
* This program is distributed in the hope that it will be useful,
|
27 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29 |
* GNU General Public License for more details.
|
30 |
*
|
31 |
* You should have received a copy of the GNU General Public License
|
32 |
* along with this program; if not, write to the Free Software
|
33 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
34 |
*
|
35 |
* For more information, contact:
|
36 |
*
|
37 |
* Generalitat Valenciana
|
38 |
* Conselleria d'Infraestructures i Transport
|
39 |
* Av. Blasco Ib??ez, 50
|
40 |
* 46010 VALENCIA
|
41 |
* SPAIN
|
42 |
*
|
43 |
* +34 963862235
|
44 |
* gvsig@gva.es
|
45 |
* www.gvsig.gva.es
|
46 |
*
|
47 |
* or
|
48 |
*
|
49 |
* IVER T.I. S.A
|
50 |
* Salamanca 50
|
51 |
* 46005 Valencia
|
52 |
* Spain
|
53 |
*
|
54 |
* +34 963163400
|
55 |
* dac@iver.es
|
56 |
*/
|
57 |
/* CVS MESSAGES:
|
58 |
*
|
59 |
* $Id:LinearRingTypeBinding.java 195 2007-11-26 09:02:22Z jpiera $
|
60 |
* $Log$
|
61 |
* Revision 1.4 2007/05/16 09:29:12 jorpiell
|
62 |
* The polygons has to be closed
|
63 |
*
|
64 |
* Revision 1.3 2007/05/15 11:55:11 jorpiell
|
65 |
* MultiGeometry is now supported
|
66 |
*
|
67 |
* Revision 1.2 2007/05/14 09:31:06 jorpiell
|
68 |
* Add the a new class to compare tags
|
69 |
*
|
70 |
* Revision 1.1 2007/05/07 12:58:42 jorpiell
|
71 |
* Add some methods to manage the multigeometries
|
72 |
*
|
73 |
*
|
74 |
*/
|
75 |
/**
|
76 |
* It parses a gml:linearRingType object. Example:
|
77 |
* <p>
|
78 |
* <pre>
|
79 |
* <code>
|
80 |
* <LinearRing>
|
81 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
82 |
* </LinearRing>
|
83 |
* </code>
|
84 |
* </pre>
|
85 |
* </p>
|
86 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
87 |
*/
|
88 |
public class LinearRingTypeBinding extends GeometryBinding{ |
89 |
|
90 |
/**
|
91 |
* It parses the gml:LinearRing tag and return the
|
92 |
* Object
|
93 |
* @param parser
|
94 |
* The XML parser
|
95 |
* @param handler
|
96 |
* The GPE parser that contains the content handler and
|
97 |
* the error handler
|
98 |
* @return
|
99 |
* A linear ring
|
100 |
* @throws XmlStreamException
|
101 |
* @throws IOException
|
102 |
*/
|
103 |
public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException{ |
104 |
Object linearRing = null; |
105 |
|
106 |
super.setAtributtes(parser, handler.getErrorHandler());
|
107 |
|
108 |
ICoordinateIterator coordinatesIteartor = parseCoordinates(parser, handler); |
109 |
|
110 |
linearRing = handler.getContentHandler().startLinearRing(id, coordinatesIteartor, srsName); |
111 |
handler.getContentHandler().endLinearRing(linearRing); |
112 |
|
113 |
return linearRing;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* It parses the gml:LinearRing tag and return the
|
118 |
* coordinates
|
119 |
* @param parser
|
120 |
* The XML parser
|
121 |
* @param handler
|
122 |
* The GPE parser that contains the content handler and
|
123 |
* the error handler
|
124 |
* @return
|
125 |
* An array of coordinates
|
126 |
* @throws XmlStreamException
|
127 |
* @throws IOException
|
128 |
* @throws PolygonNotClosedWarning
|
129 |
*/
|
130 |
public ICoordinateIterator parseCoordinates(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException { |
131 |
boolean endFeature = false; |
132 |
int currentTag;
|
133 |
|
134 |
QName tag = parser.getName();
|
135 |
currentTag = parser.getEventType(); |
136 |
|
137 |
while (!endFeature){
|
138 |
switch(currentTag){
|
139 |
case IXmlStreamReader.START_ELEMENT:
|
140 |
ICoordinateIterator iterator = parseTag_(parser, handler, tag); |
141 |
if (iterator != null){ |
142 |
return iterator;
|
143 |
} |
144 |
case IXmlStreamReader.END_ELEMENT:
|
145 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_LINEARRING)){
|
146 |
|
147 |
} |
148 |
break;
|
149 |
case IXmlStreamReader.CHARACTERS:
|
150 |
|
151 |
break;
|
152 |
} |
153 |
if (!endFeature){
|
154 |
currentTag = parser.next(); |
155 |
tag = parser.getName(); |
156 |
} |
157 |
} |
158 |
//The first and the last coordinates has to be the same
|
159 |
// if ((coordinates[0][0] != coordinates[0][coordinates[0].length - 1]) ||
|
160 |
// (coordinates[1][0] != coordinates[1][coordinates[1].length - 1]) ||
|
161 |
// (coordinates[2][0] != coordinates[2][coordinates[2].length - 1])){
|
162 |
// handler.getErrorHandler().addWarning(new PolygonNotClosedWarning(coordinates));
|
163 |
// }
|
164 |
return null; |
165 |
} |
166 |
|
167 |
/**
|
168 |
*
|
169 |
* @param parser
|
170 |
* @param handler
|
171 |
* @param tag
|
172 |
* @param coordsContainer
|
173 |
* @return
|
174 |
* @throws XmlStreamException
|
175 |
* @throws IOException
|
176 |
*/
|
177 |
protected ICoordinateIterator parseTag_(IXmlStreamReader parser,GPEDefaultGmlParser handler, QName tag) throws XmlStreamException, IOException{ |
178 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORDINATES)){
|
179 |
CoordinatesTypeIterator coordinatesIterator = handler.getProfile().getCoordinatesTypeBinding(); |
180 |
coordinatesIterator.initialize(parser, handler,GMLTags.GML_LINEARRING); |
181 |
return coordinatesIterator;
|
182 |
}else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORD)){ |
183 |
CoordTypeIterator coordinatesIterator = handler.getProfile().getCoordTypeBinding(); |
184 |
coordinatesIterator.initialize(parser, handler,GMLTags.GML_LINEARRING); |
185 |
return coordinatesIterator;
|
186 |
} |
187 |
return null; |
188 |
} |
189 |
|
190 |
|
191 |
} |