Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / writer / geometries / CoordWriter.java @ 11621

History | View | Annotate | Download (4.25 KB)

1
package org.gvsig.gpe.gml.writer.geometries;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.GPEErrorHandler;
6
import org.gvsig.gpe.xml.writer.Writer;
7

    
8
import org.gvsig.gpe.gml.GMLTags;
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: CoordWriter.java 11621 2007-05-14 11:18:12Z jorpiell $
53
 * $Log$
54
 * Revision 1.6  2007-05-14 11:18:12  jorpiell
55
 * Add the ErrorHandler to all the methods
56
 *
57
 * Revision 1.5  2007/05/08 10:24:16  jorpiell
58
 * Add comments to create javadocs
59
 *
60
 * Revision 1.4  2007/04/14 16:07:30  jorpiell
61
 * The writer has been created
62
 *
63
 * Revision 1.3  2007/04/13 13:16:00  jorpiell
64
 * Add the multiple geometries
65
 *
66
 * Revision 1.2  2007/04/12 17:06:44  jorpiell
67
 * First GML writing tests
68
 *
69
 * Revision 1.1  2007/04/12 11:36:15  jorpiell
70
 * Added new geometry writers
71
 *
72
 *
73
 */
74
/**
75
 * It parses a gml:CoordType object. Example:
76
 * <p>
77
 * <pre>
78
 * <code>
79
 * &lt;gml:coord&gt;&lt;gml:X&gt;0&lt;/gml:X&gt;&lt;gml:Y&gt;0&lt;/gml:Y&gt;&lt;/gml:coord&gt;
80
 * </code>
81
 * </pre>
82
 * </p> 
83
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
84
 */
85
public class CoordWriter {
86
        
87
        /**
88
         * It writes a gml:Coord tag
89
         * @param writer
90
         * Writer to write the labels
91
         * @param errorHandler
92
         * To add the errors
93
         * @param x
94
         * X coordinate 
95
         * @param y
96
         * Y coordinate
97
         * @param z
98
         * Z coordinate
99
         * @throws IOException
100
         */
101
        public static void write(Writer writer, GPEErrorHandler errorHandler,double x, double y,
102
                        double z) throws IOException{
103
                        writer.write("<" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
104
                        writeOneCoordinate(writer,errorHandler,x,y,z);
105
                        writer.write("</" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
106
        }
107
        
108
        /**
109
         * It writes a gml:Coord tag list
110
         * @param writer
111
         * Writer to write the labels
112
         * @param errorHandler
113
         * To add the errors
114
         * @param x
115
         * X coordinates
116
         * @param y
117
         * Y coordinates
118
         * @param z
119
         * Z coordinates
120
         * @throws IOException
121
         */
122
        public static void write(Writer writer, GPEErrorHandler errorHandler,double[] x, double[] y,
123
                        double[] z) throws IOException{
124
                for (int i=0 ; i<x.length ; i++){
125
                        writer.write("\n");
126
                        writer.write("<" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
127
                        writeOneCoordinate(writer,errorHandler,x[i],y[i],z[i]);
128
                        writer.write("</" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
129
                }
130
        }
131
        
132
        /**
133
         * Writes the content of a gml:coord tag
134
         * @param writer
135
         * Writer to write the labels
136
          @param x
137
         * X coordinate
138
         * @param y
139
         * Y coordinates
140
         * @param z
141
         * Z coordinate
142
         * @throws IOException
143
         */
144
        private static void writeOneCoordinate(Writer writer, GPEErrorHandler errorHandler,double x, double y,
145
                        double z) throws IOException{                
146
                writer.write("<" +  GMLTags.GML_NAMESPACE + ":" + "X>");
147
                DoubleWriter.write(writer,errorHandler,x);
148
                writer.write("</" +  GMLTags.GML_NAMESPACE + ":" + "X>");                
149
                writer.write("<" +  GMLTags.GML_NAMESPACE + ":" + "Y>");
150
                DoubleWriter.write(writer,errorHandler,y);
151
                writer.write("</" +  GMLTags.GML_NAMESPACE + ":" + "Y>");                
152
                writer.write("<" +  GMLTags.GML_NAMESPACE + ":" + "Z>");
153
                DoubleWriter.write(writer,errorHandler,z);
154
                writer.write("</" +  GMLTags.GML_NAMESPACE + ":" + "Z>");                
155
        }
156
}