Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / writer / geometries / LinearRingWriter.java @ 12071

History | View | Annotate | Download (3.66 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.gml.GMLTags;
7
import org.gvsig.gpe.gml.utils.GMLUtilsParser;
8
import org.gvsig.gpe.warnings.PolygonAutomaticallyClosedWarning;
9
import org.gvsig.gpe.xml.writer.Writer;
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id: LinearRingWriter.java 12071 2007-06-07 14:53:59Z jorpiell $
54
 * $Log$
55
 * Revision 1.6  2007-06-07 14:53:30  jorpiell
56
 * Add the schema support
57
 *
58
 * Revision 1.5  2007/05/16 09:29:12  jorpiell
59
 * The polygons has to be closed
60
 *
61
 * Revision 1.4  2007/05/14 11:18:12  jorpiell
62
 * Add the ErrorHandler to all the methods
63
 *
64
 * Revision 1.3  2007/05/08 10:24:16  jorpiell
65
 * Add comments to create javadocs
66
 *
67
 * Revision 1.2  2007/04/14 16:07:30  jorpiell
68
 * The writer has been created
69
 *
70
 * Revision 1.1  2007/04/12 10:23:41  jorpiell
71
 * Add some writers and the GPEXml parser
72
 *
73
 *
74
 */
75
/**
76
 * It writes a gml:linearRingType object. Example:
77
 * <p>
78
 * <pre>
79
 * <code>
80
 * &lt;LinearRing&gt;
81
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
82
 * &lt;/LinearRing&gt;
83
 * </code>
84
 * </pre>
85
 * </p> 
86
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
87
 */
88
public class LinearRingWriter {
89
        
90
        
91
        /**
92
         * It writes a gml:linearRing init tag
93
         * @param writer
94
         * Writer to write the labels
95
         * @param errorHandler
96
         * To add the errors
97
         * @param id
98
         * Geometry ID
99
         * @param x
100
         * X coordinates 
101
         * @param y
102
         * Y coordinates 
103
         * @param z
104
         * Z coordinates 
105
         * @param srs
106
         * Spatial reference system
107
         * @throws IOException
108
         */
109
        public static void start(Writer writer, GPEErrorHandler errorHandler, String id, double[] x, double[] y,
110
                        double[] z, String srs) throws IOException{
111
                GeometriesWriter.startGeometry(writer, errorHandler, GMLTags.GML_LINEARRING, id, srs);
112
                //The first and the last coordinates has to be the same
113
                if ((x[0] != x[x.length - 1]) ||
114
                                (y[0] != y[y.length - 1]) ||
115
                                (z[0] != z[z.length - 1])){
116
                        errorHandler.addWarning(new PolygonAutomaticallyClosedWarning(x,y,z));
117
                        x = GMLUtilsParser.closePolygon(x);
118
                        y = GMLUtilsParser.closePolygon(y);
119
                        z = GMLUtilsParser.closePolygon(z);                        
120
                }                
121
                CoordinatesWriter.write(writer, errorHandler, x, y, z);                
122
        }
123
        
124
        /**
125
         * It writes a gml:linearRing end tag
126
         * @param writer
127
         * Writer to write the labels
128
         * @param errorHandler
129
         * To add the errors
130
         * @throws IOException
131
         */
132
        public static void end(Writer writer, GPEErrorHandler errorHandler) throws IOException{
133
                GeometriesWriter.endGeometry(writer, errorHandler, GMLTags.GML_LINEARRING);
134
        }
135
}