Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / gml / GMLWriter.java @ 8745

History | View | Annotate | Download (6.33 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 8745 2006-11-14 13:14:23Z  $
65
 * $Log$
66
 * Revision 1.5.4.1  2006-09-21 15:34:12  jorpiell
67
 * El driver no permitía generar GML's en linux en directorios que tubiesen una letra en Mayúsculas.
68
 *
69
 * Revision 1.5  2006/08/25 13:04:07  fjp
70
 * Comprobar que se puede editar antes de ponerte en edicion
71
 *
72
 * Revision 1.4  2006/08/10 12:03:43  jorpiell
73
 * Se usa el nuevo driver de GML de remoteServices
74
 *
75
 * Revision 1.3  2006/08/02 11:22:56  fjp
76
 * Empieza a funcionar con PostGIS lo de a�adir campos
77
 *
78
 * Revision 1.2  2006/07/21 08:57:28  jorpiell
79
 * Se ha a�adido la exportaci�n de capas de puntos
80
 *
81
 * Revision 1.1  2006/07/19 12:29:39  jorpiell
82
 * A�adido el driver de GML
83
 *
84
 *
85
 */
86
/**
87
 * @author Jorge Piera Llodr� (piera_jor@gva.es)
88
 */
89
public class GMLWriter extends AbstractWriter implements ISpatialWriter{
90
        private File m_File = null;        
91
        private FeatureType featureType = null;
92
        private GMLFileCreator gmlFile = null;        
93
        private GMLSchemaCreator gmlSchemaFileCreator = null;
94
                
95
        /**
96
         * Sets the output file
97
         * @param f
98
         */
99
        public void setFile(File f) {
100
                m_File = f;
101
        }
102
        
103
        /**
104
         * Sets the schema definition
105
         * @param lyrDef
106
         * @throws EditionException 
107
         * @throws Exception 
108
         */
109
        public void setSchema(LayerDefinition lyrDef) throws EditionException{
110
                try {
111
                        featureType = GMLTypesConversor.featureTypefromGvSIGToGeotools(lyrDef);
112
                        
113
                        String schemaPath = m_File.getName().replaceAll("\\.gml", ".xsd");
114
                                                                        
115
                        gmlFile = new GMLFileCreator(m_File,schemaPath);
116
                        gmlFile.setAttibutes(lyrDef.getFieldsDesc());
117
                        
118
                        schemaPath = m_File.getAbsolutePath().replaceAll("\\.gml", ".xsd");
119
                        
120
                                                
121
                        gmlSchemaFileCreator = new GMLSchemaCreator(new File(schemaPath));
122
                        gmlSchemaFileCreator.createFile(lyrDef);
123
                } catch (Exception e) {
124
                        // TODO Auto-generated catch block
125
                        e.printStackTrace();
126
                        throw new EditionException(e.toString());
127
                }
128
        }
129
        
130
        /**
131
         * Sets the geometry extend
132
         * @param extend
133
         * @param proj
134
         */
135
        public void setBoundedBy(Rectangle2D extend,IProjection proj){
136
                gmlFile.setBoundedBy(extend,proj);
137
        }
138
        
139
        /*
140
         *  (non-Javadoc)
141
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#canWriteAttribute(int)
142
         */
143
        public boolean canWriteAttribute(int sqlType) {
144
                return true;
145
        }
146

    
147
        /*
148
         *  (non-Javadoc)
149
         * @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#canWriteGeometry(int)
150
         */
151
        public boolean canWriteGeometry(int gvSIGgeometryType) {
152
                return true;
153
        }
154

    
155
        /*
156
         *  (non-Javadoc)
157
         * @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#setFlatness(double)
158
         */
159
        public void setFlatness(double flatness) {
160
                // TODO Auto-generated method stub
161
                
162
        }
163

    
164
        /*
165
         *  (non-Javadoc)
166
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#preProcess()
167
         */
168
        public void preProcess() throws EditionException {
169
                if (gmlFile == null){
170
                        new EditionException("The driver must be initialized using the setSchema method");
171
                }
172
                try {
173
                        gmlFile.initialize();
174
                        
175
                } catch (IOException e) {
176
                        // TODO Auto-generated catch block
177
                        e.printStackTrace();
178
                        new EditionException(e.toString());
179
                }
180
        }
181

    
182
        /*
183
         *  (non-Javadoc)
184
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#process(com.iver.cit.gvsig.fmap.edition.IRowEdited)
185
         */
186
        public void process(IRowEdited row) throws EditionException {
187
                Geometry geom =  ((IFeature)row.getLinkedRow()).getGeometry().toJTSGeometry();
188
                try {                        
189
                        gmlFile.insertFeature(geom,row.getAttributes());
190
                } catch (IOException e) {
191
                        // TODO Auto-generated catch block
192
                        e.printStackTrace();
193
                        throw new EditionException(e.toString()); 
194
                }                                        
195
        }
196

    
197
        /*
198
         *  (non-Javadoc)
199
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#postProcess()
200
         */
201
        public void postProcess() throws EditionException {
202
                try {
203
                        gmlFile.writeFile();
204
                        gmlSchemaFileCreator.writeFile();
205
                } catch (IOException e) {
206
                        // TODO Auto-generated catch block
207
                        e.printStackTrace();
208
                        throw new EditionException(e.toString()); 
209
                }                
210
        }
211

    
212
        /*
213
         *  (non-Javadoc)
214
         * @see com.iver.cit.gvsig.fmap.edition.IWriter#initialize(com.iver.cit.gvsig.fmap.drivers.ITableDefinition)
215
         */
216
        public void initialize(ITableDefinition tableDefinition) throws EditionException {
217
                super.initialize(tableDefinition);
218
                
219
        }
220

    
221
        /*
222
         *  (non-Javadoc)
223
         * @see com.hardcode.driverManager.Driver#getName()
224
         */
225
        public String getName() {
226
                return "GML Writer";
227
        }
228

    
229
        public boolean canAlterTable() {
230
                // TODO Auto-generated method stub
231
                return false;
232
        }
233
        
234
        public boolean canSaveEdits() {
235
                if (m_File.canWrite()) return true;
236
                return false;
237
        }
238

    
239

    
240

    
241
}