Statistics
| Revision:

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

History | View | Annotate | Download (4.36 KB)

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

    
3
import java.io.IOException;
4
import org.gvsig.gpe.GPEErrorHandler;
5
import org.gvsig.gpe.xml.writer.Writer;
6
import org.gvsig.gpe.gml.GMLTags;
7
import org.gvsig.gpe.xml.writer.Writer;
8

    
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id: CoordWriter.java 11697 2007-05-16 13:00:48Z csanchez $
52
 * $Log$
53
 * Revision 1.7  2007-05-16 13:00:48  csanchez
54
 * Actualizaci?n de libGPE-GML
55
 *
56
 * Revision 1.6  2007/05/14 11:18:12  jorpiell
57
 * Add the ErrorHandler to all the methods
58
 *
59
 * Revision 1.5  2007/05/08 10:24:16  jorpiell
60
 * Add comments to create javadocs
61
 *
62
 * Revision 1.4  2007/04/14 16:07:30  jorpiell
63
 * The writer has been created
64
 *
65
 * Revision 1.3  2007/04/13 13:16:00  jorpiell
66
 * Add the multiple geometries
67
 *
68
 * Revision 1.2  2007/04/12 17:06:44  jorpiell
69
 * First GML writing tests
70
 *
71
 * Revision 1.1  2007/04/12 11:36:15  jorpiell
72
 * Added new geometry writers
73
 *
74
 *
75
 */
76
/**
77
 * It parses a gml:CoordType object. Example:
78
 * <p>
79
 * <pre>
80
 * <code>
81
 * &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;
82
 * </code>
83
 * </pre>
84
 * </p> 
85
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
86
 */
87
public class CoordWriter {
88
        
89
        /**
90
         * It writes a gml:Coord tag
91
         * @param writer
92
         * Writer to write the labels
93
         * @param errorHandler
94
         * To add the errors
95
         * @param x
96
         * X coordinate 
97
         * @param y
98
         * Y coordinate
99
         * @param z
100
         * Z coordinate
101
         * @throws IOException
102
         */
103
        public static void write(Writer writer, GPEErrorHandler errorHandler,double x, double y,
104
                        double z) throws IOException{
105
                        writer.write("<" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
106
                        writeOneCoordinate(writer,errorHandler,x,y,z);
107
                        writer.write("</" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
108
        }
109
        
110
        /**
111
         * It writes a gml:Coord tag list
112
         * @param writer
113
         * Writer to write the labels
114
         * @param errorHandler
115
         * To add the errors
116
         * @param x
117
         * X coordinates
118
         * @param y
119
         * Y coordinates
120
         * @param z
121
         * Z coordinates
122
         * @throws IOException
123
         */
124
        public static void write(Writer writer, GPEErrorHandler errorHandler,double[] x, double[] y,
125
                        double[] z) throws IOException{
126
                for (int i=0 ; i<x.length ; i++){
127
                        writer.write("\n");
128
                        writer.write("<" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
129
                        writeOneCoordinate(writer,errorHandler,x[i],y[i],z[i]);
130
                        writer.write("</" + GMLTags.GML_NAMESPACE + ":" + GMLTags.GML_COORD + ">");
131
                }
132
        }
133
        
134
        /**
135
         * Writes the content of a gml:coord tag
136
         * @param writer
137
         * Writer to write the labels
138
          @param x
139
         * X coordinate
140
         * @param y
141
         * Y coordinates
142
         * @param z
143
         * Z coordinate
144
         * @throws IOException
145
         */
146
        private static void writeOneCoordinate(Writer writer, GPEErrorHandler errorHandler,double x, double y,
147
                        double z) throws IOException{                
148
                writer.write("<" +  GMLTags.GML_NAMESPACE + ":" + "X>");
149
                DoubleWriter.write(writer,errorHandler,x);
150
                writer.write("</" +  GMLTags.GML_NAMESPACE + ":" + "X>");                
151
                writer.write("<" +  GMLTags.GML_NAMESPACE + ":" + "Y>");
152
                DoubleWriter.write(writer,errorHandler,y);
153
                writer.write("</" +  GMLTags.GML_NAMESPACE + ":" + "Y>");                
154
                writer.write("<" +  GMLTags.GML_NAMESPACE + ":" + "Z>");
155
                DoubleWriter.write(writer,errorHandler,z);
156
                writer.write("</" +  GMLTags.GML_NAMESPACE + ":" + "Z>");                
157
        }
158
}