root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / writer / v21 / geometries / LatLonAltBoxWriter.java @ 21966
History | View | Annotate | Download (4.16 KB)
1 |
package org.gvsig.gpe.kml.writer.v21.geometries; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.kml.utils.Kml2_1_Tags; |
6 |
import org.gvsig.gpe.kml.writer.GPEKmlWriterHandlerImplementor; |
7 |
import org.gvsig.gpe.writer.ICoordinateSequence; |
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamWriter; |
9 |
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 |
*
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
13 |
*
|
14 |
* This program is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU General Public License
|
16 |
* as published by the Free Software Foundation; either version 2
|
17 |
* of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This program is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* GNU General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU General Public License
|
25 |
* along with this program; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
27 |
*
|
28 |
* For more information, contact:
|
29 |
*
|
30 |
* Generalitat Valenciana
|
31 |
* Conselleria d'Infraestructures i Transport
|
32 |
* Av. Blasco Ib??ez, 50
|
33 |
* 46010 VALENCIA
|
34 |
* SPAIN
|
35 |
*
|
36 |
* +34 963862235
|
37 |
* gvsig@gva.es
|
38 |
* www.gvsig.gva.es
|
39 |
*
|
40 |
* or
|
41 |
*
|
42 |
* IVER T.I. S.A
|
43 |
* Salamanca 50
|
44 |
* 46005 Valencia
|
45 |
* Spain
|
46 |
*
|
47 |
* +34 963163400
|
48 |
* dac@iver.es
|
49 |
*/
|
50 |
/* CVS MESSAGES:
|
51 |
*
|
52 |
* $Id: LatLonAltBoxWriter.java 361 2008-01-10 08:41:21Z jpiera $
|
53 |
* $Log$
|
54 |
* Revision 1.3 2007/05/16 09:30:09 jorpiell
|
55 |
* the writting methods has to have the errorHandler argument
|
56 |
*
|
57 |
* Revision 1.2 2007/05/09 08:36:23 jorpiell
|
58 |
* Add the bbox to the layer
|
59 |
*
|
60 |
* Revision 1.1 2007/05/08 07:53:08 jorpiell
|
61 |
* Add comments to the writers
|
62 |
*
|
63 |
*
|
64 |
*/
|
65 |
/**
|
66 |
* This class writes a LatLonAltBox Kml tag. Example:
|
67 |
* <p>
|
68 |
* <pre>
|
69 |
* <code>
|
70 |
* <LatLonAltBox>
|
71 |
* <north>43.374</north>
|
72 |
* <south>42.983</south>
|
73 |
* <east>-0.335</east>
|
74 |
* <west>-1.423</west>
|
75 |
* <minAltitude>0</minAltitude>
|
76 |
* <maxAltitude>0</maxAltitude>
|
77 |
* </LatLonAltBox>
|
78 |
* </code>
|
79 |
* </pre>
|
80 |
* </p>
|
81 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
82 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#latlonaltbox
|
83 |
*/
|
84 |
public class LatLonAltBoxWriter { |
85 |
|
86 |
/**
|
87 |
* It writes the LatLonAltBox init tag and its fields
|
88 |
* @param writer
|
89 |
* Writer to write the labels
|
90 |
* @param handler
|
91 |
* The writer handler implementor
|
92 |
* @param coords
|
93 |
* A coordinates iterator.
|
94 |
* @throws IOException
|
95 |
*/
|
96 |
public void start(IXmlStreamWriter writer, GPEKmlWriterHandlerImplementor handler, |
97 |
ICoordinateSequence coords) throws IOException{ |
98 |
double[] minBuffer = new double[coords.iterator().getDimension()]; |
99 |
double[] maxBuffer = new double[coords.iterator().getDimension()]; |
100 |
//TODO what happends if the length is < 3!!! If the iterator only has 1 element
|
101 |
if (coords.iterator().hasNext()){
|
102 |
coords.iterator().next(minBuffer); |
103 |
} |
104 |
if (coords.iterator().hasNext()){
|
105 |
coords.iterator().next(maxBuffer); |
106 |
} |
107 |
writer.writeStartElement(Kml2_1_Tags.LATLONALTBOX); |
108 |
writer.writeStartElement(Kml2_1_Tags.NORTH); |
109 |
writer.writeValue(maxBuffer[1]);
|
110 |
writer.writeEndElement(); |
111 |
writer.writeStartElement(Kml2_1_Tags.SOUTH); |
112 |
writer.writeValue(minBuffer[1]);
|
113 |
writer.writeEndElement(); |
114 |
writer.writeStartElement(Kml2_1_Tags.EAST); |
115 |
writer.writeValue(maxBuffer[0]);
|
116 |
writer.writeEndElement(); |
117 |
writer.writeStartElement(Kml2_1_Tags.WEST); |
118 |
writer.writeValue(minBuffer[0]);
|
119 |
writer.writeEndElement(); |
120 |
writer.writeStartElement(Kml2_1_Tags.MINALTITUDE); |
121 |
writer.writeValue(minBuffer[2]);
|
122 |
writer.writeEndElement(); |
123 |
writer.writeStartElement(Kml2_1_Tags.MAXALTITUDE); |
124 |
writer.writeValue(maxBuffer[2]);
|
125 |
writer.writeEndElement(); |
126 |
} |
127 |
|
128 |
/**
|
129 |
/**
|
130 |
* It writes the LatLonAltBox end tag and its fields
|
131 |
* @param writer
|
132 |
* Writer to write the labels
|
133 |
* @param handler
|
134 |
* The writer handler implementor
|
135 |
* @throws IOException
|
136 |
*/
|
137 |
public void end(IXmlStreamWriter writer, GPEKmlWriterHandlerImplementor hanlder) throws IOException{ |
138 |
writer.writeEndElement(); |
139 |
} |
140 |
} |