Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / gml / GMLWriter.java @ 6433

History | View | Annotate | Download (5.61 KB)

1
package com.iver.cit.gvsig.fmap.edition.writers.gml;
2

    
3
import java.awt.geom.Rectangle2D;
4
import java.io.File;
5
import java.io.FileWriter;
6
import java.io.IOException;
7

    
8
import org.cresques.cts.IProjection;
9
import org.geotools.feature.FeatureType;
10

    
11
import com.iver.cit.gvsig.fmap.core.IFeature;
12
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
13
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
14
import com.iver.cit.gvsig.fmap.drivers.gml.GMLTypesConversor;
15
import com.iver.cit.gvsig.fmap.edition.EditionException;
16
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
17
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
18
import com.iver.cit.gvsig.fmap.edition.writers.AbstractWriter;
19
import com.iver.utiles.StringUtilities;
20
import com.vividsolutions.jts.geom.Geometry;
21

    
22
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
23
 *
24
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
25
 *
26
 * This program is free software; you can redistribute it and/or
27
 * modify it under the terms of the GNU General Public License
28
 * as published by the Free Software Foundation; either version 2
29
 * of the License, or (at your option) any later version.
30
 *
31
 * This program is distributed in the hope that it will be useful,
32
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34
 * GNU General Public License for more details.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program; if not, write to the Free Software
38
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
39
 *
40
 * For more information, contact:
41
 *
42
 *  Generalitat Valenciana
43
 *   Conselleria d'Infraestructures i Transport
44
 *   Av. Blasco Ib??ez, 50
45
 *   46010 VALENCIA
46
 *   SPAIN
47
 *
48
 *      +34 963862235
49
 *   gvsig@gva.es
50
 *      www.gvsig.gva.es
51
 *
52
 *    or
53
 *
54
 *   IVER T.I. S.A
55
 *   Salamanca 50
56
 *   46005 Valencia
57
 *   Spain
58
 *
59
 *   +34 963163400
60
 *   dac@iver.es
61
 */
62
/* CVS MESSAGES:
63
 *
64
 * $Id: GMLWriter.java 6433 2006-07-19 12:30:09Z jorpiell $
65
 * $Log$
66
 * Revision 1.1  2006-07-19 12:29:39  jorpiell
67
 * A?adido el driver de GML
68
 *
69
 *
70
 */
71
/**
72
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
73
 */
74
public class GMLWriter extends AbstractWriter implements ISpatialWriter{
75
        private File m_File = null;        
76
        private FeatureType featureType = null;
77
        private GMLFileCreator gmlFile = null;        
78
        private GMLSchemaCreator gmlSchemaFileCreator = null;
79
                
80
        /**
81
         * Sets the output file
82
         * @param f
83
         */
84
        public void setFile(File f) {
85
                m_File = f;
86
        }
87
        
88
        /**
89
         * Sets the schema definition
90
         * @param lyrDef
91
         * @throws EditionException 
92
         * @throws Exception 
93
         */
94
        public void setSchema(LayerDefinition lyrDef) throws EditionException{
95
                try {
96
                        featureType = GMLTypesConversor.featureTypefromGvSIGToGeotools(lyrDef);
97
                        
98
                        String schemaPath = m_File.toURI().getPath().toLowerCase().replaceAll("\\.gml", ".xsd");
99
                                                
100
                        gmlFile = new GMLFileCreator(m_File,schemaPath);
101
                        gmlFile.setAttibutes(lyrDef.getFieldsDesc());
102
                        
103
                        schemaPath = m_File.getAbsolutePath().toLowerCase().replaceAll("\\.gml", ".xsd");
104
                        
105
                        gmlSchemaFileCreator = new GMLSchemaCreator(new File(schemaPath));
106
                        gmlSchemaFileCreator.createFile(lyrDef);
107
                } catch (Exception e) {
108
                        // TODO Auto-generated catch block
109
                        e.printStackTrace();
110
                        throw new EditionException(e.toString());
111
                }
112
        }
113
        
114
        /**
115
         * Sets the geometry extend
116
         * @param extend
117
         * @param proj
118
         */
119
        public void setBoundedBy(Rectangle2D extend,IProjection proj){
120
                gmlFile.setBoundedBy(extend,proj);
121
        }
122
        
123
        /*
124
         *  (non-Javadoc)
125
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#canWriteAttribute(int)
126
         */
127
        public boolean canWriteAttribute(int sqlType) {
128
                return true;
129
        }
130

    
131
        /*
132
         *  (non-Javadoc)
133
         * @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#canWriteGeometry(int)
134
         */
135
        public boolean canWriteGeometry(int gvSIGgeometryType) {
136
                return true;
137
        }
138

    
139
        /*
140
         *  (non-Javadoc)
141
         * @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#setFlatness(double)
142
         */
143
        public void setFlatness(double flatness) {
144
                // TODO Auto-generated method stub
145
                
146
        }
147

    
148
        /*
149
         *  (non-Javadoc)
150
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#preProcess()
151
         */
152
        public void preProcess() throws EditionException {
153
                if (gmlFile == null){
154
                        new EditionException("The driver must be initialized using the setSchema method");
155
                }
156
                try {
157
                        gmlFile.initialize();
158
                        
159
                } catch (IOException e) {
160
                        // TODO Auto-generated catch block
161
                        e.printStackTrace();
162
                        new EditionException(e.toString());
163
                }
164
        }
165

    
166
        /*
167
         *  (non-Javadoc)
168
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#process(com.iver.cit.gvsig.fmap.edition.IRowEdited)
169
         */
170
        public void process(IRowEdited row) throws EditionException {
171
                Geometry geom =  ((IFeature)row.getLinkedRow()).getGeometry().toJTSGeometry();
172
                try {                        
173
                        gmlFile.insertFeature(geom,row.getAttributes());
174
                } catch (IOException e) {
175
                        // TODO Auto-generated catch block
176
                        e.printStackTrace();
177
                        throw new EditionException(e.toString()); 
178
                }                                        
179
        }
180

    
181
        /*
182
         *  (non-Javadoc)
183
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#postProcess()
184
         */
185
        public void postProcess() throws EditionException {
186
                try {
187
                        gmlFile.writeFile();
188
                        gmlSchemaFileCreator.writeFile();
189
                } catch (IOException e) {
190
                        // TODO Auto-generated catch block
191
                        e.printStackTrace();
192
                        throw new EditionException(e.toString()); 
193
                }                
194
        }
195

    
196
        /*
197
         *  (non-Javadoc)
198
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#initialize(com.iver.cit.gvsig.fmap.drivers.ITableDefinition)
199
         */
200
        public void initialize(ITableDefinition tableDefinition) throws EditionException {
201
                // TODO Auto-generated method stub
202
                
203
        }
204

    
205
        /*
206
         *  (non-Javadoc)
207
         * @see com.hardcode.driverManager.Driver#getName()
208
         */
209
        public String getName() {
210
                return "GML Writer";
211
        }
212
        
213

    
214

    
215

    
216
}