[mapserver-commits] r10508 -
sandbox/sdlime/common-expressions/mapserver
svn at osgeo.org
svn at osgeo.org
Fri Sep 17 16:52:33 EDT 2010
Author: assefa
Date: 2010-09-17 20:52:33 +0000 (Fri, 17 Sep 2010)
New Revision: 10508
Modified:
sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c
sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h
sandbox/sdlime/common-expressions/mapserver/mapwfs.c
Log:
add initial support for binary and logical common expressions
Modified: sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c 2010-09-17 16:07:02 UTC (rev 10507)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c 2010-09-17 20:52:33 UTC (rev 10508)
@@ -3093,6 +3093,8 @@
int bString=0;
char szTmp[256];
+
+
szBuffer[0] = '\0';
if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
return NULL;
@@ -3121,7 +3123,7 @@
strcat(szBuffer, " (\"[");
else
strcat(szBuffer, " ([");
- /* attribute */
+
strcat(szBuffer, psFilterNode->psLeftNode->pszValue);
if (bString)
@@ -4070,47 +4072,135 @@
}
-int FLTGetLogicalComparisonExpresssionObj(FilterEncodingNode *psFilterNode, layerObj *lp,
- expressionObj *expression)
+
+
+
+char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNode,
+ layerObj *lp)
{
+ char szBuffer[256];
+ char **aszBounds = NULL;
+ int nBounds = 0;
+ int bString=0;
+ char *pszExpression=NULL;
+ if (!psFilterNode ||
+ !(strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0))
+ return NULL;
+
+ if (!psFilterNode->psLeftNode || !psFilterNode->psRightNode )
+ return NULL;
+
/* -------------------------------------------------------------------- */
-/* OR and AND */
+/* Get the bounds value which are stored like boundmin;boundmax */
/* -------------------------------------------------------------------- */
- if (psFilterNode->psLeftNode && psFilterNode->psRightNode)
+ aszBounds = msStringSplit(psFilterNode->psRightNode->pszValue, ';', &nBounds);
+ if (nBounds != 2)
+ return NULL;
+/* -------------------------------------------------------------------- */
+/* check if the value is a numeric value or alphanumeric. If it */
+/* is alphanumeric, add quotes around attribute and values. */
+/* -------------------------------------------------------------------- */
+ bString = 0;
+ if (aszBounds[0])
{
- FLTFilterNodeToExpressionObj(psFilterNode->psLeftNode, lp /*, exp TODO: non working code, FIXME */);
- if (strcasecmp(psFilterNode->pszValue, "AND") == 0)
- expression->tokens[expression->numtokens++].token = MS_TOKEN_LOGICAL_AND;
- else
- expression->tokens[expression->numtokens++].token = MS_TOKEN_LOGICAL_OR;
- FLTFilterNodeToExpressionObj(psFilterNode->psRightNode, lp /*, exp TODO: non working code, FIXME */);
+ sprintf(szBuffer, "%s_type", psFilterNode->psLeftNode->pszValue);
+ if (msOWSLookupMetadata(&(lp->metadata), "OFG", szBuffer) != NULL &&
+ (strcasecmp(msOWSLookupMetadata(&(lp->metadata), "G", szBuffer), "Character") == 0))
+ bString = 1;
+ else if (FLTIsNumeric(aszBounds[0]) == MS_FALSE)
+ bString = 1;
}
+ if (!bString)
+ {
+ if (aszBounds[1])
+ {
+ if (FLTIsNumeric(aszBounds[1]) == MS_FALSE)
+ bString = 1;
+ }
+ }
+
+
/* -------------------------------------------------------------------- */
-/* NOT */
+/* build expresssion. */
/* -------------------------------------------------------------------- */
- else if (psFilterNode->psLeftNode &&
- strcasecmp(psFilterNode->pszValue, "NOT") == 0)
+ /* attribute */
+ if (bString)
+ sprintf(szBuffer, "%s", " (\"[");
+ else
+ sprintf(szBuffer, "%s", " ([");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ pszExpression = msStringConcatenate(pszExpression, psFilterNode->psLeftNode->pszValue);
+
+ if (bString)
+ sprintf(szBuffer, "%s", "]\" ");
+ else
+ sprintf(szBuffer, "%s", "] ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ sprintf(szBuffer, "%s", " >= ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ if (bString)
{
- expression->tokens[expression->numtokens++].token = MS_TOKEN_LOGICAL_NOT;
- FLTFilterNodeToExpressionObj(psFilterNode->psLeftNode, lp);
+ sprintf(szBuffer,"%s", "\"");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
}
- return MS_TRUE;
-}
+ sprintf(szBuffer, "%s", aszBounds[0]);
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ if (bString)
+ {
+ sprintf(szBuffer, "%s", "\"");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ }
+ sprintf(szBuffer, "%s", " AND ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
-int FLTGetBinaryComparisonExpresssionObj(FilterEncodingNode *psFilterNode, layerObj *lp,
- expressionObj *expression)
+ if (bString)
+ sprintf(szBuffer, "%s", " \"[");
+ else
+ sprintf(szBuffer, "%s", " [");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ /* attribute */
+ pszExpression = msStringConcatenate(pszExpression, psFilterNode->psLeftNode->pszValue);
+
+ if (bString)
+ sprintf(szBuffer, "%s", "]\" ");
+ else
+ sprintf(szBuffer, "%s", "] ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ sprintf(szBuffer, "%s", " <= ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ if (bString)
+ {
+ sprintf(szBuffer,"%s", "\"");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ }
+ sprintf(szBuffer, "%s", aszBounds[1]);
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ if (bString)
+ {
+ sprintf(szBuffer,"\"");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ }
+ strcat(szBuffer, ")");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ return pszExpression;
+}
+char *FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp)
{
- int n=0;
- int bString=0;
- char szTmp[256];
+ char szTmp[256];
+ char *pszExpression = NULL;
+ int bString;
- if (!expression)
- return MS_FALSE;
- if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
- return MS_FALSE;
+ if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
+ return NULL;
/* -------------------------------------------------------------------- */
/* check if the value is a numeric value or alphanumeric. If it */
@@ -4131,83 +4221,186 @@
if (psFilterNode->psRightNode->pszValue == NULL)
bString = 1;
-
- n = expression->numtokens;
+ /* attribute */
if (bString)
- expression->tokens[n].token = MS_TOKEN_BINDING_STRING;
+ sprintf(szTmp, "%s", " (\"[");
else
- expression->tokens[n].token = MS_TOKEN_BINDING_DOUBLE;
-
- expression->tokens[n].tokenval.bindval.item = strdup(psFilterNode->psLeftNode->pszValue);
+ sprintf(szTmp, "%s"," ([");
+ pszExpression = msStringConcatenate(pszExpression, szTmp);
+ pszExpression = msStringConcatenate(pszExpression, psFilterNode->psLeftNode->pszValue);
+ if (bString)
+ sprintf(szTmp, "%s","]\" ");
+ else
+ sprintf(szTmp, "%s", "] ");
+ pszExpression = msStringConcatenate(pszExpression, szTmp);
- n++;
-
- /* logical operator */
if (strcasecmp(psFilterNode->pszValue,
"PropertyIsEqualTo") == 0)
{
/*case insensitive set ? */
if (psFilterNode->psRightNode->pOther &&
(*(int *)psFilterNode->psRightNode->pOther) == 1)
- expression->tokens[n].token = MS_TOKEN_COMPARISON_IEQ;
+ {
+ sprintf(szTmp, "%s", "=="); /*TODO whar should be this??*/
+ }
else
- expression->tokens[n].token = MS_TOKEN_COMPARISON_EQ;
+ sprintf(szTmp, "%s", "==");
+
}
else if (strcasecmp(psFilterNode->pszValue,
"PropertyIsNotEqualTo") == 0)
- expression->tokens[n].token = MS_TOKEN_COMPARISON_NE;
+ sprintf(szTmp, "%s", " != ");
else if (strcasecmp(psFilterNode->pszValue,
"PropertyIsLessThan") == 0)
- expression->tokens[n].token = MS_TOKEN_COMPARISON_LT;
+ sprintf(szTmp, "%s", " < ");
else if (strcasecmp(psFilterNode->pszValue,
"PropertyIsGreaterThan") == 0)
- expression->tokens[n].token = MS_TOKEN_COMPARISON_GT;
+ sprintf(szTmp, "%s", " > ");
else if (strcasecmp(psFilterNode->pszValue,
"PropertyIsLessThanOrEqualTo") == 0)
- expression->tokens[n].token = MS_TOKEN_COMPARISON_LE;
+ sprintf(szTmp, "%s", " <= ");
else if (strcasecmp(psFilterNode->pszValue,
"PropertyIsGreaterThanOrEqualTo") == 0)
- expression->tokens[n].token = MS_TOKEN_COMPARISON_GE;
+ sprintf(szTmp, "%s", " >= ");
+ else if (strcasecmp(psFilterNode->pszValue,
+ "PropertyIsLike") == 0)
+ sprintf(szTmp, "%s", " ~* ");
+
+ pszExpression = msStringConcatenate(pszExpression, szTmp);
+ /* value */
+ if (bString)
+ sprintf(szTmp, "%s", "\"");
+ pszExpression = msStringConcatenate(pszExpression, szTmp);
+
+ if (psFilterNode->psRightNode->pszValue)
+ pszExpression = msStringConcatenate(pszExpression, psFilterNode->psRightNode->pszValue);
- n++;
- expression->tokens[n].token = MS_TOKEN_LITERAL_STRING;
- expression->tokens[n].tokenval.strval = strdup(psFilterNode->psRightNode->pszValue);
+ if (bString)
+ sprintf(szTmp, "%s", "\") ");
+
+ pszExpression = msStringConcatenate(pszExpression, szTmp);
- expression->numtokens = n;
+ return pszExpression;
+}
- return MS_TRUE;
+char *FLTGetLogicalComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp)
+{
+ char *pszExpression = NULL;
+ char *pszTmp = NULL;
+ char szBuffer[256];
+
+ if (!psFilterNode || !FLTIsLogicalFilterType(psFilterNode->pszValue))
+ return NULL;
+
+/* -------------------------------------------------------------------- */
+/* OR and AND */
+/* -------------------------------------------------------------------- */
+ if (psFilterNode->psLeftNode && psFilterNode->psRightNode)
+ {
+ pszTmp = FLTFilterNodeToCommonExpression(psFilterNode->psLeftNode, lp);
+ if (!pszTmp)
+ return NULL;
+
+ sprintf(szBuffer, "%s", " (");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ pszExpression = msStringConcatenate(pszExpression, pszTmp);
+ msFree(pszTmp);
+
+ sprintf(szBuffer, "%s", " ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ pszExpression = msStringConcatenate(pszExpression, psFilterNode->pszValue);
+ sprintf(szBuffer, "%s", " ");
+
+
+ pszTmp = FLTFilterNodeToCommonExpression(psFilterNode->psRightNode, lp);
+ if (!pszTmp)
+ return NULL;
+
+ pszExpression = msStringConcatenate(pszExpression, pszTmp);
+ msFree(pszTmp);
+
+ sprintf(szBuffer, "%s", ") ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+ }
+/* -------------------------------------------------------------------- */
+/* NOT */
+/* -------------------------------------------------------------------- */
+ else if (psFilterNode->psLeftNode &&
+ strcasecmp(psFilterNode->pszValue, "NOT") == 0)
+ {
+ pszTmp = FLTFilterNodeToCommonExpression(psFilterNode->psLeftNode, lp);
+ if (!pszTmp)
+ return NULL;
+
+ sprintf(szBuffer, "%s", " (NOT ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ pszExpression = msStringConcatenate(pszExpression, pszTmp);
+ msFree(pszTmp);
+
+ sprintf(szBuffer, "%s", ") ");
+ pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+ }
+
+
+ return pszExpression;
}
-expressionObj *FLTFilterNodeToExpressionObj(FilterEncodingNode *psFilterNode, layerObj *lp)
+char *FLTFilterNodeToCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp)
{
- expressionObj *exp =NULL;
+ char *pszExpression = NULL;
if (!psFilterNode)
return NULL;
- exp = (expressionObj *)malloc(sizeof(expressionObj));
- exp->numtokens = 0;
- //initExpression(exp);
-
if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON)
{
if ( psFilterNode->psLeftNode && psFilterNode->psRightNode)
{
if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
{
- FLTGetBinaryComparisonExpresssionObj(psFilterNode, lp, exp);
+ pszExpression = FLTGetBinaryComparisonCommonExpression(psFilterNode, lp);
}
}
+ else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)
+ {
+ pszExpression = FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp);
+ }
}
+
else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL)
- FLTGetLogicalComparisonExpresssionObj(psFilterNode, lp, exp);
+ pszExpression = FLTGetLogicalComparisonCommonExpression(psFilterNode, lp);
+
+ return pszExpression;
+}
- return exp;
+
+int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, char *pszExpression)
+{
+ int retval;
+
+ //msFreeQuery(&(map->query));
+ /* TODO : this should be done but crashs query->filter is corrupted and not NULL*/
+ // msInitQuery(&(map->query));
+
+ map->query.type = MS_QUERY_BY_FILTER;
+
+ map->query.filter = (expressionObj *) malloc(sizeof(expressionObj));
+ map->query.filter->string = strdup(pszExpression);
+ map->query.filter->type = 2000;
+ map->query.layer = iLayerIndex;
+ map->query.rect = map->extent;
+
+ retval = msQueryByFilter(map);
+
+ return retval;
}
-
#ifdef USE_LIBXML2
xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal)
Modified: sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h 2010-09-17 16:07:02 UTC (rev 10507)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h 2010-09-17 20:52:33 UTC (rev 10508)
@@ -122,8 +122,14 @@
MS_DLL_EXPORT int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS);
MS_DLL_EXPORT int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS);
-expressionObj *FLTFilterNodeToExpressionObj(FilterEncodingNode *psFilterNode, layerObj *lp);
+/*common-expressions*/
+MS_DLL_EXPORT char *FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
+MS_DLL_EXPORT char *FLTFilterNodeToCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
+MS_DLL_EXPORT int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, char *pszExpression);
+
+
+
#ifdef USE_LIBXML2
MS_DLL_EXPORT xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal);
#endif
Modified: sandbox/sdlime/common-expressions/mapserver/mapwfs.c
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapwfs.c 2010-09-17 16:07:02 UTC (rev 10507)
+++ sandbox/sdlime/common-expressions/mapserver/mapwfs.c 2010-09-17 20:52:33 UTC (rev 10508)
@@ -1782,6 +1782,8 @@
/* or groups. Need to be a bit more sophisticated here. */
/* -------------------------------------------------------------------- */
for (i=0; i<nFilters; i++) {
+ char *pszExpression=NULL;
+
iLayerIndex = msGetLayerIndex(map, layers[i]);
if (iLayerIndex < 0) {
msSetError(MS_WFSERR, "Invalid Typename in GetFeature : %s", "msWFSGetFeature()", layers[i]);
@@ -1813,9 +1815,13 @@
/*preparse the filter for gml aliases*/
FLTPreParseFilterForAlias(psNode, map, iLayerIndex, "G");
+ pszExpression = FLTFilterNodeToCommonExpression(psNode, GET_LAYER(map, iLayerIndex));
/* run filter. If no results are found, do not throw exception */
/* this is a null result */
- if( FLTApplyFilterToLayer(psNode, map, iLayerIndex, MS_FALSE) != MS_SUCCESS )
+
+
+ /*if( FLTApplyFilterToLayer(psNode, map, iLayerIndex, MS_FALSE) != MS_SUCCESS ) */
+ if (FLTApplyFilterToLayerCommonExpression(map, iLayerIndex, pszExpression) != MS_SUCCESS )
{
ms_error = msGetErrorObj();
@@ -1826,8 +1832,11 @@
}
}
- FLTFreeFilterEncodingNode( psNode );
+ FLTFreeFilterEncodingNode( psNode );
psNode = NULL;
+ if (pszExpression)
+ msFree(pszExpression);
+
}
if (paszFilter)
More information about the mapserver-commits
mailing list