root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / bindings / geometries / CoordinatesBinding.java @ 11464
History | View | Annotate | Download (3.36 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.kxml2.io.KXmlParser; |
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: CoordinatesBinding.java 11464 2007-05-07 07:08:02Z jorpiell $
|
54 |
* $Log$
|
55 |
* Revision 1.1 2007-05-07 07:06:46 jorpiell
|
56 |
* Add a constructor with the name and the description fields
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
/**
|
61 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
62 |
*/
|
63 |
public class CoordinatesBinding { |
64 |
|
65 |
/**
|
66 |
* It retuns a matrix of doubles with 3 columns (x,y,z) and
|
67 |
* one row for each coordinate.
|
68 |
* @param parser
|
69 |
* @param handler
|
70 |
* @return
|
71 |
* @throws XmlPullParserException
|
72 |
* @throws IOException
|
73 |
* @throws KmlBodyParseException
|
74 |
*/
|
75 |
public static double[][] parse(XmlPullParser parser,GPEGmlParser handler) throws XmlPullParserException, IOException { |
76 |
boolean endFeature = false; |
77 |
int currentTag;
|
78 |
|
79 |
double[][] aCoordinates = null; |
80 |
|
81 |
String tag = parser.getName();
|
82 |
currentTag = parser.getEventType(); |
83 |
|
84 |
while (!endFeature){
|
85 |
switch(currentTag){
|
86 |
case KXmlParser.START_TAG:
|
87 |
if (tag.compareTo(GMLTags.GML_COORDINATES) == 0){ |
88 |
parser.next(); |
89 |
//Calcular los car?cteres de separaci?n
|
90 |
String TUPLES_SEPARATOR = null; |
91 |
String COORDINATES_SEPARATOR = null; |
92 |
String DOUBLE_SEPARATOR = null; |
93 |
|
94 |
String[] coordinates = parser.getText().split(TUPLES_SEPARATOR); |
95 |
aCoordinates = new double[3][coordinates.length]; |
96 |
for (int i=0 ; i<coordinates.length ; i++){ |
97 |
String[] coordinate = coordinates[i].trim().split(COORDINATES_SEPARATOR); |
98 |
aCoordinates[0][i] = Double.valueOf(coordinate[0]).doubleValue(); |
99 |
aCoordinates[1][i] = Double.valueOf(coordinate[1]).doubleValue(); |
100 |
//Tener en cuenta que puede no haber una tercera coordenada
|
101 |
aCoordinates[2][i] = Double.valueOf(coordinate[2]).doubleValue(); |
102 |
} |
103 |
} |
104 |
break;
|
105 |
case KXmlParser.END_TAG:
|
106 |
if (tag.compareTo(GMLTags.GML_COORDINATES) == 0){ |
107 |
endFeature = true;
|
108 |
} |
109 |
break;
|
110 |
case KXmlParser.TEXT:
|
111 |
|
112 |
break;
|
113 |
} |
114 |
if (!endFeature){
|
115 |
currentTag = parser.next(); |
116 |
tag = parser.getName(); |
117 |
} |
118 |
} |
119 |
|
120 |
return aCoordinates;
|
121 |
} |
122 |
|
123 |
} |