svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / binfings / geometries / CoordinatesTypeBinding.java @ 10637
History | View | Annotate | Download (3.7 KB)
1 |
package org.gvsig.gpe.kml.binfings.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
7 |
import org.gvsig.gpe.kml.KmlTags; |
8 |
import org.gvsig.gpe.kml.bindings.AbstractComplexBinding; |
9 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
10 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
11 |
import org.kxml2.io.KXmlParser; |
12 |
import org.xmlpull.v1.XmlPullParserException; |
13 |
|
14 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
15 |
*
|
16 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
17 |
*
|
18 |
* This program is free software; you can redistribute it and/or
|
19 |
* modify it under the terms of the GNU General Public License
|
20 |
* as published by the Free Software Foundation; either version 2
|
21 |
* of the License, or (at your option) any later version.
|
22 |
*
|
23 |
* This program is distributed in the hope that it will be useful,
|
24 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
26 |
* GNU General Public License for more details.
|
27 |
*
|
28 |
* You should have received a copy of the GNU General Public License
|
29 |
* along with this program; if not, write to the Free Software
|
30 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
31 |
*
|
32 |
* For more information, contact:
|
33 |
*
|
34 |
* Generalitat Valenciana
|
35 |
* Conselleria d'Infraestructures i Transport
|
36 |
* Av. Blasco Ib??ez, 50
|
37 |
* 46010 VALENCIA
|
38 |
* SPAIN
|
39 |
*
|
40 |
* +34 963862235
|
41 |
* gvsig@gva.es
|
42 |
* www.gvsig.gva.es
|
43 |
*
|
44 |
* or
|
45 |
*
|
46 |
* IVER T.I. S.A
|
47 |
* Salamanca 50
|
48 |
* 46005 Valencia
|
49 |
* Spain
|
50 |
*
|
51 |
* +34 963163400
|
52 |
* dac@iver.es
|
53 |
*/
|
54 |
/* CVS MESSAGES:
|
55 |
*
|
56 |
* $Id: CoordinatesTypeBinding.java 10637 2007-03-07 08:19:11Z jorpiell $
|
57 |
* $Log$
|
58 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell
|
59 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML
|
60 |
*
|
61 |
* Revision 1.1 2007/02/28 11:48:31 csanchez
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell
|
65 |
* A?adidos los proyectos de kml y gml antiguos
|
66 |
*
|
67 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell
|
68 |
* A?adido el driver de KML
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
/**
|
73 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
74 |
*/
|
75 |
public class CoordinatesTypeBinding extends AbstractComplexBinding{ |
76 |
|
77 |
public CoordinatesTypeBinding(IGeometriesFactory gFactory) {
|
78 |
super(gFactory);
|
79 |
} |
80 |
|
81 |
public Object parse(IReaderFile reader) throws KmlBodyParseException { |
82 |
boolean endFeature = false; |
83 |
int currentTag;
|
84 |
ArrayList aCoordinates = new ArrayList(); |
85 |
|
86 |
try {
|
87 |
String tag = reader.getName();
|
88 |
currentTag = reader.getEventType(); |
89 |
|
90 |
while (!endFeature){
|
91 |
switch(currentTag){
|
92 |
case KXmlParser.START_TAG:
|
93 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
94 |
reader.next(); |
95 |
String[] coordinates = reader.getText().split("\n"); |
96 |
double[] x = new double[coordinates.length]; |
97 |
double[] y = new double[coordinates.length]; |
98 |
double[] z = new double[coordinates.length]; |
99 |
for (int i=0 ; i<coordinates.length ; i++){ |
100 |
String[] coordinate = coordinates[i].trim().split(KmlTags.COORDINATES_SEPARATOR); |
101 |
x[i] = Double.valueOf(coordinate[0]).doubleValue(); |
102 |
y[i] = Double.valueOf(coordinate[1]).doubleValue(); |
103 |
z[i] = Double.valueOf(coordinate[2]).doubleValue(); |
104 |
} |
105 |
aCoordinates.add(x); |
106 |
aCoordinates.add(y); |
107 |
aCoordinates.add(z); |
108 |
} |
109 |
break;
|
110 |
case KXmlParser.END_TAG:
|
111 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
112 |
endFeature = true;
|
113 |
} |
114 |
break;
|
115 |
case KXmlParser.TEXT:
|
116 |
|
117 |
break;
|
118 |
} |
119 |
if (!endFeature){
|
120 |
currentTag = reader.next(); |
121 |
tag = reader.getName(); |
122 |
} |
123 |
} |
124 |
} catch (XmlPullParserException e) {
|
125 |
throw new KmlBodyParseException(e); |
126 |
} catch (IOException e) { |
127 |
throw new KmlBodyParseException(e); |
128 |
} |
129 |
return aCoordinates;
|
130 |
} |
131 |
|
132 |
} |