root / org.gvsig.gpe / library / trunk / org.gvsig.gpe / org.gvsig.gpe.prov / org.gvsig.gpe.prov.gml / src / main / java / org / gvsig / gpe / prov / gml / parser / v2 / geometries / MultiGeometryTypeBinding.java @ 492
History | View | Annotate | Download (5.32 KB)
1 |
package org.gvsig.gpe.prov.gml.parser.v2.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.prov.gml.parser.GPEDefaultGmlParser; |
6 |
import org.gvsig.gpe.prov.gml.utils.GmlTags; |
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:MultiGeometryTypeBinding.java 371 2008-01-10 09:30:19Z jpiera $
|
54 |
* $Log$
|
55 |
* Revision 1.5 2007/05/14 11:18:51 jorpiell
|
56 |
* ProjectionFactory updated
|
57 |
*
|
58 |
* Revision 1.4 2007/05/14 09:52:53 jorpiell
|
59 |
* Nullpointer exception fixed
|
60 |
*
|
61 |
* Revision 1.3 2007/05/14 09:31:06 jorpiell
|
62 |
* Add the a new class to compare tags
|
63 |
*
|
64 |
* Revision 1.2 2007/05/08 10:24:16 jorpiell
|
65 |
* Add comments to create javadocs
|
66 |
*
|
67 |
* Revision 1.1 2007/05/07 12:58:42 jorpiell
|
68 |
* Add some methods to manage the multigeometries
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
/**
|
73 |
* It parses a gml:MultiGeometryType object. Example:
|
74 |
* <p>
|
75 |
* <pre>
|
76 |
* <code>
|
77 |
* <MultiGeometry gid="c731" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
|
78 |
* <geometryMember>
|
79 |
* <Point gid="P6776">
|
80 |
* <coord><X>50.0</X><Y>50.0</Y></coord>
|
81 |
* </Point>
|
82 |
* </geometryMember>
|
83 |
* <geometryMember>
|
84 |
* <LineString gid="L21216">
|
85 |
* <coord><X>0.0</X><Y>0.0</Y></coord>
|
86 |
* <coord><X>0.0</X><Y>50.0</Y></coord>
|
87 |
* <coord><X>100.0</X><Y>50.0</Y></coord>
|
88 |
* </LineString>
|
89 |
* </geometryMember>
|
90 |
* <geometryMember>
|
91 |
* <Polygon gid="_877789">
|
92 |
* <outerBoundaryIs>
|
93 |
* <LinearRing>
|
94 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
95 |
* </LinearRing>
|
96 |
* </outerBoundaryIs>
|
97 |
* </Polygon>
|
98 |
* </geometryMember>
|
99 |
* </MultiGeometry>
|
100 |
* </code>
|
101 |
* </pre>
|
102 |
* </p>
|
103 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
104 |
*/
|
105 |
public class MultiGeometryTypeBinding extends GeometryBinding{ |
106 |
|
107 |
/**
|
108 |
* It parses the gml:MultiGeometry tag
|
109 |
* @param parser
|
110 |
* The XML parser
|
111 |
* @param handler
|
112 |
* The GPE parser that contains the content handler and
|
113 |
* the error handler
|
114 |
* @return
|
115 |
* A multigeometry
|
116 |
* @throws XmlStreamException
|
117 |
* @throws IOException
|
118 |
*/
|
119 |
public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException { |
120 |
boolean endFeature = false; |
121 |
int currentTag;
|
122 |
Object multiGeometry = null; |
123 |
|
124 |
super.setAtributtes(parser, handler);
|
125 |
|
126 |
//multiGeometry = handler.getContentHandler().startMultiGeometry(id, srsName);
|
127 |
|
128 |
IQName tag = parser.getName(); |
129 |
currentTag = parser.getEventType(); |
130 |
|
131 |
while (!endFeature){
|
132 |
switch(currentTag){
|
133 |
case IXmlStreamReader.START_ELEMENT:
|
134 |
if (handler.getQNameComparator().equals(tag,GmlTags.GML_GEOMETRYMEMBER)){
|
135 |
Object geometry = handler.getProfile().getGeometryMemberTypeBinding().
|
136 |
parse(parser, handler); |
137 |
if (multiGeometry ==null){ |
138 |
if (geometry instanceof PolygonTypeBinding){ |
139 |
multiGeometry = handler.getContentHandler().startMultiPolygon(id, srsName); |
140 |
} else if (geometry instanceof LineStringTypeBinding){ |
141 |
multiGeometry = handler.getContentHandler().startMultiLineString(id, srsName); |
142 |
} else if (geometry instanceof PointTypeBinding){ |
143 |
multiGeometry = handler.getContentHandler().startMultiPoint(id, srsName); |
144 |
}else{
|
145 |
multiGeometry = handler.getContentHandler().startMultiGeometry(id, srsName); |
146 |
} |
147 |
} |
148 |
handler.getContentHandler().addGeometryToMultiGeometry(geometry, multiGeometry); |
149 |
} |
150 |
break;
|
151 |
case IXmlStreamReader.END_ELEMENT:
|
152 |
if (handler.getQNameComparator().equals(tag,GmlTags.GML_MULTIGEOMETRY)){
|
153 |
endFeature = true;
|
154 |
multiGeometry = handler.getContentHandler().endMultiGeometry(multiGeometry); |
155 |
} |
156 |
break;
|
157 |
case IXmlStreamReader.CHARACTERS:
|
158 |
|
159 |
break;
|
160 |
} |
161 |
if (!endFeature){
|
162 |
currentTag = parser.next(); |
163 |
tag = parser.getName(); |
164 |
} |
165 |
} |
166 |
return multiGeometry;
|
167 |
} |
168 |
} |