root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / gml / GMLWriter.java @ 6485
History | View | Annotate | Download (5.7 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 6485 2006-07-21 08:57:28Z jorpiell $
|
65 |
* $Log$
|
66 |
* Revision 1.2 2006-07-21 08:57:28 jorpiell
|
67 |
* Se ha a?adido la exportaci?n de capas de puntos
|
68 |
*
|
69 |
* Revision 1.1 2006/07/19 12:29:39 jorpiell
|
70 |
* A?adido el driver de GML
|
71 |
*
|
72 |
*
|
73 |
*/
|
74 |
/**
|
75 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
76 |
*/
|
77 |
public class GMLWriter extends AbstractWriter implements ISpatialWriter{ |
78 |
private File m_File = null; |
79 |
private FeatureType featureType = null; |
80 |
private GMLFileCreator gmlFile = null; |
81 |
private GMLSchemaCreator gmlSchemaFileCreator = null; |
82 |
|
83 |
/**
|
84 |
* Sets the output file
|
85 |
* @param f
|
86 |
*/
|
87 |
public void setFile(File f) { |
88 |
m_File = f; |
89 |
} |
90 |
|
91 |
/**
|
92 |
* Sets the schema definition
|
93 |
* @param lyrDef
|
94 |
* @throws EditionException
|
95 |
* @throws Exception
|
96 |
*/
|
97 |
public void setSchema(LayerDefinition lyrDef) throws EditionException{ |
98 |
try {
|
99 |
featureType = GMLTypesConversor.featureTypefromGvSIGToGeotools(lyrDef); |
100 |
|
101 |
String schemaPath = m_File.toURI().getPath().toLowerCase().replaceAll("\\.gml", ".xsd"); |
102 |
|
103 |
gmlFile = new GMLFileCreator(m_File,schemaPath);
|
104 |
gmlFile.setAttibutes(lyrDef.getFieldsDesc()); |
105 |
|
106 |
schemaPath = m_File.getAbsolutePath().toLowerCase().replaceAll("\\.gml", ".xsd"); |
107 |
|
108 |
gmlSchemaFileCreator = new GMLSchemaCreator(new File(schemaPath)); |
109 |
gmlSchemaFileCreator.createFile(lyrDef); |
110 |
} catch (Exception e) { |
111 |
// TODO Auto-generated catch block
|
112 |
e.printStackTrace(); |
113 |
throw new EditionException(e.toString()); |
114 |
} |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Sets the geometry extend
|
119 |
* @param extend
|
120 |
* @param proj
|
121 |
*/
|
122 |
public void setBoundedBy(Rectangle2D extend,IProjection proj){ |
123 |
gmlFile.setBoundedBy(extend,proj); |
124 |
} |
125 |
|
126 |
/*
|
127 |
* (non-Javadoc)
|
128 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#canWriteAttribute(int)
|
129 |
*/
|
130 |
public boolean canWriteAttribute(int sqlType) { |
131 |
return true; |
132 |
} |
133 |
|
134 |
/*
|
135 |
* (non-Javadoc)
|
136 |
* @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#canWriteGeometry(int)
|
137 |
*/
|
138 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
139 |
return true; |
140 |
} |
141 |
|
142 |
/*
|
143 |
* (non-Javadoc)
|
144 |
* @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#setFlatness(double)
|
145 |
*/
|
146 |
public void setFlatness(double flatness) { |
147 |
// TODO Auto-generated method stub
|
148 |
|
149 |
} |
150 |
|
151 |
/*
|
152 |
* (non-Javadoc)
|
153 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#preProcess()
|
154 |
*/
|
155 |
public void preProcess() throws EditionException { |
156 |
if (gmlFile == null){ |
157 |
new EditionException("The driver must be initialized using the setSchema method"); |
158 |
} |
159 |
try {
|
160 |
gmlFile.initialize(); |
161 |
|
162 |
} catch (IOException e) { |
163 |
// TODO Auto-generated catch block
|
164 |
e.printStackTrace(); |
165 |
new EditionException(e.toString());
|
166 |
} |
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#process(com.iver.cit.gvsig.fmap.edition.IRowEdited)
|
172 |
*/
|
173 |
public void process(IRowEdited row) throws EditionException { |
174 |
Geometry geom = ((IFeature)row.getLinkedRow()).getGeometry().toJTSGeometry(); |
175 |
try {
|
176 |
gmlFile.insertFeature(geom,row.getAttributes()); |
177 |
} catch (IOException e) { |
178 |
// TODO Auto-generated catch block
|
179 |
e.printStackTrace(); |
180 |
throw new EditionException(e.toString()); |
181 |
} |
182 |
} |
183 |
|
184 |
/*
|
185 |
* (non-Javadoc)
|
186 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#postProcess()
|
187 |
*/
|
188 |
public void postProcess() throws EditionException { |
189 |
try {
|
190 |
gmlFile.writeFile(); |
191 |
gmlSchemaFileCreator.writeFile(); |
192 |
} catch (IOException e) { |
193 |
// TODO Auto-generated catch block
|
194 |
e.printStackTrace(); |
195 |
throw new EditionException(e.toString()); |
196 |
} |
197 |
} |
198 |
|
199 |
/*
|
200 |
* (non-Javadoc)
|
201 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#initialize(com.iver.cit.gvsig.fmap.drivers.ITableDefinition)
|
202 |
*/
|
203 |
public void initialize(ITableDefinition tableDefinition) throws EditionException { |
204 |
super.initialize(tableDefinition);
|
205 |
|
206 |
} |
207 |
|
208 |
/*
|
209 |
* (non-Javadoc)
|
210 |
* @see com.hardcode.driverManager.Driver#getName()
|
211 |
*/
|
212 |
public String getName() { |
213 |
return "GML Writer"; |
214 |
} |
215 |
|
216 |
|
217 |
|
218 |
|
219 |
} |