Statistics
| Revision:

root / org.gvsig.gpe / library / trunk / org.gvsig.gpe / org.gvsig.gpe.prov / org.gvsig.gpe.prov.kml / src / main / java / org / gvsig / gpe / prov / kml / parser / v21 / geometries / MultiGeometryBinding.java @ 492

History | View | Annotate | Download (5.16 KB)

1
package org.gvsig.gpe.prov.kml.parser.v21.geometries;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.prov.kml.parser.GPEDeafultKmlParser;
6
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags;
7
import org.gvsig.xmlpull.lib.api.stream.IQName;
8
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
9
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException;
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:MultiGeometryBinding.java 357 2008-01-09 17:50:08Z jpiera $
54
 * $Log$
55
 * Revision 1.2  2007/06/07 14:53:59  jorpiell
56
 * Add the schema support
57
 *
58
 * Revision 1.1  2007/05/15 12:37:45  jorpiell
59
 * Add multyGeometries
60
 *
61
 *
62
 */
63
/**
64
 * It parses a MultyGeometry tag. Example:
65
 * <p>
66
 * <pre>
67
 * <code>
68
 * &lt;MultiGeometry&gt;
69
 * &lt;Point gid="P6776"&gt;
70
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
71
 * &lt;/Point&gt;
72
 * &lt;Polygon gid="_877789"&gt;
73
 * &lt;outerBoundaryIs&gt;
74
 * &lt;LinearRing&gt;
75
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
76
 * &lt;/LinearRing&gt;
77
 * &lt;/outerBoundaryIs&gt;
78
 * &lt;/Polygon&gt;
79
 * &lt;MultiGeometry&gt;
80
 * </code>
81
 * </pre>
82
 * </p>
83
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
84
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#multigeometry
85
 */
86
public class MultiGeometryBinding {
87
        /**
88
         * It parses the MultiGeometry tag
89
         * @param parser
90
         * The XML parser
91
         * @param handler
92
         * The GPE parser that contains the content handler and
93
         * the error handler
94
         * @return
95
         * A multigeometry
96
         * @throws XmlStreamException
97
         * @throws IOException
98
         */
99
        public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
100
                boolean endFeature = false;
101
                int currentTag;
102
                Object multiGeometry = null;
103

    
104
                String id = handler.getProfile().getGeometryBinding().getID(parser, handler);
105

    
106
                //multiGeometry = handler.getContentHandler().startMultiGeometry(id, Kml2_1_Tags.DEFAULT_SRS);
107

    
108
                IQName tag = parser.getName();
109
                currentTag = parser.getEventType();
110

    
111
                while (!endFeature){
112
                        switch(currentTag){
113
                        case IXmlStreamReader.START_ELEMENT:
114
                                        if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.POINT)){
115
                                            if (multiGeometry == null){
116
                                                multiGeometry = handler.getContentHandler().startMultiPoint(id, Kml2_1_Tags.DEFAULT_SRS);
117
                                            }
118
                                            Object point = handler.getProfile().getPointTypeBinding().parse(parser, handler);
119
                                                handler.getContentHandler().addGeometryToMultiGeometry(point, multiGeometry);
120
                                        }else if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.LINESTRING)){
121
                       if (multiGeometry == null){
122
                            multiGeometry = handler.getContentHandler().startMultiLineString(id, Kml2_1_Tags.DEFAULT_SRS);
123
                        }
124
                                                Object lineString = handler.getProfile().getLineStringTypeBinding().parse(parser, handler);
125
                                                handler.getContentHandler().addGeometryToMultiGeometry(lineString, multiGeometry);
126
                                        }else if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.POLYGON)){
127
                       if (multiGeometry == null){
128
                            multiGeometry = handler.getContentHandler().startMultiPolygon(id, Kml2_1_Tags.DEFAULT_SRS);
129
                        }
130
                                                Object polygon = handler.getProfile().getPolygonTypeBinding().parse(parser, handler);
131
                                                handler.getContentHandler().addGeometryToMultiGeometry(polygon, multiGeometry);
132
                                        }else{
133
                       if (multiGeometry == null){
134
                           multiGeometry = handler.getContentHandler().startMultiGeometry(id, Kml2_1_Tags.DEFAULT_SRS);
135
                        }
136
                                        }
137
                                        break;
138
                                case IXmlStreamReader.END_ELEMENT:
139
                                        if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.MULTIGEOMETRY)){
140
                                                endFeature = true;
141
                                                multiGeometry = handler.getContentHandler().endMultiGeometry(multiGeometry);
142
                                        }
143
                                        break;
144
                                case IXmlStreamReader.CHARACTERS:
145

    
146
                                        break;
147
                                }
148
                                if (!endFeature){
149
                                        currentTag = parser.next();
150
                                        tag = parser.getName();
151
                                }
152
                        }
153
                return multiGeometry;
154
        }
155
}