Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / geometries / CoordTypeBinding.java @ 18882

History | View | Annotate | Download (3.63 KB)

1 18286 jpiera
package org.gvsig.gpe.gml.parser.v2.geometries;
2
3
import java.io.IOException;
4
5
import org.gvsig.gpe.gml.GMLTags;
6
import org.gvsig.gpe.gml.GPEDefaultGmlParser;
7
import org.gvsig.gpe.gml.utils.CompareUtils;
8
import org.xmlpull.v1.XmlPullParser;
9
import org.xmlpull.v1.XmlPullParserException;
10
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id:CoordTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
54
 * $Log$
55
 * Revision 1.2  2007/05/14 09:31:06  jorpiell
56
 * Add the a new class to compare tags
57
 *
58
 * Revision 1.1  2007/05/07 12:58:42  jorpiell
59
 * Add some methods to manage the multigeometries
60
 *
61
 *
62
 */
63
/**
64
 * It parses a gml:CoordType object. Example:
65
 * <p>
66
 * <pre>
67
 * <code>
68
 * &lt;gml:coord&gt;&lt;gml:X&gt;0&lt;/gml:X&gt;&lt;gml:Y&gt;0&lt;/gml:Y&gt;&lt;/gml:coord&gt;
69
 * </code>
70
 * </pre>
71
 * </p>
72
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
73
 */
74
public class CoordTypeBinding {
75
76
        /**
77
         * It parses the gml:coord tag
78
         * @param parser
79
         * The XML parser
80
         * @param handler
81
         * The GPE parser that contains the content handler and
82
         * the error handler
83
         * @return
84
         * It retuns an array of doubles with 3 values (x,y,z)
85
         * @throws XmlPullParserException
86
         * @throws IOException
87
         */
88
        public double[] parse(XmlPullParser parser,GPEDefaultGmlParser handler) throws XmlPullParserException, IOException  {
89
                boolean endFeature = false;
90
                int currentTag;
91
92
                String COORDINATES_DECIMAL = GMLTags.GML_DEFAULT_COORDINATES_DECIMAL;
93
94
                double[] aCoordinates = new double[3];
95
96
                String tag = parser.getName();
97
                currentTag = parser.getEventType();
98
99
                while (!endFeature){
100
                        switch(currentTag){
101
                        case XmlPullParser.START_TAG:
102
                                if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_X)){
103
                                        parser.next();
104
                                        aCoordinates[0] = DoubleTypeBinding.parse(parser.getText(),COORDINATES_DECIMAL);
105
                                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_Y)){
106
                                        parser.next();
107
                                        aCoordinates[1] = DoubleTypeBinding.parse(parser.getText(),COORDINATES_DECIMAL);
108
                                }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_Z)){
109
                                        parser.next();
110
                                        aCoordinates[2] = DoubleTypeBinding.parse(parser.getText(),COORDINATES_DECIMAL);
111
                                }
112
                                break;
113
                        case XmlPullParser.END_TAG:
114
                                if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_COORD)){
115
                                        endFeature = true;
116
                                }
117
                                break;
118
                        case XmlPullParser.TEXT:
119
120
                                break;
121
                        }
122
                        if (!endFeature){
123
                                currentTag = parser.next();
124
                                tag = parser.getName();
125
                        }
126
                }
127
                return aCoordinates;
128
        }
129
}