root / branches / v1_9_0 / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / coordinates / CoordTypeIterator.java @ 53
History | View | Annotate | Download (4.61 KB)
1 |
package org.gvsig.gpe.gml.parser.v2.coordinates; |
---|---|
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.geometries.DoubleTypeBinding; |
9 |
import org.gvsig.gpe.gml.utils.GMLTags; |
10 |
import org.gvsig.gpe.xml.stream.EventType; |
11 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
12 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
13 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
14 |
|
15 |
|
16 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
17 |
*
|
18 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
19 |
*
|
20 |
* This program is free software; you can redistribute it and/or
|
21 |
* modify it under the terms of the GNU General Public License
|
22 |
* as published by the Free Software Foundation; either version 2
|
23 |
* of the License, or (at your option) any later version.
|
24 |
*
|
25 |
* This program is distributed in the hope that it will be useful,
|
26 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28 |
* GNU General Public License for more details.
|
29 |
*
|
30 |
* You should have received a copy of the GNU General Public License
|
31 |
* along with this program; if not, write to the Free Software
|
32 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
33 |
*
|
34 |
* For more information, contact:
|
35 |
*
|
36 |
* Generalitat Valenciana
|
37 |
* Conselleria d'Infraestructures i Transport
|
38 |
* Av. Blasco Ib??ez, 50
|
39 |
* 46010 VALENCIA
|
40 |
* SPAIN
|
41 |
*
|
42 |
* +34 963862235
|
43 |
* gvsig@gva.es
|
44 |
* www.gvsig.gva.es
|
45 |
*
|
46 |
* or
|
47 |
*
|
48 |
* IVER T.I. S.A
|
49 |
* Salamanca 50
|
50 |
* 46005 Valencia
|
51 |
* Spain
|
52 |
*
|
53 |
* +34 963163400
|
54 |
* dac@iver.es
|
55 |
*/
|
56 |
/* CVS MESSAGES:
|
57 |
*
|
58 |
* $Id:CoordTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
|
59 |
* $Log$
|
60 |
* Revision 1.2 2007/05/14 09:31:06 jorpiell
|
61 |
* Add the a new class to compare tags
|
62 |
*
|
63 |
* Revision 1.1 2007/05/07 12:58:42 jorpiell
|
64 |
* Add some methods to manage the multigeometries
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
/**
|
69 |
* It parses a gml:CoordType object. Example:
|
70 |
* <p>
|
71 |
* <pre>
|
72 |
* <code>
|
73 |
* <gml:coord><gml:X>0</gml:X><gml:Y>0</gml:Y></gml:coord>
|
74 |
* </code>
|
75 |
* </pre>
|
76 |
* </p>
|
77 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
78 |
*/
|
79 |
public class CoordTypeIterator extends GmlCoodinatesIterator{ |
80 |
|
81 |
/**
|
82 |
* It parses the gml:coord tag
|
83 |
* @param parser
|
84 |
* The XML parser
|
85 |
* @param handler
|
86 |
* The GPE parser that contains the content handler and
|
87 |
* the error handler
|
88 |
* @return
|
89 |
* It retuns an array of doubles with 3 values (x,y,z)
|
90 |
* @throws XmlStreamException
|
91 |
* @throws IOException
|
92 |
*/
|
93 |
/* (non-Javadoc)
|
94 |
* @see org.gvsig.gpe.gml.parser.v2.coordinates.GmlCoodinatesIterator#initialize(org.gvsig.gpe.xml.stream.IXmlStreamReader, org.gvsig.gpe.gml.parser.GPEDefaultGmlParser, java.lang.String)
|
95 |
*/
|
96 |
public void initialize(IXmlStreamReader parser, |
97 |
GPEDefaultGmlParser handler, QName lastTag)
|
98 |
throws XmlStreamException, IOException { |
99 |
super.initialize(parser, handler, lastTag);
|
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#getDimension()
|
105 |
*/
|
106 |
public int getDimension() { |
107 |
//TODO gets the dimension!!!
|
108 |
return 3; |
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#hasNext()
|
114 |
*/
|
115 |
public boolean hasNext() throws IOException { |
116 |
QName tag = parser.getElementName();
|
117 |
|
118 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORD)){
|
119 |
return true; |
120 |
} |
121 |
parseAll(); |
122 |
return false; |
123 |
} |
124 |
|
125 |
/*
|
126 |
* (non-Javadoc)
|
127 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#next(double[])
|
128 |
*/
|
129 |
public void next(double[] buffer) throws IOException { |
130 |
boolean endCoord = false; |
131 |
EventType currentTag; |
132 |
|
133 |
QName tag = parser.getElementName();
|
134 |
currentTag = parser.getEventType(); |
135 |
|
136 |
while (!endCoord){
|
137 |
switch(currentTag.getCode()){
|
138 |
case EventType.START_ELEMENT_CODE:
|
139 |
tag = parser.getElementName(); |
140 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_X)){
|
141 |
parser.next(); |
142 |
buffer[0] = DoubleTypeBinding.parse(parser.getText(),COORDINATES_DECIMAL);
|
143 |
}else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_Y)){ |
144 |
parser.next(); |
145 |
buffer[1] = DoubleTypeBinding.parse(parser.getText(),COORDINATES_DECIMAL);
|
146 |
}else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_Z)){ |
147 |
parser.next(); |
148 |
buffer[2] = DoubleTypeBinding.parse(parser.getText(),COORDINATES_DECIMAL);
|
149 |
} |
150 |
break;
|
151 |
case EventType.END_ELEMENT_CODE:
|
152 |
tag = parser.getElementName(); |
153 |
if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_COORD)){
|
154 |
//Advance until netx XML tag
|
155 |
endCoord = true;
|
156 |
} |
157 |
break;
|
158 |
} |
159 |
if (!endCoord){
|
160 |
currentTag = parser.next(); |
161 |
} |
162 |
} |
163 |
} |
164 |
} |