root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / bindings / geometries / LinearRingTypeBinding.java @ 11475
History | View | Annotate | Download (3.45 KB)
1 |
package org.gvsig.gpe.gml.bindings.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.gml.GMLTags; |
6 |
import org.gvsig.gpe.gml.GPEGmlParser; |
7 |
import org.gvsig.gpe.gml.utils.CoordsContainer; |
8 |
import org.xmlpull.v1.XmlPullParser; |
9 |
import org.xmlpull.v1.XmlPullParserException; |
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: LinearRingTypeBinding.java 11475 2007-05-07 12:58:42Z jorpiell $
|
54 |
* $Log$
|
55 |
* Revision 1.1 2007-05-07 12:58:42 jorpiell
|
56 |
* Add some methods to manage the multigeometries
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
/**
|
61 |
* It parses a gml:linearRingType object. Example:
|
62 |
* <p>
|
63 |
* <pre>
|
64 |
* <code>
|
65 |
* <LinearRing>
|
66 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates>
|
67 |
* </LinearRing>
|
68 |
* </code>
|
69 |
* </pre>
|
70 |
* </p>
|
71 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
72 |
*/
|
73 |
public class LinearRingTypeBinding { |
74 |
|
75 |
/**
|
76 |
* It parses the gml:LinearRing tag
|
77 |
* @param parser
|
78 |
* The XML parser
|
79 |
* @param handler
|
80 |
* The GPE parser that contains the content handler and
|
81 |
* the error handler
|
82 |
* @return
|
83 |
* An array of coordinates
|
84 |
* @throws XmlPullParserException
|
85 |
* @throws IOException
|
86 |
*/
|
87 |
public static double[][] parse(XmlPullParser parser,GPEGmlParser handler) throws XmlPullParserException, IOException{ |
88 |
boolean endFeature = false; |
89 |
int currentTag;
|
90 |
CoordsContainer coordsContainer = null;
|
91 |
double[][] coordinates = null; |
92 |
|
93 |
|
94 |
String tag = parser.getName();
|
95 |
currentTag = parser.getEventType(); |
96 |
|
97 |
while (!endFeature){
|
98 |
switch(currentTag){
|
99 |
case XmlPullParser.START_TAG:
|
100 |
if (tag.compareTo(GMLTags.GML_COORDINATES) == 0){ |
101 |
coordinates = CoordinatesTypeBinding.parse(parser, handler); |
102 |
}else if (tag.compareTo(GMLTags.GML_COORD) == 0){ |
103 |
double[] coord = CoordTypeBinding.parse(parser, handler); |
104 |
if (coordsContainer == null){ |
105 |
coordsContainer = new CoordsContainer();
|
106 |
} |
107 |
coordsContainer.addCoordinates(coord); |
108 |
} |
109 |
break;
|
110 |
case XmlPullParser.END_TAG:
|
111 |
if (tag.compareTo(GMLTags.GML_LINEARRING) == 0){ |
112 |
endFeature = true;
|
113 |
//If the file contains the COORD tag instead of the
|
114 |
//coordinates
|
115 |
if (coordsContainer != null){ |
116 |
coordinates = coordsContainer.getCoordinates(); |
117 |
} |
118 |
} |
119 |
break;
|
120 |
case XmlPullParser.TEXT:
|
121 |
|
122 |
break;
|
123 |
} |
124 |
if (!endFeature){
|
125 |
currentTag = parser.next(); |
126 |
tag = parser.getName(); |
127 |
} |
128 |
} |
129 |
|
130 |
return coordinates;
|
131 |
} |
132 |
} |