Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / filters / filterencoding / GeometryFEQuery.java @ 40559

History | View | Annotate | Download (3.5 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {Iver T.I.}   {Task}
27
 */
28

    
29
package org.gvsig.remoteclient.wfs.filters.filterencoding;
30

    
31
import java.awt.geom.PathIterator;
32

    
33
import org.gvsig.fmap.geom.Geometry;
34
import org.gvsig.fmap.geom.Geometry.TYPES;
35
import org.gvsig.fmap.geom.primitive.GeneralPathX;
36
import org.gvsig.fmap.geom.primitive.Surface;
37
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
38

    
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41
 */
42
public class GeometryFEQuery extends SpatialFEQuery{
43
        private Geometry geometry = null;
44

    
45
        public GeometryFEQuery(WFSGeometryFilterOperation geometryOperation) {
46
                super(geometryOperation);
47
                this.geometry = geometryOperation.getGeometry();        
48
        }
49
        
50
        public String getFilterEncoding(){
51
                StringBuffer request = new StringBuffer();
52
                if (geometry.getType() == TYPES.SURFACE){
53
                        Surface surface = (Surface)geometry;
54
                        request.append("<ogc:Intersects>");
55
                        request.append("<ogc:PropertyName>" + spatialFilterOperation.getAttributeName() + "</ogc:PropertyName>");
56
                        request.append("<gml:MultiSurface srsName=\"" + spatialFilterOperation.getSrsName() + "\">");
57
                        request.append("<gml:surfaceMember>");
58
                        request.append("<gml:Polygon>");
59
                        request.append("<gml:exterior>");
60
                        request.append("<gml:LinearRing>");
61
                        request.append("<gml:coordinates cs=\",\" decimal=\".\" ts=\" \">");
62
                        GeneralPathX generalPath = surface.getGeneralPath();
63
                        PathIterator it = generalPath.getPathIterator(null);
64
                        int type;
65
                        double[] coordinates = new double[6];
66
                        double[] firstCoordinates = null;
67
                        while (!it.isDone()){
68
                                type = it.currentSegment(coordinates);
69
                                switch (type) {
70
                                        case PathIterator.SEG_MOVETO:
71
                                        case PathIterator.SEG_LINETO:
72
                                                request.append(coordinates[0]);
73
                                                request.append(",");
74
                                                request.append(coordinates[1]);        
75
                                                request.append(" ");
76
                                                if (firstCoordinates == null){
77
                                                        firstCoordinates = new double[2];
78
                                                        firstCoordinates[0] = coordinates[0];
79
                                                        firstCoordinates[1] = coordinates[1];
80
                                                }
81
                                                break;
82
                                }                                
83
                                it.next();
84
                        }
85
                        if ((coordinates[0] != firstCoordinates[0]) || 
86
                                        (coordinates[1] != firstCoordinates[1])){
87
                                request.append(firstCoordinates[0]);
88
                                request.append(",");
89
                                request.append(firstCoordinates[1]);        
90
                        }
91
                        request.append("</gml:coordinates>");
92
                        request.append("</gml:LinearRing>");
93
                        request.append("</gml:exterior>");
94
                        request.append("</gml:Polygon>");
95
                        request.append("</gml:surfaceMember>");
96
                        request.append("</gml:MultiSurface>");
97
                        request.append("</ogc:Intersects>");
98
                }
99
                return request.toString();
100
        }
101

    
102

    
103
}
104