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 / PolygonTypeBinding.java @ 264

History | View | Annotate | Download (5.14 KB)

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

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
6
import org.gvsig.gpe.prov.kml.parser.GPEDeafultKmlParser;
7
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags;
8
import org.gvsig.xmlpull.lib.api.stream.IQName;
9
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
10
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException;
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:PolygonTypeBinding.java 357 2008-01-09 17:50:08Z jpiera $
55
 * $Log$
56
 * Revision 1.2  2007/06/07 14:53:59  jorpiell
57
 * Add the schema support
58
 *
59
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
60
 * Refactoring of some package names
61
 *
62
 * Revision 1.5  2007/05/08 08:22:37  jorpiell
63
 * Add comments to create javadocs
64
 *
65
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
66
 * Writing tests updated
67
 *
68
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
69
 * Tests updating
70
 *
71
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
72
 * Kml writing support added
73
 *
74
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
75
 * Add KML reading support
76
 *
77
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
78
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
79
 *
80
 * Revision 1.1  2007/02/28 11:48:31  csanchez
81
 * *** empty log message ***
82
 *
83
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
84
 * A?adidos los proyectos de kml y gml antiguos
85
 *
86
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
87
 * A?adido el driver de KML
88
 *
89
 *
90
 */
91
/**
92
 * It writes a Polygon tag. Example:
93
 * <p>
94
 * <pre>
95
 * <code>
96
 * &lt;Polygon gid="_877789"&gt;
97
 * &lt;outerBoundaryIs&gt;
98
 * &lt;LinearRing&gt;
99
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
100
 * &lt;/LinearRing&gt;
101
 * &lt;/outerBoundaryIs&gt;
102
 * &lt;/Polygon&gt;
103
 * </code>
104
 * </pre>
105
 * </p> 
106
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
107
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#polygon
108
 */
109
public class PolygonTypeBinding {
110

    
111
        /**
112
         * It parses the Polygon tag
113
         * @param parser
114
         * The XML parser
115
         * @param handler
116
         * The GPE parser that contains the content handler and
117
         * the error handler
118
         * @return
119
         * A polygon
120
         * @throws IOException 
121
         * @throws XmlStreamException 
122
         * @throws XmlStreamException
123
         * @throws IOException
124
         */
125
        public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
126
                boolean endFeature = false;
127
                int currentTag;                        
128
                Object polygon = null;
129

    
130
                String id = handler.getProfile().getGeometryBinding().getID(parser, handler);                
131

    
132
                IQName tag = parser.getName();
133
                currentTag = parser.getEventType();
134

    
135
                while (!endFeature){
136
                        switch(currentTag){
137
                        case IXmlStreamReader.START_ELEMENT:
138
                                if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.OUTERBOUNDARYIS)){
139
                                        OuterBoundaryIsBinding coordinatesBinding = handler.getProfile().getOuterBoundaryIsBinding();
140
                                        ICoordinateIterator coordinatesIterator = coordinatesBinding.parse(parser, handler);
141
                                        polygon = handler.getContentHandler().startPolygon(id,
142
                                                        coordinatesIterator,
143
                                                        Kml2_1_Tags.DEFAULT_SRS);                                        
144
                                }else if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.INNERBOUNDARYIS)){
145
                                        InnerBoundaryIsBinding innerPolygonBinding = handler.getProfile().getInnerBoundaryIsBinding();
146
                                        ICoordinateIterator coordinatesIterator = innerPolygonBinding.parse(parser, handler);
147
                                        Object innerPolygon = handler.getContentHandler().startInnerPolygon(id,
148
                                                        coordinatesIterator,
149
                                                        Kml2_1_Tags.DEFAULT_SRS);        
150
                                        handler.getContentHandler().endInnerPolygon(innerPolygon);
151
                                        handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,polygon);
152
                                }
153
                                break;
154
                        case IXmlStreamReader.END_ELEMENT:
155
                                if (handler.getQNameComparator().equals(tag,Kml2_1_Tags.POLYGON)){                                                
156
                                        endFeature = true;
157
                                        polygon = handler.getContentHandler().endPolygon(polygon);
158
                                }
159
                                break;
160
                        case IXmlStreamReader.CHARACTERS:                                        
161

    
162
                                break;
163
                        }
164
                        if (!endFeature){                                        
165
                                currentTag = parser.next();
166
                                tag = parser.getName();
167
                        }
168
                }        
169

    
170
                return polygon;
171
        }
172
}