Statistics
| Revision:

root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / binfings / geometries / LineStringTypeBinding.java @ 10637

History | View | Annotate | Download (3.29 KB)

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

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

    
6
import org.gvsig.gpe.gml.factories.IGeometriesFactory;
7
import org.gvsig.gpe.kml.KmlTags;
8
import org.gvsig.gpe.kml.bindings.AbstractComplexBinding;
9
import org.gvsig.gpe.kml.engine.IReaderFile;
10
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
11
import org.kxml2.io.KXmlParser;
12
import org.xmlpull.v1.XmlPullParserException;
13

    
14
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
15
 *
16
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
17
 *
18
 * This program is free software; you can redistribute it and/or
19
 * modify it under the terms of the GNU General Public License
20
 * as published by the Free Software Foundation; either version 2
21
 * of the License, or (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
31
 *
32
 * For more information, contact:
33
 *
34
 *  Generalitat Valenciana
35
 *   Conselleria d'Infraestructures i Transport
36
 *   Av. Blasco Ib??ez, 50
37
 *   46010 VALENCIA
38
 *   SPAIN
39
 *
40
 *      +34 963862235
41
 *   gvsig@gva.es
42
 *      www.gvsig.gva.es
43
 *
44
 *    or
45
 *
46
 *   IVER T.I. S.A
47
 *   Salamanca 50
48
 *   46005 Valencia
49
 *   Spain
50
 *
51
 *   +34 963163400
52
 *   dac@iver.es
53
 */
54
/* CVS MESSAGES:
55
 *
56
 * $Id: LineStringTypeBinding.java 10637 2007-03-07 08:19:11Z jorpiell $
57
 * $Log$
58
 * Revision 1.1  2007-03-07 08:19:10  jorpiell
59
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
60
 *
61
 * Revision 1.1  2007/02/28 11:48:31  csanchez
62
 * *** empty log message ***
63
 *
64
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
65
 * A?adidos los proyectos de kml y gml antiguos
66
 *
67
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
68
 * A?adido el driver de KML
69
 *
70
 *
71
 */
72
/**
73
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
74
 */
75
public class LineStringTypeBinding extends AbstractComplexBinding{
76

    
77
        public LineStringTypeBinding(IGeometriesFactory gFactory) {
78
                super(gFactory);
79
                // TODO Auto-generated constructor stub
80
        }        
81

    
82
        public Object parse(IReaderFile reader)throws KmlBodyParseException {
83
                boolean endFeature = false;
84
                int currentTag;
85
                Object geometry = null;
86
                        
87
                try {
88
                        String tag = reader.getName();
89
                        currentTag = reader.getEventType();
90
                        
91
                        while (!endFeature){
92
                                switch(currentTag){
93
                                case KXmlParser.START_TAG:
94
                                        if (tag.compareTo(KmlTags.COORDINATES) == 0){
95
                                                ArrayList coordinates = (ArrayList)new CoordinatesTypeBinding(getGFactory()).parse(reader);
96
                                                geometry = getGFactory().createMultipoint2D((double[])coordinates.get(0),(double[])coordinates.get(1));
97
                                        }
98
                                        break;
99
                                case KXmlParser.END_TAG:
100
                                        if (tag.compareTo(KmlTags.LINESTRING) == 0){                                                
101
                                                endFeature = true;
102
                                        }
103
                                        break;
104
                                case KXmlParser.TEXT:                                        
105
                                        
106
                                        break;
107
                                }
108
                                if (!endFeature){                                        
109
                                        currentTag = reader.next();
110
                                        tag = reader.getName();
111
                                }
112
                        }                        
113
                } catch (XmlPullParserException e) {
114
                        throw new KmlBodyParseException(e);
115
                } catch (IOException e) {
116
                        throw new KmlBodyParseException(e);
117
                }
118
                return geometry;        
119
        }
120
}