Statistics
| Revision:

root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / bindings / geometries / CoordinatesTypeBinding.java @ 11205

History | View | Annotate | Download (3.66 KB)

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

    
3
import java.io.IOException;
4
import java.util.ArrayList;
5

    
6
import org.gvsig.gpe.kml.GPEKmlParser;
7
import org.gvsig.gpe.kml.KmlTags;
8
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
9
import org.kxml2.io.KXmlParser;
10
import org.xmlpull.v1.XmlPullParser;
11
import org.xmlpull.v1.XmlPullParserException;
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: CoordinatesTypeBinding.java 11205 2007-04-13 13:16:21Z jorpiell $
56
 * $Log$
57
 * Revision 1.1  2007-04-13 13:16:21  jorpiell
58
 * Add KML reading support
59
 *
60
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
61
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
62
 *
63
 * Revision 1.1  2007/02/28 11:48:31  csanchez
64
 * *** empty log message ***
65
 *
66
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
67
 * A?adidos los proyectos de kml y gml antiguos
68
 *
69
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
70
 * A?adido el driver de KML
71
 *
72
 *
73
 */
74
/**
75
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
76
 */
77
public class CoordinatesTypeBinding {
78
        
79
        /**
80
         * It retuns a matrix of doubles with 3 columns (x,y,z) and
81
         * one row for each coordinate.
82
         * @param parser
83
         * @param handler
84
         * @return
85
         * @throws KmlBodyParseException
86
         */
87
        public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException  {
88
                boolean endFeature = false;
89
                int currentTag;
90
                
91
                double[][] aCoordinates = null;
92
                
93
                try {
94
                        String tag = parser.getName();
95
                        currentTag = parser.getEventType();
96
                        
97
                        while (!endFeature){
98
                                switch(currentTag){
99
                                case KXmlParser.START_TAG:
100
                                        if (tag.compareTo(KmlTags.COORDINATES) == 0){
101
                                                parser.next();
102
                                                String[] coordinates = parser.getText().split("\n");
103
                                                aCoordinates = new double[3][coordinates.length];
104
                                                for (int i=0 ; i<coordinates.length ; i++){                                        
105
                                                        String[] coordinate = coordinates[i].trim().split(KmlTags.COORDINATES_SEPARATOR);
106
                                                        aCoordinates[0][i] = Double.valueOf(coordinate[0]).doubleValue();
107
                                                        aCoordinates[1][i] = Double.valueOf(coordinate[1]).doubleValue();
108
                                                        aCoordinates[2][i] = Double.valueOf(coordinate[2]).doubleValue();
109
                                                }                                        
110
                                        }
111
                                        break;
112
                                case KXmlParser.END_TAG:
113
                                        if (tag.compareTo(KmlTags.COORDINATES) == 0){                                                
114
                                                endFeature = true;
115
                                        }
116
                                        break;
117
                                case KXmlParser.TEXT:                                        
118
                                        
119
                                        break;
120
                                }
121
                                if (!endFeature){                                        
122
                                        currentTag = parser.next();
123
                                        tag = parser.getName();
124
                                }
125
                        }                        
126
                } catch (XmlPullParserException e) {
127
                        throw new KmlBodyParseException(e);
128
                } catch (IOException e) {
129
                        throw new KmlBodyParseException(e);
130
                }
131
                return aCoordinates;        
132
        }
133
        
134
}