1 /**********************************************************************
2  * $Id$
3  *
4  * Project:  MapServer
5  * Purpose:  OGC Filter Encoding implementation
6  * Author:   Y. Assefa, DM Solutions Group (assefa@dmsolutions.ca)
7  *
8  **********************************************************************
9  * Copyright (c) 2003, Y. Assefa, DM Solutions Group Inc
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies of this Software or works derived from this Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  ****************************************************************************/
28 
29 #ifndef MAPOGCFILTER_H
30 #define MAPOGCFILTER_H
31 
32 #include "mapserver.h"
33 
34 /* There is a dependency to OGR for the MiniXML parser */
35 #include "cpl_minixml.h"
36 
37 #ifdef USE_LIBXML2
38 
39 #include<libxml/parser.h>
40 #include<libxml/tree.h>
41 #endif
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 typedef struct {
48   char *pszWildCard;
49   char *pszSingleChar;
50   char *pszEscapeChar;
51   int  bCaseInsensitive;
52 } FEPropertyIsLike;
53 
54 /* -------------------------------------------------------------------- */
55 /*      prototypes.                                                     */
56 /* -------------------------------------------------------------------- */
57 MS_DLL_EXPORT int FLTIsNumeric(const char *pszValue);
58 MS_DLL_EXPORT int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression);
59 MS_DLL_EXPORT  char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char *value,  int forcecharcter);
60 
61 MS_DLL_EXPORT FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString);
62 MS_DLL_EXPORT FilterEncodingNode *FLTCreateFilterEncodingNode(void);
63 MS_DLL_EXPORT char** FLTSplitFilters(const char* pszStr, int* pnTokens);
64 MS_DLL_EXPORT int FLTApplyFilterToLayer(FilterEncodingNode *psNode, mapObj *map,
65                                         int iLayerIndex);
66 
67 MS_DLL_EXPORT int FLTLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map,
68     int iLayerIndex);
69 MS_DLL_EXPORT int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map,
70     int iLayerIndex);
71 
72 MS_DLL_EXPORT void FLTFreeFilterEncodingNode(FilterEncodingNode *psFilterNode);
73 
74 MS_DLL_EXPORT int FLTValidFilterNode(FilterEncodingNode *psFilterNode);
75 MS_DLL_EXPORT int FLTValidForBBoxFilter(FilterEncodingNode *psFilterNode);
76 MS_DLL_EXPORT int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode,
77                                         const char *szType);
78 MS_DLL_EXPORT int FLTIsBBoxFilter(FilterEncodingNode *psFilterNode);
79 MS_DLL_EXPORT int FLTIsPointFilter(FilterEncodingNode *psFilterNode);
80 MS_DLL_EXPORT int FLTIsLineFilter(FilterEncodingNode *psFilterNode);
81 MS_DLL_EXPORT int FLTIsPolygonFilter(FilterEncodingNode *psFilterNode);
82 
83 MS_DLL_EXPORT int FLTValidForPropertyIsLikeFilter(FilterEncodingNode *psFilterNode);
84 MS_DLL_EXPORT int FLTIsOnlyPropertyIsLike(FilterEncodingNode *psFilterNode);
85 
86 MS_DLL_EXPORT void FLTInsertElementInNode(FilterEncodingNode *psFilterNode,
87     CPLXMLNode *psXMLNode);
88 MS_DLL_EXPORT int FLTIsLogicalFilterType(const char *pszValue);
89 MS_DLL_EXPORT int FLTIsBinaryComparisonFilterType(const char *pszValue);
90 MS_DLL_EXPORT int FLTIsComparisonFilterType(const char *pszValue);
91 MS_DLL_EXPORT int FLTIsFeatureIdFilterType(const char *pszValue);
92 MS_DLL_EXPORT int FLTIsSpatialFilterType(const char *pszValue);
93 MS_DLL_EXPORT int FLTIsTemporalFilterType(const char *pszValue);
94 MS_DLL_EXPORT int FLTIsSupportedFilterType(CPLXMLNode *psXMLNode);
95 
96 MS_DLL_EXPORT const char *FLTGetBBOX(FilterEncodingNode *psFilterNode, rectObj *psRect);
97 const char* FLTGetDuring(FilterEncodingNode *psFilterNode, const char** ppszTimeField);
98 
99 MS_DLL_EXPORT shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance,
100                                     int *pnUnit);
101 
102 MS_DLL_EXPORT int FLTHasSpatialFilter(FilterEncodingNode *psFilterNode);
103 
104 
105 /*SQL expressions related functions.*/
106 MS_DLL_EXPORT int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map,
107     int iLayerIndex);
108 
109 MS_DLL_EXPORT char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode,layerObj *lp);
110 MS_DLL_EXPORT char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
111 MS_DLL_EXPORT char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
112 MS_DLL_EXPORT char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
113 
114 MS_DLL_EXPORT char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode,
115     layerObj *lp);
116 MS_DLL_EXPORT int FLTIsSimpleFilter(FilterEncodingNode *psFilterNode);
117 
118 MS_DLL_EXPORT FilterEncodingNode *FLTCreateFeatureIdFilterEncoding(const char *pszString);
119 
120 MS_DLL_EXPORT int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS);
121 MS_DLL_EXPORT  int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS);
122 
123 /*common-expressions*/
124 MS_DLL_EXPORT   char *FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
125 MS_DLL_EXPORT  char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
126 char* FLTGetTimeExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
127 MS_DLL_EXPORT int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, const char *pszExpression);
128 
129 #ifdef USE_LIBXML2
130 MS_DLL_EXPORT xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal);
131 #endif
132 
133 void FLTDoAxisSwappingIfNecessary(mapObj *map, FilterEncodingNode *psFilterNode, int bDefaultSRSNeedsAxisSwapping);
134 
135 void FLTPreParseFilterForAliasAndGroup(FilterEncodingNode *psFilterNode,
136                                        mapObj *map, int i, const char *namespaces);
137 int FLTCheckFeatureIdFilters(FilterEncodingNode *psFilterNode,
138                              mapObj *map, int i);
139 int FLTCheckInvalidOperand(FilterEncodingNode *psFilterNode);
140 int FLTCheckInvalidProperty(FilterEncodingNode *psFilterNode,
141                             mapObj *map, int i);
142 FilterEncodingNode* FLTSimplify(FilterEncodingNode *psFilterNode,
143                                 int* pnEvaluation);
144 int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, const char *pszExpression, rectObj rect);
145 int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode,
146                             mapObj *map, int i);
147 int FLTLayerSetInvalidRectIfSupported(layerObj* lp, rectObj* rect);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
154