svn-gvsig-desktop / branches / v10 / libraries / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / geometries / BoxTypeBinding.java @ 18882
History | View | Annotate | Download (4.61 KB)
1 | 18286 | jpiera | package org.gvsig.gpe.gml.parser.v2.geometries; |
---|---|---|---|
2 | |||
3 | import java.io.IOException; |
||
4 | |||
5 | import org.gvsig.gpe.gml.GMLTags; |
||
6 | import org.gvsig.gpe.gml.GPEDefaultGmlParser; |
||
7 | import org.gvsig.gpe.gml.utils.CompareUtils; |
||
8 | import org.gvsig.gpe.gml.utils.CoordsContainer; |
||
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:BoxTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
|
||
56 | * $Log$
|
||
57 | * Revision 1.5 2007/05/24 07:29:47 csanchez
|
||
58 | * A?adidos Alias GML2
|
||
59 | *
|
||
60 | * Revision 1.4 2007/05/14 11:18:51 jorpiell
|
||
61 | * ProjectionFactory updated
|
||
62 | *
|
||
63 | * Revision 1.3 2007/05/14 09:31:06 jorpiell
|
||
64 | * Add the a new class to compare tags
|
||
65 | *
|
||
66 | * Revision 1.2 2007/05/08 10:24:16 jorpiell
|
||
67 | * Add comments to create javadocs
|
||
68 | *
|
||
69 | * Revision 1.1 2007/05/07 12:58:42 jorpiell
|
||
70 | * Add some methods to manage the multigeometries
|
||
71 | *
|
||
72 | *
|
||
73 | */
|
||
74 | /**
|
||
75 | * It parses a gml:BoxType object. Example:
|
||
76 | * <p>
|
||
77 | * <pre>
|
||
78 | * <code>
|
||
79 | * <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
|
||
80 | * <gml:coord><gml:X>0</gml:X><gml:Y>0</gml:Y></gml:coord>
|
||
81 | * <gml:coord><gml:X>50</gml:X><gml:Y>50</gml:Y></gml:coord>
|
||
82 | * </gml:Box>
|
||
83 | * </code>
|
||
84 | * </pre>
|
||
85 | * </p>
|
||
86 | * @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
||
87 | */
|
||
88 | public class BoxTypeBinding extends GeometryBinding{ |
||
89 | |||
90 | /**
|
||
91 | * It parses the gml:Box tag
|
||
92 | * @param parser
|
||
93 | * The XML parser
|
||
94 | * @param handler
|
||
95 | * The GPE parser that contains the content handler and
|
||
96 | * the error handler
|
||
97 | * @return
|
||
98 | * The Bounding box
|
||
99 | * @throws XmlPullParserException
|
||
100 | * @throws IOException
|
||
101 | */
|
||
102 | public Object parse(XmlPullParser parser,GPEDefaultGmlParser handler) throws XmlPullParserException, IOException { |
||
103 | boolean endFeature = false; |
||
104 | int currentTag;
|
||
105 | CoordsContainer coordsContainer = null;
|
||
106 | Object bbox = null; |
||
107 | |||
108 | super.setAtributtes(parser, handler.getErrorHandler());
|
||
109 | |||
110 | String tag = parser.getName();
|
||
111 | currentTag = parser.getEventType(); |
||
112 | |||
113 | while (!endFeature){
|
||
114 | switch(currentTag){
|
||
115 | case KXmlParser.START_TAG:
|
||
116 | if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_COORDINATES)){
|
||
117 | double[][] coordinates = handler.getProfile().getCoordinatesTypeBinding().parse(parser, handler); |
||
118 | bbox = handler.getContentHandler().startBbox(id, |
||
119 | coordinates[0],
|
||
120 | coordinates[1],
|
||
121 | coordinates[2],
|
||
122 | srsName); |
||
123 | }else if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_COORD)){ |
||
124 | double[] coordinates = handler.getProfile().getCoordTypeBinding(). |
||
125 | parse(parser, handler); |
||
126 | if (coordsContainer == null){ |
||
127 | coordsContainer = new CoordsContainer();
|
||
128 | } |
||
129 | coordsContainer.addCoordinates(coordinates); |
||
130 | } |
||
131 | break;
|
||
132 | case KXmlParser.END_TAG:
|
||
133 | if (CompareUtils.compareWithOutNamespace(tag,GMLTags.GML_BOX)){
|
||
134 | endFeature = true;
|
||
135 | //If the file contains the COORD tag instead of the
|
||
136 | //coordinates
|
||
137 | if (coordsContainer != null){ |
||
138 | double[][] coordinates = coordsContainer.getCoordinates(); |
||
139 | bbox = handler.getContentHandler().startBbox(id, |
||
140 | coordinates[0],
|
||
141 | coordinates[1],
|
||
142 | coordinates[2],
|
||
143 | srsName); |
||
144 | } |
||
145 | handler.getContentHandler().endBbox(bbox); |
||
146 | } |
||
147 | break;
|
||
148 | case KXmlParser.TEXT:
|
||
149 | |||
150 | break;
|
||
151 | } |
||
152 | if (!endFeature){
|
||
153 | currentTag = parser.next(); |
||
154 | tag = parser.getName(); |
||
155 | } |
||
156 | } |
||
157 | return bbox;
|
||
158 | } |
||
159 | } |