Statistics
| Revision:

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

History | View | Annotate | Download (3.33 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
/* 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: LinearRingBinding.java 11485 2007-05-08 08:22:37Z jorpiell $
55
 * $Log$
56
 * Revision 1.3  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
60
 * Kml writing support added
61
 *
62
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
63
 * Add KML reading support
64
 *
65
 *
66
 */
67
/**
68
 * It parses the linearRing KML tag. Example:
69
 * <p>
70
 * <pre>
71
 * <code>
72
 * &lt;LinearRing&gt;
73
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
74
 * &lt;/LinearRing&gt;
75
 * </code>
76
 * </pre>
77
 * </p> 
78
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
79
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#linearring
80
 */
81
public class LinearRingBinding {
82

    
83
        /**
84
         * It parses the linearRing tag
85
         * @param parser
86
         * The XML parser
87
         * @param handler
88
         * The GPE parser that contains the content handler and
89
         * the error handler
90
         * @return
91
         * It retuns a matrix of doubles with 3 columns (x,y,z) and
92
         * one row for each coordinate.
93
         * @throws IOException 
94
         * @throws XmlPullParserException 
95
         * @throws XmlPullParserException
96
         * @throws IOException
97
         */
98
        public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
99
                boolean endFeature = false;
100
                int currentTag;
101
                double[][] coordinates = null;
102

    
103
                String tag = parser.getName();
104
                currentTag = parser.getEventType();
105

    
106
                while (!endFeature){
107
                        switch(currentTag){
108
                        case KXmlParser.START_TAG:
109
                                if (tag.compareTo(KmlTags.COORDINATES) == 0){
110
                                        coordinates = CoordinatesTypeBinding.parse(parser, handler);
111
                                }
112
                                break;
113
                        case KXmlParser.END_TAG:
114
                                if (tag.compareTo(KmlTags.LINEARRING) == 0){                                                
115
                                        endFeature = true;
116
                                }
117
                                break;
118
                        case KXmlParser.TEXT:                                        
119

    
120
                                break;
121
                        }
122
                        if (!endFeature){                                        
123
                                currentTag = parser.next();
124
                                tag = parser.getName();
125
                        }
126
                }                        
127
                return coordinates;
128
        }
129
}