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 @ 40769
History | View | Annotate | Download (3.43 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
24 | |||
25 | package org.gvsig.remoteclient.wfs.filters.filterencoding; |
||
26 | |||
27 | import java.awt.geom.PathIterator; |
||
28 | |||
29 | import org.gvsig.fmap.geom.Geometry; |
||
30 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
31 | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
||
32 | import org.gvsig.fmap.geom.primitive.Surface; |
||
33 | import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation; |
||
34 | |||
35 | /**
|
||
36 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
37 | */
|
||
38 | public class GeometryFEQuery extends SpatialFEQuery{ |
||
39 | private Geometry geometry = null; |
||
40 | |||
41 | public GeometryFEQuery(WFSGeometryFilterOperation geometryOperation) {
|
||
42 | super(geometryOperation);
|
||
43 | this.geometry = geometryOperation.getGeometry();
|
||
44 | } |
||
45 | |||
46 | public String getFilterEncoding(){ |
||
47 | StringBuffer request = new StringBuffer(); |
||
48 | if (geometry.getType() == TYPES.SURFACE){
|
||
49 | Surface surface = (Surface)geometry; |
||
50 | request.append("<ogc:Intersects>");
|
||
51 | request.append("<ogc:PropertyName>" + spatialFilterOperation.getAttributeName() + "</ogc:PropertyName>"); |
||
52 | request.append("<gml:MultiSurface srsName=\"" + spatialFilterOperation.getSrsName() + "\">"); |
||
53 | request.append("<gml:surfaceMember>");
|
||
54 | request.append("<gml:Polygon>");
|
||
55 | request.append("<gml:exterior>");
|
||
56 | request.append("<gml:LinearRing>");
|
||
57 | request.append("<gml:coordinates cs=\",\" decimal=\".\" ts=\" \">");
|
||
58 | GeneralPathX generalPath = surface.getGeneralPath(); |
||
59 | PathIterator it = generalPath.getPathIterator(null); |
||
60 | int type;
|
||
61 | double[] coordinates = new double[6]; |
||
62 | double[] firstCoordinates = null; |
||
63 | while (!it.isDone()){
|
||
64 | type = it.currentSegment(coordinates); |
||
65 | switch (type) {
|
||
66 | case PathIterator.SEG_MOVETO: |
||
67 | case PathIterator.SEG_LINETO: |
||
68 | request.append(coordinates[0]);
|
||
69 | request.append(",");
|
||
70 | request.append(coordinates[1]);
|
||
71 | request.append(" ");
|
||
72 | if (firstCoordinates == null){ |
||
73 | firstCoordinates = new double[2]; |
||
74 | firstCoordinates[0] = coordinates[0]; |
||
75 | firstCoordinates[1] = coordinates[1]; |
||
76 | } |
||
77 | break;
|
||
78 | } |
||
79 | it.next(); |
||
80 | } |
||
81 | if ((coordinates[0] != firstCoordinates[0]) || |
||
82 | (coordinates[1] != firstCoordinates[1])){ |
||
83 | request.append(firstCoordinates[0]);
|
||
84 | request.append(",");
|
||
85 | request.append(firstCoordinates[1]);
|
||
86 | } |
||
87 | request.append("</gml:coordinates>");
|
||
88 | request.append("</gml:LinearRing>");
|
||
89 | request.append("</gml:exterior>");
|
||
90 | request.append("</gml:Polygon>");
|
||
91 | request.append("</gml:surfaceMember>");
|
||
92 | request.append("</gml:MultiSurface>");
|
||
93 | request.append("</ogc:Intersects>");
|
||
94 | } |
||
95 | return request.toString();
|
||
96 | } |
||
97 | |||
98 | |||
99 | } |