root / trunk / extensions / extWFS2 / src-test / com / iver / cit / gvsig / fmap / layers / gml / GMLWriterTest.java @ 7721
History | View | Annotate | Download (6.61 KB)
1 |
package com.iver.cit.gvsig.fmap.layers.gml; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.io.File; |
5 |
import java.util.ArrayList; |
6 |
|
7 |
import junit.framework.TestCase; |
8 |
|
9 |
import org.cresques.cts.IProjection; |
10 |
import org.cresques.cts.ProjectionPool; |
11 |
|
12 |
import com.hardcode.driverManager.DriverLoadException; |
13 |
import com.hardcode.gdbms.engine.values.Value; |
14 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
15 |
import com.iver.cit.gvsig.fmap.DriverException; |
16 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
17 |
import com.iver.cit.gvsig.fmap.core.FShape; |
18 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
19 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
20 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
21 |
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
22 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
23 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
24 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
25 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
26 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
27 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
28 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
29 |
import com.iver.cit.gvsig.fmap.edition.writers.gml.GMLWriter; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
32 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
33 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
34 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
35 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
36 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
37 |
*
|
38 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
39 |
*
|
40 |
* This program is free software; you can redistribute it and/or
|
41 |
* modify it under the terms of the GNU General Public License
|
42 |
* as published by the Free Software Foundation; either version 2
|
43 |
* of the License, or (at your option) any later version.
|
44 |
*
|
45 |
* This program is distributed in the hope that it will be useful,
|
46 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
47 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
48 |
* GNU General Public License for more details.
|
49 |
*
|
50 |
* You should have received a copy of the GNU General Public License
|
51 |
* along with this program; if not, write to the Free Software
|
52 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
53 |
*
|
54 |
* For more information, contact:
|
55 |
*
|
56 |
* Generalitat Valenciana
|
57 |
* Conselleria d'Infraestructures i Transport
|
58 |
* Av. Blasco Ib??ez, 50
|
59 |
* 46010 VALENCIA
|
60 |
* SPAIN
|
61 |
*
|
62 |
* +34 963862235
|
63 |
* gvsig@gva.es
|
64 |
* www.gvsig.gva.es
|
65 |
*
|
66 |
* or
|
67 |
*
|
68 |
* IVER T.I. S.A
|
69 |
* Salamanca 50
|
70 |
* 46005 Valencia
|
71 |
* Spain
|
72 |
*
|
73 |
* +34 963163400
|
74 |
* dac@iver.es
|
75 |
*/
|
76 |
/* CVS MESSAGES:
|
77 |
*
|
78 |
* $Id: GMLWriterTest.java 7721 2006-10-02 09:09:45Z jorpiell $
|
79 |
* $Log$
|
80 |
* Revision 1.3 2006-10-02 09:09:45 jorpiell
|
81 |
* Cambios del 10 copiados al head
|
82 |
*
|
83 |
* Revision 1.1.2.1 2006/09/29 14:12:53 luisw2
|
84 |
* CRSFactory.getCRS substitutes ProjectionPool.get
|
85 |
*
|
86 |
* Revision 1.1 2006/07/24 07:30:33 jorpiell
|
87 |
* Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
|
88 |
*
|
89 |
*
|
90 |
*/
|
91 |
/**
|
92 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
93 |
*/
|
94 |
public class GMLWriterTest extends TestCase { |
95 |
private String gmlFile = "MUNIC.gml"; |
96 |
|
97 |
protected void setUp(){ |
98 |
LayerFactory.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
99 |
LayerFactory.setWritersPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
100 |
System.out.println("****************READERS****************"); |
101 |
for (int i=0 ; i<LayerFactory.getDM().getDriverNames().length ; i++){ |
102 |
System.out.println(LayerFactory.getDM().getDriverNames()[i]);
|
103 |
} |
104 |
System.out.println("****************WRITERS****************"); |
105 |
for (int i=0 ; i<LayerFactory.getWM().getWriterNames().length ; i++){ |
106 |
System.out.println(LayerFactory.getWM().getWriterNames()[i]);
|
107 |
} |
108 |
System.out.println("****************COMENZANDO****************"); |
109 |
} |
110 |
|
111 |
public void test1() throws DriverLoadException, DriverException, EditionException, DriverIOException, com.hardcode.gdbms.engine.data.driver.DriverException{ |
112 |
// DRIVER DEFINITION (SHAPE TYPE AND FIELDS)
|
113 |
ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
|
114 |
driver.setShapeType(FShape.LINE); |
115 |
|
116 |
ArrayList arrayFields = new ArrayList(); |
117 |
arrayFields.add("ID");
|
118 |
Value[] auxRow = new Value[1]; |
119 |
|
120 |
driver.getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
121 |
|
122 |
//GEOMETRY DEFINITION
|
123 |
GeneralPathX gp = new GeneralPathX();
|
124 |
|
125 |
gp.moveTo(20,80); |
126 |
gp.lineTo(80,60); |
127 |
gp.lineTo(100, 140); |
128 |
|
129 |
FShape shp = new FPolyline2D(gp);
|
130 |
|
131 |
|
132 |
// ATRIBUTES
|
133 |
auxRow[0] = ValueFactory.createValue(0); |
134 |
|
135 |
// ADD RECORD
|
136 |
driver.addShape(shp, auxRow); |
137 |
|
138 |
//GEOMETRY DEFINITION
|
139 |
gp = new GeneralPathX();
|
140 |
|
141 |
gp.moveTo(20,80); |
142 |
gp.lineTo(80,60); |
143 |
gp.lineTo(100, 140); |
144 |
|
145 |
shp = new FPolyline2D(gp);
|
146 |
|
147 |
|
148 |
// ATRIBUTES
|
149 |
auxRow[0] = ValueFactory.createValue(1); |
150 |
|
151 |
// ADD RECORD
|
152 |
driver.addShape(shp, auxRow); |
153 |
|
154 |
// CREATE AND ADD LAYER
|
155 |
FLyrVect lyr; |
156 |
String layerName = "Example"; |
157 |
lyr = (FLyrVect) LayerFactory.createLayer(layerName,driver, CRSFactory.getCRS("EPSG:4326"));
|
158 |
|
159 |
|
160 |
SHPLayerDefinition lyrDef = new SHPLayerDefinition();
|
161 |
SelectableDataSource sds = lyr.getRecordset(); |
162 |
FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
|
163 |
lyrDef.setFieldsDesc(fieldsDescrip); |
164 |
lyrDef.setName(lyr.getName()); |
165 |
|
166 |
File newFile = new File(gmlFile); |
167 |
|
168 |
GMLWriter writer = (GMLWriter)LayerFactory.getWM().getWriter("GML Writer");
|
169 |
writer.setFile(new File(gmlFile)); |
170 |
writer.setSchema(lyrDef); |
171 |
Rectangle2D rectangle = new Rectangle2D.Double(0, |
172 |
0,
|
173 |
100,
|
174 |
100);
|
175 |
writer.setBoundedBy(rectangle,CRSFactory.getCRS("EPSG:23030"));
|
176 |
|
177 |
writer.preProcess(); |
178 |
|
179 |
ReadableVectorial adapter = lyr.getSource(); |
180 |
for (int i=0; i < adapter.getShapeCount(); i++){ |
181 |
IFeature feat = adapter.getFeature(i); |
182 |
IRowEdited editFeat = new DefaultRowEdited(feat, IRowEdited.STATUS_MODIFIED, i);
|
183 |
writer.process(editFeat); |
184 |
} |
185 |
writer.postProcess(); |
186 |
} |
187 |
|
188 |
|
189 |
|
190 |
private static FLayer createLayer(String layerName, VectorialFileDriver d, |
191 |
File f, IProjection proj) throws DriverException { |
192 |
//TODO Comprobar si hay un adaptador ya
|
193 |
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
194 |
adapter.setDriver(d); |
195 |
FLyrVect capa = new FLyrVect();
|
196 |
capa.setName(layerName); |
197 |
|
198 |
capa.setSource(adapter); |
199 |
capa.setProjection(proj); |
200 |
|
201 |
return capa;
|
202 |
} |
203 |
} |