Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extWFS2 / src-test / com / iver / cit / gvsig / fmap / layers / gml / GMLWriterTest.java @ 8847

History | View | Annotate | Download (6.72 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 8847 2006-11-17 11:29:00Z ppiqueras $
79
 * $Log$
80
 * Revision 1.1.2.3  2006-11-17 11:28:45  ppiqueras
81
 * Corregidos bugs y a?adida nueva funcionalidad.
82
 *
83
 * Revision 1.3  2006/10/02 09:09:45  jorpiell
84
 * Cambios del 10 copiados al head
85
 *
86
 * Revision 1.1.2.1  2006/09/29 14:12:53  luisw2
87
 * CRSFactory.getCRS substitutes ProjectionPool.get
88
 *
89
 * Revision 1.1  2006/07/24 07:30:33  jorpiell
90
 * Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
91
 *
92
 *
93
 */
94
/**
95
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
96
 */
97
public class GMLWriterTest extends TestCase {
98
        private String gmlFile = "MUNIC.gml";
99
        
100
        protected void setUp(){
101
                LayerFactory.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
102
                LayerFactory.setWritersPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
103
                System.out.println("****************READERS****************");
104
                for (int i=0 ; i<LayerFactory.getDM().getDriverNames().length ; i++){
105
                        System.out.println(LayerFactory.getDM().getDriverNames()[i]);
106
                }
107
                System.out.println("****************WRITERS****************");
108
                for (int i=0 ; i<LayerFactory.getWM().getWriterNames().length ; i++){
109
                        System.out.println(LayerFactory.getWM().getWriterNames()[i]);
110
                }
111
                System.out.println("****************COMENZANDO****************");
112
        }
113
        
114
        public void test1() throws DriverLoadException, DriverException, EditionException, DriverIOException, com.hardcode.gdbms.engine.data.driver.DriverException{
115
        // DRIVER DEFINITION (SHAPE TYPE AND FIELDS)
116
        ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
117
        driver.setShapeType(FShape.LINE);
118
        
119
        ArrayList arrayFields = new ArrayList();
120
        arrayFields.add("ID");
121
        Value[] auxRow = new Value[1];
122
  
123
        driver.getTableModel().setColumnIdentifiers(arrayFields.toArray());
124
                
125
        //GEOMETRY DEFINITION
126
        GeneralPathX gp = new GeneralPathX();
127
        
128
        gp.moveTo(20,80);
129
        gp.lineTo(80,60);
130
        gp.lineTo(100, 140);
131
        
132
        FShape shp = new FPolyline2D(gp);
133
        
134
        
135
        // ATRIBUTES
136
        auxRow[0] = ValueFactory.createValue(0);
137
        
138
        // ADD RECORD
139
        driver.addShape(shp, auxRow);
140
         
141
        //GEOMETRY DEFINITION
142
        gp = new GeneralPathX();
143
        
144
        gp.moveTo(20,80);
145
        gp.lineTo(80,60);
146
        gp.lineTo(100, 140);
147
        
148
        shp = new FPolyline2D(gp);
149
        
150
        
151
        // ATRIBUTES
152
        auxRow[0] = ValueFactory.createValue(1);
153
        
154
        // ADD RECORD
155
        driver.addShape(shp, auxRow);
156

    
157
        // CREATE AND ADD LAYER
158
        FLyrVect lyr;
159
        String layerName = "Example";
160
               lyr = (FLyrVect) LayerFactory.createLayer(layerName,driver, CRSFactory.getCRS("EPSG:4326"));                   
161
                
162
                              
163
               SHPLayerDefinition lyrDef = new SHPLayerDefinition();
164
                SelectableDataSource sds = lyr.getRecordset();
165
                FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
166
                lyrDef.setFieldsDesc(fieldsDescrip);
167
                lyrDef.setName(lyr.getName());
168
               
169
                File newFile = new File(gmlFile);
170
                
171
                GMLWriter writer = (GMLWriter)LayerFactory.getWM().getWriter("GML Writer");
172
                writer.setFile(new File(gmlFile));
173
                writer.setSchema(lyrDef);                
174
                Rectangle2D rectangle = new Rectangle2D.Double(0,
175
                                0,
176
                                100,
177
                                100);                
178
                writer.setBoundedBy(rectangle,CRSFactory.getCRS("EPSG:23030"));
179
                
180
                writer.preProcess();
181
                
182
                ReadableVectorial adapter = lyr.getSource();
183
                for (int i=0; i < adapter.getShapeCount(); i++){
184
                        IFeature feat = adapter.getFeature(i);
185
                        IRowEdited editFeat = new DefaultRowEdited(feat, IRowEdited.STATUS_MODIFIED, i);
186
                        writer.process(editFeat);
187
                }
188
                writer.postProcess();                
189
        }
190
        
191

    
192
        
193
        private static FLayer createLayer(String layerName, VectorialFileDriver d,
194
                        File f, IProjection proj) throws DriverException {
195
                        //TODO Comprobar si hay un adaptador ya
196
                        VectorialFileAdapter adapter = new VectorialFileAdapter(f);
197
                        adapter.setDriver(d);
198
                        FLyrVect capa = new FLyrVect();
199
                        capa.setName(layerName);
200

    
201
                        capa.setSource(adapter);
202
                        capa.setProjection(proj);
203

    
204
                        return capa;
205
                }
206
}