Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libRemoteServices / test / org / gvsig / remoteClient / gml / GMLReaderTest.java @ 9917

History | View | Annotate | Download (7.24 KB)

1
package org.gvsig.remoteClient.gml;
2

    
3
import java.awt.geom.Rectangle2D;
4
import java.io.File;
5
import java.io.IOException;
6
import java.util.ArrayList;
7
import java.util.Hashtable;
8
import java.util.Iterator;
9
import java.util.Map;
10
import java.util.Set;
11

    
12
import org.gvsig.remoteClient.gml.factories.GeometriesFactory;
13
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
14
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory;
15
import org.gvsig.remoteClient.gml.factories.XMLSchemasFactory;
16
import org.gvsig.remoteClient.gml.factories.XMLTypesFactory;
17
import org.gvsig.remoteClient.gml.v2.GMLSimpleFeature_v2;
18
import org.xmlpull.v1.XmlPullParserException;
19

    
20
import junit.framework.TestCase;
21
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
22
 *
23
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
24
 *
25
 * This program is free software; you can redistribute it and/or
26
 * modify it under the terms of the GNU General Public License
27
 * as published by the Free Software Foundation; either version 2
28
 * of the License, or (at your option) any later version.
29
 *
30
 * This program is distributed in the hope that it will be useful,
31
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
 * GNU General Public License for more details.
34
 *
35
 * You should have received a copy of the GNU General Public License
36
 * along with this program; if not, write to the Free Software
37
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
38
 *
39
 * For more information, contact:
40
 *
41
 *  Generalitat Valenciana
42
 *   Conselleria d'Infraestructures i Transport
43
 *   Av. Blasco Ib??ez, 50
44
 *   46010 VALENCIA
45
 *   SPAIN
46
 *
47
 *      +34 963862235
48
 *   gvsig@gva.es
49
 *      www.gvsig.gva.es
50
 *
51
 *    or
52
 *
53
 *   IVER T.I. S.A
54
 *   Salamanca 50
55
 *   46005 Valencia
56
 *   Spain
57
 *
58
 *   +34 963163400
59
 *   dac@iver.es
60
 */
61
/* CVS MESSAGES:
62
 *
63
 * $Id: GMLReaderTest.java 9917 2007-01-25 16:13:00Z jorpiell $
64
 * $Log$
65
 * Revision 1.1.2.5  2007-01-25 16:13:00  jorpiell
66
 * Se han sustituido las clases por las que hay en el nuevo driver de GML.
67
 *
68
 * Revision 1.8  2006/12/29 17:54:48  jorpiell
69
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
70
 *
71
 * Revision 1.7  2006/12/26 19:20:52  jorpiell
72
 * Se ha a?adido un nuevo fichero al test
73
 *
74
 * Revision 1.6  2006/12/22 11:25:44  csanchez
75
 * Nuevo parser GML 2.x para gml's sin esquema
76
 *
77
 * Revision 1.5  2006/10/11 08:48:49  jorpiell
78
 * Test actualizado
79
 *
80
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
81
 * Soporte para features complejas.
82
 *
83
 * Revision 1.3  2006/10/02 08:33:49  jorpiell
84
 * Cambios del 10 copiados al head
85
 *
86
 * Revision 1.1.2.2  2006/09/25 11:35:15  jorpiell
87
 * Se tienen en cuanta tablas a distintos niveles. En caso de anidamiento se cogen los resultados de la primera tabla que aparezca.
88
 *
89
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
90
 * Ya no se depende de geotools
91
 *
92
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
93
 * Se han hecho algunas modificaciones que necesitaba el WFS
94
 *
95
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
96
 * Primer commit del driver de Gml
97
 *
98
 *
99
 */
100
/**
101
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
102
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
103
 */
104
public class GMLReaderTest extends TestCase {
105
        private static String gmlFileWFS = "test/WFS-dmsolutionsGetFeature.xml";
106
        private static String gmlFileWFSDuplicados = "test/WFS-AtlasAvesGetFeature.xml";
107
        private static String gmlFilePoints = "test/GML-points.gml";
108
        private static String gmlFileLines = "test/GML-lines.gml";
109
        private static String gmlFilePolygons = "test/GML-polygons.gml";
110
        private static String gmlNomenclatorIdee = "test/GMLNomenclatorIdee.gml";
111
        private static String gmlNoSchema="test/GMLNomenclatorIdeeWithoutSchema.gml";
112
        private IGeometriesFactory factory = new GeometriesFactory();
113
        
114
        public void testWFS() throws Exception{
115
                assertEquals(parseFile(gmlFileWFS),495);//                
116
        }        
117

    
118
        public void testWFSDuplicados() throws Exception{
119
                assertEquals(parseFile(gmlFileWFSDuplicados),199);        
120
        }
121
        
122
        public void testParsePoints() throws Exception{
123
                assertEquals(parseFile(gmlFilePoints),25);
124
        }
125
        
126
        public void testParseLines() throws Exception{
127
                assertEquals(parseFile(gmlFileLines),10);
128
        }
129
        
130
        public void testParsePolygons() throws Exception{
131
                assertEquals(parseFile(gmlFilePolygons),3);
132
        }
133
        
134
        public void testNomenclatorIdee() throws Exception{
135
                assertEquals(parseFile(gmlNomenclatorIdee),1);
136
        }
137
        
138
        public void testParseNoSchema() throws Exception{
139
                assertEquals(parseFile(gmlNoSchema),1);
140
        }
141
                
142
        public int parseFile(String file) throws Exception{
143
                //Creamos un nuevo lector de GML, parseando los schemas y creando la tabla hash
144
                //con la estructura de tipos que necesitamos
145
                GMLReader reader = new GMLReader(new File(file),factory);                
146
                
147
                //Estas son las coordenadas de referencia en el plano
148
                //donde se dibujar?n las geometrias, hace referencia al <coordinates>
149
                Rectangle2D extent = reader.getExtent();
150
        
151
                IGMLFeaturesIterator iterator = reader.getFeaturesIterator();
152
                
153
                System.out.println("******* PARSEANDO ESQUEMA XML : \n");
154
                System.out.println("******* VERSION GML "+reader.getVersion());
155
                System.out.println("******* Espacio de Nombres por defecto : "+reader.getTargetNamespace());
156
                XMLElementsFactory.printEntities();
157
                XMLTypesFactory.printTypes();
158
                XMLSchemasFactory.printSchemas();
159
                
160
                int i=0;
161
                while (iterator.hasNext()){
162
                        System.out.println("*********  FEATURE NUMBER " + i + " ***********");
163
                        GMLSimpleFeature_v2 feature = (GMLSimpleFeature_v2) iterator.next();
164
                        Map values = feature.getValues();
165
                        Set keys = values.keySet();
166
                        Iterator it = keys.iterator();
167
                        System.out.println("********* DATOS QUE CONTIENE: ************\n" + feature.getGeom());
168
                        while (it.hasNext()){
169
                                String key = (String)it.next();                
170
                                Object value = values.get(key);
171
                                if (value instanceof ArrayList){
172
                                        printArrayList(key,(ArrayList)value,1);
173
                                }else if(value instanceof Hashtable){
174
                                        printComplexType((Hashtable)value,1);
175
                                }else{
176
                                        System.out.print(key + ": ");
177
                                        System.out.println(value);
178
                                }
179
                        }
180
                        i++;
181
                }
182
                System.out.println("NUM FEATURES: " + i);
183
                return i;
184
        }
185
        
186
        private void printComplexType(Map values,int level){
187
                String tab = "";
188
                for (int i=0 ; i<level ; i++){
189
                        tab = tab + "\t";
190
                }
191
                level++;
192
                Set keys = values.keySet();
193
                Iterator it = keys.iterator();
194
                while (it.hasNext()){
195
                        String key = (String)it.next();                
196
                        Object value = values.get(key);
197
                        if (value instanceof ArrayList){
198
                                ArrayList lValues = (ArrayList)value;
199
                                printArrayList(key,lValues,level);
200
                        }else if(value instanceof Hashtable){
201
                                printComplexType((Hashtable)value,level);
202
                        }else{
203
                                System.out.print(tab + key + ": ");
204
                                System.out.print(value + "\n");
205
                        }
206
                }
207
        }
208
        
209
        private void printArrayList(String name,ArrayList al, int level){
210
                String tab = "";
211
                int myLevel = level - 1;
212
                for (int i=0 ; i<myLevel ; i++){
213
                        tab = tab + "\t";
214
                }        
215
                System.out.println(tab + name + ": HAY " + al.size() + " OCURRENCIAS DEL ATRIBUTO " + name);
216
                for (int k=0 ; k<al.size() ; k++){
217
                        System.out.print(tab + "\t" + "OCURRENCIA NUMERO " + (k+1) + "\n");
218
                        Object oc = al.get(k);
219
                        if (oc instanceof ArrayList){
220
                                System.out.print("VECTOR");
221
                        }else if(oc instanceof Hashtable){
222
                                printComplexType((Hashtable)oc,level);
223
                        }else{
224
                                System.out.print(tab + "\t" + oc + "\n");
225
                        }
226
                }
227
        }
228
}