Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / geometries / PolygonTypeBinding.java @ 19680

History | View | Annotate | Download (4.94 KB)

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

    
3
import java.io.IOException;
4

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

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

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

    
131
                String tag = parser.getName();
132
                currentTag = parser.getEventType();
133

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

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

    
169
                return polygon;
170
        }
171
}