Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / bindings / geometries / PointTypeBinding.java @ 11485

History | View | Annotate | Download (4.03 KB)

1
package org.gvsig.gpe.kml.bindings.geometries;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.kml.GPEKmlParser;
6
import org.gvsig.gpe.kml.KmlTags;
7
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
8
import org.kxml2.io.KXmlParser;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

    
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: PointTypeBinding.java 11485 2007-05-08 08:22:37Z jorpiell $
56
 * $Log$
57
 * Revision 1.5  2007-05-08 08:22:37  jorpiell
58
 * Add comments to create javadocs
59
 *
60
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
61
 * Writing tests updated
62
 *
63
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
64
 * Tests updating
65
 *
66
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
67
 * Kml writing support added
68
 *
69
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
70
 * Add KML reading support
71
 *
72
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
73
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
74
 *
75
 * Revision 1.1  2007/02/28 11:48:31  csanchez
76
 * *** empty log message ***
77
 *
78
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
79
 * A?adidos los proyectos de kml y gml antiguos
80
 *
81
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
82
 * A?adido el driver de KML
83
 *
84
 *
85
 */
86
/**
87
 * It parses a Point tag. Example:
88
 * <p>
89
 * <pre>
90
 * <code>
91
 * &lt;Point gid="P6776"&gt;
92
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
93
 * &lt;/Point&gt;
94
 * </code>
95
 * </pre>
96
 * </p> 
97
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
98
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#point
99
 */
100
public class PointTypeBinding{
101

    
102
        /**
103
         * It parses the Point tag
104
         * @param parser
105
         * The XML parser
106
         * @param handler
107
         * The GPE parser that contains the content handler and
108
         * the error handler
109
         * @return
110
         * A point
111
         * @throws IOException 
112
         * @throws XmlPullParserException 
113
         * @throws XmlPullParserException 
114
         * @throws IOException 
115
         */
116
        public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
117
                boolean endFeature = false;
118
                int currentTag;
119
                Object point = null;                        
120
                
121
                String id = GeometryBinding.getID(parser, handler);
122
                
123
                
124
                        String tag = parser.getName();
125
                        currentTag = parser.getEventType();
126
                        
127
                        while (!endFeature){
128
                                switch(currentTag){
129
                                case KXmlParser.START_TAG:
130
                                        if (tag.compareTo(KmlTags.COORDINATES) == 0){
131
                                                double[][] coordinates = CoordinatesTypeBinding.parse(parser, handler);
132
                                                point = handler.getContentHandler().startPoint(id,
133
                                                                        coordinates[0][0],
134
                                                                        coordinates[1][0],
135
                                                                        coordinates[2][0],
136
                                                                        KmlTags.DEFAULT_SRS);
137
                                        }
138
                                        break;
139
                                case KXmlParser.END_TAG:
140
                                        if (tag.compareTo(KmlTags.POINT) == 0){                                                
141
                                                endFeature = true;
142
                                                handler.getContentHandler().endPoint(point);
143
                                        }
144
                                        break;
145
                                case KXmlParser.TEXT:                                        
146
                                        
147
                                        break;
148
                                }
149
                                if (!endFeature){                                        
150
                                        currentTag = parser.next();
151
                                        tag = parser.getName();
152
                                }
153
                        }                        
154
                
155
                return point;        
156
        }
157

    
158

    
159

    
160
}