root / branches / piloto3d / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / gml / GMLWriter.java @ 9524
History | View | Annotate | Download (6.42 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 9524 2007-01-03 15:14:45Z sbayarri $
|
65 |
* $Log$
|
66 |
* Revision 1.5.2.1 2007-01-03 15:12:33 sbayarri
|
67 |
* v10 synch & 3D
|
68 |
*
|
69 |
* Revision 1.5.4.2 2006/11/15 00:08:27 jjdelcerro
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
* Revision 1.6 2006/09/21 15:47:04 jorpiell
|
73 |
* Ya se pueden exportar ficheros a GML en Linux cuyo path tenga una may?scula
|
74 |
*
|
75 |
* Revision 1.5 2006/08/25 13:04:07 fjp
|
76 |
* Comprobar que se puede editar antes de ponerte en edicion
|
77 |
*
|
78 |
* Revision 1.4 2006/08/10 12:03:43 jorpiell
|
79 |
* Se usa el nuevo driver de GML de remoteServices
|
80 |
*
|
81 |
* Revision 1.3 2006/08/02 11:22:56 fjp
|
82 |
* Empieza a funcionar con PostGIS lo de a?adir campos
|
83 |
*
|
84 |
* Revision 1.2 2006/07/21 08:57:28 jorpiell
|
85 |
* Se ha a?adido la exportaci?n de capas de puntos
|
86 |
*
|
87 |
* Revision 1.1 2006/07/19 12:29:39 jorpiell
|
88 |
* A?adido el driver de GML
|
89 |
*
|
90 |
*
|
91 |
*/
|
92 |
/**
|
93 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
94 |
*/
|
95 |
public class GMLWriter extends AbstractWriter implements ISpatialWriter{ |
96 |
private File m_File = null; |
97 |
private FeatureType featureType = null; |
98 |
private GMLFileCreator gmlFile = null; |
99 |
private GMLSchemaCreator gmlSchemaFileCreator = null; |
100 |
|
101 |
/**
|
102 |
* Sets the output file
|
103 |
* @param f
|
104 |
*/
|
105 |
public void setFile(File f) { |
106 |
m_File = f; |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Sets the schema definition
|
111 |
* @param lyrDef
|
112 |
* @throws EditionException
|
113 |
* @throws Exception
|
114 |
*/
|
115 |
public void setSchema(LayerDefinition lyrDef) throws EditionException{ |
116 |
try {
|
117 |
featureType = GMLTypesConversor.featureTypefromGvSIGToGeotools(lyrDef); |
118 |
|
119 |
String schemaPath = m_File.getName().replaceAll("\\.gml", ".xsd"); |
120 |
|
121 |
gmlFile = new GMLFileCreator(m_File,schemaPath);
|
122 |
gmlFile.setAttibutes(lyrDef.getFieldsDesc()); |
123 |
|
124 |
schemaPath = m_File.getAbsolutePath().replaceAll("\\.gml", ".xsd"); |
125 |
|
126 |
gmlSchemaFileCreator = new GMLSchemaCreator(new File(schemaPath)); |
127 |
gmlSchemaFileCreator.createFile(lyrDef); |
128 |
} catch (Exception e) { |
129 |
// TODO Auto-generated catch block
|
130 |
e.printStackTrace(); |
131 |
throw new EditionException(e.toString()); |
132 |
} |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Sets the geometry extend
|
137 |
* @param extend
|
138 |
* @param proj
|
139 |
*/
|
140 |
public void setBoundedBy(Rectangle2D extend,IProjection proj){ |
141 |
gmlFile.setBoundedBy(extend,proj); |
142 |
} |
143 |
|
144 |
/*
|
145 |
* (non-Javadoc)
|
146 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#canWriteAttribute(int)
|
147 |
*/
|
148 |
public boolean canWriteAttribute(int sqlType) { |
149 |
return true; |
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
* @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#canWriteGeometry(int)
|
155 |
*/
|
156 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
157 |
return true; |
158 |
} |
159 |
|
160 |
/*
|
161 |
* (non-Javadoc)
|
162 |
* @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#setFlatness(double)
|
163 |
*/
|
164 |
public void setFlatness(double flatness) { |
165 |
// TODO Auto-generated method stub
|
166 |
|
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#preProcess()
|
172 |
*/
|
173 |
public void preProcess() throws EditionException { |
174 |
if (gmlFile == null){ |
175 |
new EditionException("The driver must be initialized using the setSchema method"); |
176 |
} |
177 |
try {
|
178 |
gmlFile.initialize(); |
179 |
|
180 |
} catch (IOException e) { |
181 |
// TODO Auto-generated catch block
|
182 |
e.printStackTrace(); |
183 |
new EditionException(e.toString());
|
184 |
} |
185 |
} |
186 |
|
187 |
/*
|
188 |
* (non-Javadoc)
|
189 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#process(com.iver.cit.gvsig.fmap.edition.IRowEdited)
|
190 |
*/
|
191 |
public void process(IRowEdited row) throws EditionException { |
192 |
Geometry geom = ((IFeature)row.getLinkedRow()).getGeometry().toJTSGeometry(); |
193 |
try {
|
194 |
gmlFile.insertFeature(geom,row.getAttributes()); |
195 |
} catch (IOException e) { |
196 |
// TODO Auto-generated catch block
|
197 |
e.printStackTrace(); |
198 |
throw new EditionException(e.toString()); |
199 |
} |
200 |
} |
201 |
|
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#postProcess()
|
205 |
*/
|
206 |
public void postProcess() throws EditionException { |
207 |
try {
|
208 |
gmlFile.writeFile(); |
209 |
gmlSchemaFileCreator.writeFile(); |
210 |
} catch (IOException e) { |
211 |
// TODO Auto-generated catch block
|
212 |
e.printStackTrace(); |
213 |
throw new EditionException(e.toString()); |
214 |
} |
215 |
} |
216 |
|
217 |
/*
|
218 |
* (non-Javadoc)
|
219 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#initialize(com.iver.cit.gvsig.fmap.drivers.ITableDefinition)
|
220 |
*/
|
221 |
public void initialize(ITableDefinition tableDefinition) throws EditionException { |
222 |
super.initialize(tableDefinition);
|
223 |
|
224 |
} |
225 |
|
226 |
/*
|
227 |
* (non-Javadoc)
|
228 |
* @see com.hardcode.driverManager.Driver#getName()
|
229 |
*/
|
230 |
public String getName() { |
231 |
return "GML Writer"; |
232 |
} |
233 |
|
234 |
public boolean canAlterTable() { |
235 |
// TODO Auto-generated method stub
|
236 |
return false; |
237 |
} |
238 |
|
239 |
public boolean canSaveEdits() { |
240 |
if (m_File.canWrite()) return true; |
241 |
return false; |
242 |
} |
243 |
|
244 |
|
245 |
|
246 |
} |