root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / writer / geometries / CoordinatesWriter.java @ 11484
History | View | Annotate | Download (3.81 KB)
1 |
package org.gvsig.gpe.kml.writer.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.kml.KmlTags; |
6 |
import org.gvsig.gpe.xml.writer.Writer; |
7 |
|
8 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
9 |
*
|
10 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
11 |
*
|
12 |
* This program is free software; you can redistribute it and/or
|
13 |
* modify it under the terms of the GNU General Public License
|
14 |
* as published by the Free Software Foundation; either version 2
|
15 |
* of the License, or (at your option) any later version.
|
16 |
*
|
17 |
* This program is distributed in the hope that it will be useful,
|
18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
* GNU General Public License for more details.
|
21 |
*
|
22 |
* You should have received a copy of the GNU General Public License
|
23 |
* along with this program; if not, write to the Free Software
|
24 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
25 |
*
|
26 |
* For more information, contact:
|
27 |
*
|
28 |
* Generalitat Valenciana
|
29 |
* Conselleria d'Infraestructures i Transport
|
30 |
* Av. Blasco Ib??ez, 50
|
31 |
* 46010 VALENCIA
|
32 |
* SPAIN
|
33 |
*
|
34 |
* +34 963862235
|
35 |
* gvsig@gva.es
|
36 |
* www.gvsig.gva.es
|
37 |
*
|
38 |
* or
|
39 |
*
|
40 |
* IVER T.I. S.A
|
41 |
* Salamanca 50
|
42 |
* 46005 Valencia
|
43 |
* Spain
|
44 |
*
|
45 |
* +34 963163400
|
46 |
* dac@iver.es
|
47 |
*/
|
48 |
/* CVS MESSAGES:
|
49 |
*
|
50 |
* $Id: CoordinatesWriter.java 11484 2007-05-08 07:53:08Z jorpiell $
|
51 |
* $Log$
|
52 |
* Revision 1.2 2007-05-08 07:53:08 jorpiell
|
53 |
* Add comments to the writers
|
54 |
*
|
55 |
* Revision 1.1 2007/04/14 16:08:07 jorpiell
|
56 |
* Kml writing support added
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
/**
|
61 |
* This class writes a coordinates Kml tag. Example:
|
62 |
* <p>
|
63 |
* <pre>
|
64 |
* <code>
|
65 |
* <coordinates>60.0,60.0 60.0,90.0 90.0,90.0</coordinates>
|
66 |
* </code>
|
67 |
* </pre>
|
68 |
* </p>
|
69 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
70 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#coordinates
|
71 |
*/
|
72 |
public class CoordinatesWriter { |
73 |
|
74 |
/**
|
75 |
* It writes the coordinates tag and its value.
|
76 |
* @param writer
|
77 |
* Writer to write the labels
|
78 |
* @param longitude
|
79 |
* Longitude >= -180 and <= 180
|
80 |
* @param latitude
|
81 |
* Latitude >= -90 and <= 90
|
82 |
* @param altitude
|
83 |
* Meters above sea level
|
84 |
* @throws IOException
|
85 |
*/
|
86 |
public static void write(Writer writer,double longitude, double latitude, |
87 |
double altitude) throws IOException{ |
88 |
writer.write("\n");
|
89 |
writer.write("<" + KmlTags.COORDINATES + ">"); |
90 |
writeOneCoordinate(writer,longitude,latitude,altitude); |
91 |
writer.write("</" + KmlTags.COORDINATES + ">"); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* It writes an array of coordinates written using
|
96 |
* the kml coordinates tag
|
97 |
* @param writer
|
98 |
* Writer to write the labels
|
99 |
* @param longitudes
|
100 |
* Array of longitudes (>= -180 and <= 180)
|
101 |
* @param latitudes
|
102 |
* Array of latitudes (>= -90 and <= 90)
|
103 |
* @param altitudes
|
104 |
* Array of altitudes (Meters above sea level)
|
105 |
* @throws IOException
|
106 |
*/
|
107 |
public static void write(Writer writer,double[] longitudes, double[] latitudes, |
108 |
double[] altitudes) throws IOException{ |
109 |
writer.write("\n");
|
110 |
writer.write("<" + KmlTags.COORDINATES + ">"); |
111 |
for (int i=0 ; i<longitudes.length ; i++){ |
112 |
writeOneCoordinate(writer,longitudes[i],latitudes[i],altitudes[i]); |
113 |
if (i<longitudes.length-1){ |
114 |
writer.write(KmlTags.TUPLES_SEPARATOR); |
115 |
} |
116 |
} |
117 |
writer.write("</" + KmlTags.COORDINATES + ">"); |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Writes the content of a coordinates kml tag
|
122 |
* @param writer
|
123 |
* Writer to write the labels
|
124 |
* @param x
|
125 |
* Longitude >= -180 and <= 180
|
126 |
* @param y
|
127 |
* Latitude >= -90 and <= 90
|
128 |
* @param altitude
|
129 |
* Meters above sea level
|
130 |
* @throws IOException
|
131 |
*/
|
132 |
private static void writeOneCoordinate(Writer writer,double x, double y, |
133 |
double z) throws IOException{ |
134 |
DoubleWriter.write(writer,x); |
135 |
writer.write(KmlTags.COORDINATES_SEPARATOR); |
136 |
DoubleWriter.write(writer,y); |
137 |
writer.write(KmlTags.COORDINATES_SEPARATOR); |
138 |
DoubleWriter.write(writer,z); |
139 |
} |
140 |
} |