Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / drivers / geotools / WFSFilter.java @ 5948

History | View | Annotate | Download (6.87 KB)

1
package com.iver.cit.gvsig.fmap.drivers.geotools;
2

    
3
import java.util.Hashtable;
4
import java.util.Vector;
5

    
6
import org.geotools.filter.CompareFilter;
7
import org.geotools.filter.FilterFactory;
8
import org.gvsig.remoteClient.wfs.WFSAttribute;
9
import org.gvsig.remoteClient.wfs.WFSStatus;
10

    
11
import com.iver.andami.PluginServices;
12
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
13
import com.vividsolutions.jts.geom.Geometry;
14
import com.vividsolutions.jts.geom.GeometryCollection;
15
import com.vividsolutions.jts.geom.LineString;
16
import com.vividsolutions.jts.geom.MultiLineString;
17
import com.vividsolutions.jts.geom.MultiPoint;
18
import com.vividsolutions.jts.geom.MultiPolygon;
19
import com.vividsolutions.jts.geom.Point;
20
import com.vividsolutions.jts.geom.Polygon;
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: WFSFilter.java 5948 2006-06-21 12:35:45Z jorpiell $
65
 * $Log$
66
 * Revision 1.5  2006-06-21 12:35:45  jorpiell
67
 * Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
68
 *
69
 * Revision 1.4  2006/06/14 07:57:19  jorpiell
70
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
71
 *
72
 * Revision 1.3  2006/05/25 15:32:01  jorpiell
73
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
74
 *
75
 * Revision 1.2  2006/05/25 10:32:21  jorpiell
76
 * Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
77
 *
78
 * Revision 1.1  2006/05/23 08:07:00  jorpiell
79
 * A?adido un m?todo para detectar el tipo de geometr?a
80
 *
81
 *
82
 */
83
/**
84
 * This class creates a "filter encoding" filter to be used
85
 * by the WFS protocol
86
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
87
 */
88
public class WFSFilter {
89
        
90
        public static void createAttributeFilter(WFSStatus status){
91
//                FilterFactory filterFactory = FilterFactory.createFilterFactory();
92
//                CompareFilter filter = null;
93
//                try {
94
//                    filter = filterFactory.createCompareFilter(CompareFilter.COMPARE_GREATER_THAN);
95
//                    FeatureType featureType = features.getFeatures().getSchema();
96
//                    filter.addLeftValue(filterFactory.createAttributeExpression(featureType,"POP_2000"));
97
//                    filter.addRightValue(filterFactory.createLiteralExpression(100000));
98
//                } catch (IllegalFilterException e) {
99
//                    e.printStackTrace();
100
        }
101
        
102
        /**
103
         * It return true is the attributeType is a geometry
104
         * @param attributeType
105
         * Type to compare
106
         * @return
107
         */
108
        public static boolean isGeometry(String attributeType){
109
                if (attributeType == null){
110
                        return false;
111
                }
112
                
113
                if (attributeType.compareTo("gml:GeometryPropertyType") == 0){
114
                        return true;
115
                }
116
                if (attributeType.compareTo("gml:MultiLineStringPropertyType") == 0){
117
                        return true;
118
                }
119
                if (attributeType.compareTo("gml:PointPropertyType") == 0){
120
                        return true;
121
                }
122
                if (attributeType.compareTo("gml:MultiPointPropertyType") == 0){
123
                        return true;
124
                }
125
                if (attributeType.compareTo("gml:MultiPolygonPropertyType") == 0){
126
                        return true;
127
                }
128
                return false;
129
        }
130
        
131
        /**
132
         * Return the layer geometry
133
         * @param layer
134
         * Layer with a set of attributes
135
         * @return
136
         */
137
        public static String getGeometry(WFSLayerNode layer){
138
                   if (layer.getGeometry() != null){
139
                           return layer.getGeometry().getType().split(":")[1];
140
                   }
141
                   return "";
142
  
143
        }
144
        
145
        /**
146
         * It returns the attribute type. It has to remove the
147
         * namespace to can use the translation mechanism 
148
         * translations
149
         * @param attribute
150
         * Attribute to translate
151
         */
152
        public static String getAttributeType(WFSAttribute attribute){
153
                if (attribute.getType() == null){
154
                        return "";
155
                }
156
                if (isGeometry(attribute.getType())){
157
                        return attribute.getType().split(":")[1];
158
                }
159
                
160
                String sAttribute = "";
161
                if (attribute.getType().split(":").length > 1){
162
                        sAttribute = attribute.getType().split(":")[1];
163
                }else{
164
                        sAttribute = attribute.getType();
165
                }                
166
                return sAttribute;
167
        }
168
        
169
        public static Class getAttributeJavaType(WFSAttribute attribute){
170
                String sType = getAttributeType(attribute);
171
                Class clazz = GmlToJavaConversion.get(sType);
172
                if (clazz == null){
173
                        clazz = String.class;
174
                }
175
                return clazz;
176
        }
177
        
178
        public static class GmlToJavaConversion{
179
                private static Hashtable typeMap = new Hashtable();
180

    
181
            static {
182
                typeMap.put("STRING", String.class);
183
                typeMap.put("\"\"", String.class);
184
                typeMap.put("INTEGER", Integer.class);
185
                typeMap.put("INT", Integer.class);
186
                typeMap.put("0", Integer.class);
187
                typeMap.put("DOUBLE", Double.class);
188
                typeMap.put("0.0", Double.class);
189
                typeMap.put("FLOAT", Float.class);
190
                typeMap.put("0.0F", Float.class);
191
                typeMap.put("GEOMETRY", Geometry.class);
192
                typeMap.put("GEOMETRYPROPERTYTYPE", Geometry.class);
193
                typeMap.put("POINT", Point.class);
194
                typeMap.put("POINTPROPERTYTYPE", Point.class);
195
                typeMap.put("LINESTRING", LineString.class);
196
                typeMap.put("LINESTRINGPROPERTYTYPE", LineString.class);
197
                typeMap.put("POLYGON", Polygon.class);
198
                typeMap.put("POLYGONPROPERTYTYPE", Polygon.class);
199
                typeMap.put("MULTIPOINT", MultiPoint.class);
200
                typeMap.put("MULTIPOINTPROPERTYTYPE", MultiPoint.class);
201
                typeMap.put("MULTILINESTRING", MultiLineString.class);
202
                typeMap.put("MULTILINESTRINGPROPERTYTYPE", MultiLineString.class);
203
                typeMap.put("MULTIPOLYGON", MultiPolygon.class);
204
                typeMap.put("MULTIPOLYGONPROPERTYTYPE", MultiPolygon.class);
205
                typeMap.put("MULTIGEOMETRYPROPERTYTYPE", GeometryCollection.class);
206
                typeMap.put("GEOMETRYCOLLECTION", GeometryCollection.class);
207
                typeMap.put("GEOMETRYASSOCIATIONTYPE", Geometry.class);
208
            }
209
                
210
                public static Class get(String key){
211
                        return (Class)typeMap.get(key.toUpperCase());
212
                }
213
        }        
214
}