[mapserver-commits] r10360 - sandbox/sdlime/common-expressions/mapserver

svn at osgeo.org svn at osgeo.org
Thu Jul 15 23:15:52 EDT 2010


Author: assefa
Date: 2010-07-16 03:15:52 +0000 (Fri, 16 Jul 2010)
New Revision: 10360

Modified:
   sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c
   sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h
Log:
convert filter nodes to expressionobj

Modified: sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c	2010-07-15 18:26:31 UTC (rev 10359)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c	2010-07-16 03:15:52 UTC (rev 10360)
@@ -1039,7 +1039,7 @@
        type expression*/
     else if (lp->connectiontype == MS_OGR)
     {
-	if (lp->filter.type != MS_EXPRESSION)
+      if (0)//lp->filter.type != MS_EXPRESSION)
 	{
 	    szExpression = FLTGetSQLExpression(psNode, lp);
 	    bConcatWhere = 1;
@@ -1072,7 +1072,7 @@
 
 	/* if the filter is set and it's an expression type, concatenate it with
                this filter. If not just free it */
-	if (lp->filter.string && lp->filter.type == MS_EXPRESSION)
+	if (0)//lp->filter.string && lp->filter.type == MS_EXPRESSION)
 	{
 	    pszBuffer = msStringConcatenate(pszBuffer, "((");
 	    if (bHasAWhere)
@@ -1087,7 +1087,7 @@
        
 	pszBuffer = msStringConcatenate(pszBuffer, szExpression);
 
-	if(lp->filter.string && lp->filter.type == MS_EXPRESSION)
+	if(0)//lp->filter.string && lp->filter.type == MS_EXPRESSION)
 	  pszBuffer = msStringConcatenate(pszBuffer, ")");
         
         
@@ -4070,6 +4070,144 @@
 }
 
 
+int FLTGetLogicalComparisonExpresssionObj(FilterEncodingNode *psFilterNode, layerObj *lp,
+                                         expressionObj *expression)
+{
+
+/* -------------------------------------------------------------------- */
+/*      OR and AND                                                      */
+/* -------------------------------------------------------------------- */
+    if (psFilterNode->psLeftNode && psFilterNode->psRightNode)
+    {
+        FLTFilterNodeToExpressionObj(psFilterNode->psLeftNode, lp, exp);
+        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);
+    }
+/* -------------------------------------------------------------------- */
+/*      NOT                                                             */
+/* -------------------------------------------------------------------- */
+    else if (psFilterNode->psLeftNode && 
+             strcasecmp(psFilterNode->pszValue, "NOT") == 0)
+    {
+        expression->tokens[expression->numtokens++].token = MS_TOKEN_LOGICAL_NOT;
+        FLTFilterNodeToExpressionObj(psFilterNode->psLeftNode, lp);    
+    }
+
+    return MS_TRUE;
+}
+
+
+int FLTGetBinaryComparisonExpresssionObj(FilterEncodingNode *psFilterNode, layerObj *lp,
+                                         expressionObj *expression)
+{
+    int n=0;
+    int bString=0;
+    char szTmp[256];
+
+    if (!expression)
+      return MS_FALSE;
+    if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
+      return  MS_FALSE;
+
+/* -------------------------------------------------------------------- */
+/*      check if the value is a numeric value or alphanumeric. If it    */
+/*      is alphanumeric, add quotes around attribute and values.        */
+/* -------------------------------------------------------------------- */
+    bString = 0;
+    if (psFilterNode->psRightNode->pszValue)
+    {
+        sprintf(szTmp, "%s_type",  psFilterNode->psLeftNode->pszValue);
+        if (msOWSLookupMetadata(&(lp->metadata), "OFG", szTmp) != NULL &&
+            (strcasecmp(msOWSLookupMetadata(&(lp->metadata), "G", szTmp), "Character") == 0))
+          bString = 1;
+        else if (FLTIsNumeric(psFilterNode->psRightNode->pszValue) == MS_FALSE)    
+          bString = 1;
+    }
+
+    /* specical case to be able to have empty strings in the expression. */
+    if (psFilterNode->psRightNode->pszValue == NULL)
+      bString = 1;
+
+    
+    n = expression->numtokens;
+    if (bString)
+      expression->tokens[n].token = MS_TOKEN_BINDING_STRING;
+    else
+      expression->tokens[n].token = MS_TOKEN_BINDING_DOUBLE;
+    
+    expression->tokens[n].tokenval.bindval.item = strdup(psFilterNode->psLeftNode->pszValue);
+
+    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;
+        else
+          expression->tokens[n].token =  MS_TOKEN_COMPARISON_EQ;
+    }
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsNotEqualTo") == 0)
+      expression->tokens[n].token = MS_TOKEN_COMPARISON_NE;
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsLessThan") == 0)
+      expression->tokens[n].token = MS_TOKEN_COMPARISON_LT;
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsGreaterThan") == 0)
+      expression->tokens[n].token = MS_TOKEN_COMPARISON_GT;
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsLessThanOrEqualTo") == 0)
+      expression->tokens[n].token = MS_TOKEN_COMPARISON_LE;
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsGreaterThanOrEqualTo") == 0)
+       expression->tokens[n].token = MS_TOKEN_COMPARISON_GE;
+
+
+    n++;
+    expression->tokens[n].token = MS_TOKEN_LITERAL_STRING;
+    expression->tokens[n].tokenval.strval = strdup(psFilterNode->psRightNode->pszValue);
+
+    expression->numtokens = n;
+
+    return  MS_TRUE;
+
+}
+
+expressionObj *FLTFilterNodeToExpressionObj(FilterEncodingNode *psFilterNode, layerObj *lp)
+{
+    expressionObj *exp =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);
+            }
+        }
+    }
+    else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL)
+      FLTGetLogicalComparisonExpresssionObj(psFilterNode, lp, exp);
+
+    return exp;
+}
+
+
 #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-07-15 18:26:31 UTC (rev 10359)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h	2010-07-16 03:15:52 UTC (rev 10360)
@@ -122,6 +122,7 @@
 
 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);
 
 #ifdef USE_LIBXML2
 MS_DLL_EXPORT xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal);



More information about the mapserver-commits mailing list