[mapserver-commits] r9140 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Jul 6 12:29:03 EDT 2009


Author: assefa
Date: 2009-07-06 12:29:03 -0400 (Mon, 06 Jul 2009)
New Revision: 9140

Modified:
   trunk/mapserver/mapogcfilter.c
   trunk/mapserver/mapogcfilter.h
Log:
Use field type metadata if available #3052

Modified: trunk/mapserver/mapogcfilter.c
===================================================================
--- trunk/mapserver/mapogcfilter.c	2009-07-06 16:23:43 UTC (rev 9139)
+++ trunk/mapserver/mapogcfilter.c	2009-07-06 16:29:03 UTC (rev 9140)
@@ -44,6 +44,43 @@
     return (*(int*)a) - (*(int*)b);
 }
 
+static FLTIsNumeric(char *pszValue)
+{
+    if (pszValue)
+    {
+          /*the regex seems to have a problem on windows when mapserver is built using
+            PHP regex*/
+#if defined(_WIN32) && !defined(__CYGWIN__)
+        int i = 0, nLength=0, bString=0;
+
+        nLength = strlen(pszValue);
+        for (i=0; i<nLength; i++)
+        {
+            if (i == 0)
+            {
+                if (!isdigit(pszValue[i]) &&  pszValue[i] != '-')
+                {
+                     bString = 1;
+                     break;
+                }
+            }
+            else if (!isdigit(pszValue[i]) &&  pszValue[i] != '.')
+            {
+                bString = 1;
+                break;
+            }
+        }
+        if (!bString)
+          return MS_TRUE;
+#else
+        if (msEvalRegex("[-+]?\\b([0-9]*\\.[0-9]+|[0-9]+)\\b", pszValue) == MS_TRUE)
+          return MS_TRUE;
+#endif
+    }
+
+    return MS_FALSE;
+}
+
 int FLTogrConvertGeometry(OGRGeometryH hGeometry, shapeObj *psShape,
                           OGRwkbGeometryType nType) 
 {
@@ -2610,7 +2647,7 @@
     const char *pszAttribute = NULL;
     char szTmp[256];
     char **tokens = NULL;
-    int nTokens = 0, i=0,j=0, nLength=0, bString=0;
+    int nTokens = 0, i=0,bString=0;
     char *pszTmp;
     
     if (!psFilterNode)
@@ -2622,12 +2659,12 @@
         {
             if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
             {
-                pszExpression = FLTGetBinaryComparisonExpresssion(psFilterNode);
+              pszExpression = FLTGetBinaryComparisonExpresssion(psFilterNode, lp);
             }
             else if (strcasecmp(psFilterNode->pszValue, 
                                 "PropertyIsBetween") == 0)
             {
-                 pszExpression = FLTGetIsBetweenComparisonExpresssion(psFilterNode);
+              pszExpression = FLTGetIsBetweenComparisonExpresssion(psFilterNode, lp);
             }
             else if (strcasecmp(psFilterNode->pszValue, 
                                 "PropertyIsLike") == 0)
@@ -2641,11 +2678,11 @@
         if (strcasecmp(psFilterNode->pszValue, "AND") == 0 ||
             strcasecmp(psFilterNode->pszValue, "OR") == 0)
         {
-            pszExpression = FLTGetLogicalComparisonExpresssion(psFilterNode);
+          pszExpression = FLTGetLogicalComparisonExpresssion(psFilterNode, lp);
         }
         else if (strcasecmp(psFilterNode->pszValue, "NOT") == 0)
         {       
-            pszExpression = FLTGetLogicalComparisonExpresssion(psFilterNode);
+          pszExpression = FLTGetLogicalComparisonExpresssion(psFilterNode, lp);
         }
     }
     else if (psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL)
@@ -2668,17 +2705,10 @@
                         if (i == 0)
                         {
                             pszTmp = tokens[0];
-                            nLength = strlen(pszTmp);
-                            for (j=0; j<nLength; j++)
-                            {
-                                if (!isdigit(pszTmp[j]) &&  pszTmp[j] != '.')
-                                {
-                                    bString = 1;
-                                    break;
-                                }
-                            }
+                            if(FLTIsNumeric(pszTmp) == MS_FALSE) 
+                              bString = 1;
                         }
-                         if (bString)
+                        if (bString)
                           sprintf(szTmp, "('[%s]' = '%s')" , pszAttribute, tokens[i]);
                         else
                            sprintf(szTmp, "([%s] = %s)" , pszAttribute, tokens[i]);
@@ -2720,7 +2750,7 @@
     const char *pszAttribute = NULL;
     char szTmp[256];
     char **tokens = NULL;
-    int nTokens = 0, i=0,j=0, nLength=0,bString=0;
+    int nTokens = 0, i=0, bString=0;
     char *pszTmp;
 
     if (psFilterNode == NULL || lp == NULL)
@@ -2734,13 +2764,13 @@
             if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
             {
                 pszExpression = 
-                  FLTGetBinaryComparisonSQLExpresssion(psFilterNode);
+                  FLTGetBinaryComparisonSQLExpresssion(psFilterNode, lp);
             }            
             else if (strcasecmp(psFilterNode->pszValue, 
                                 "PropertyIsBetween") == 0)
             {
                  pszExpression = 
-                   FLTGetIsBetweenComparisonSQLExpresssion(psFilterNode);
+                   FLTGetIsBetweenComparisonSQLExpresssion(psFilterNode, lp);
             }
             else if (strcasecmp(psFilterNode->pszValue, 
                                 "PropertyIsLike") == 0)
@@ -2789,15 +2819,8 @@
                         if (i == 0)
                         {
                             pszTmp = tokens[0];
-                            nLength = strlen(pszTmp);
-                            for (j=0; i<nLength; j++)
-                            {
-                                if (!isdigit(pszTmp[j]) &&  pszTmp[j] != '.')
-                                {
-                                    bString = 1;
-                                    break;
-                                }
-                            }
+                            if (FLTIsNumeric(pszTmp) == MS_FALSE)    
+                               bString = 1;
                         }
                         if (bString)
                           sprintf(szTmp, "(%s = '%s')" , pszAttribute, tokens[i]);
@@ -2806,12 +2829,19 @@
 
                         if (pszExpression != NULL)
                           pszExpression = msStringConcatenate(pszExpression, " OR ");
+                        else
+                          /*opening and closing brackets*/
+                          pszExpression = msStringConcatenate(pszExpression, "(");
+
                         pszExpression = msStringConcatenate(pszExpression, szTmp);
                     }
 
                     msFreeCharArray(tokens, nTokens);
                 }
             }
+            /*opening and closing brackets*/
+            if (pszExpression)
+               pszExpression = msStringConcatenate(pszExpression, ")");
         }
 #else
         msSetError(MS_MISCERR, "OWS support is not available.", 
@@ -2828,20 +2858,20 @@
 /*                                                                      */
 /*      Return the expresion for a specific node.                       */
 /************************************************************************/
-char *FLTGetNodeExpression(FilterEncodingNode *psFilterNode)
+char *FLTGetNodeExpression(FilterEncodingNode *psFilterNode, layerObj *lp)
 {
     char *pszExpression = NULL;
     if (!psFilterNode)
       return NULL;
 
     if (FLTIsLogicalFilterType(psFilterNode->pszValue))
-      pszExpression = FLTGetLogicalComparisonExpresssion(psFilterNode);
+      pszExpression = FLTGetLogicalComparisonExpresssion(psFilterNode, lp);
     else if (FLTIsComparisonFilterType(psFilterNode->pszValue))
     {
         if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
-          pszExpression = FLTGetBinaryComparisonExpresssion(psFilterNode);
+          pszExpression = FLTGetBinaryComparisonExpresssion(psFilterNode, lp);
         else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)
-          pszExpression = FLTGetIsBetweenComparisonExpresssion(psFilterNode);
+          pszExpression = FLTGetIsBetweenComparisonExpresssion(psFilterNode, lp);
         else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0)
           pszExpression = FLTGetIsLikeComparisonExpression(psFilterNode);
     }
@@ -2952,7 +2982,7 @@
 /*                                                                      */
 /*      Return the expression for logical comparison expression.        */
 /************************************************************************/
-char *FLTGetLogicalComparisonExpresssion(FilterEncodingNode *psFilterNode)
+char *FLTGetLogicalComparisonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp)
 {
     char *pszTmp = NULL;
     char *pszBuffer = NULL;
@@ -2978,9 +3008,9 @@
         if (strcasecmp(psFilterNode->psLeftNode->pszValue, "BBOX") != 0 &&
             strcasecmp(psFilterNode->psLeftNode->pszValue, "DWithin") != 0 &&
             FLTIsGeosNode(psFilterNode->psLeftNode->pszValue) == MS_FALSE)
-          pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode);
+          pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode, lp);
         else
-          pszTmp = FLTGetNodeExpression(psFilterNode->psRightNode);
+          pszTmp = FLTGetNodeExpression(psFilterNode->psRightNode, lp);
 
         if (!pszTmp)
           return NULL;
@@ -3005,9 +3035,9 @@
          (strcasecmp(psFilterNode->psRightNode->pszValue, "PropertyIsLike") == 0)))
     {
         if (strcasecmp(psFilterNode->psLeftNode->pszValue, "PropertyIsLike") != 0)
-          pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode);
+          pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode, lp);
         else
-          pszTmp = FLTGetNodeExpression(psFilterNode->psRightNode);
+          pszTmp = FLTGetNodeExpression(psFilterNode->psRightNode, lp);
 
         if (!pszTmp)
           return NULL;
@@ -3023,7 +3053,7 @@
 /* -------------------------------------------------------------------- */
     if (psFilterNode->psLeftNode && psFilterNode->psRightNode)
     {
-        pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode);
+      pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode, lp);
         if (!pszTmp)
           return NULL;
 
@@ -3036,7 +3066,7 @@
         strcat(pszBuffer, " ");
         strcat(pszBuffer, psFilterNode->pszValue);
         strcat(pszBuffer, " ");
-        pszTmp = FLTGetNodeExpression(psFilterNode->psRightNode);
+        pszTmp = FLTGetNodeExpression(psFilterNode->psRightNode, lp);
         if (!pszTmp)
           return NULL;
 
@@ -3053,7 +3083,7 @@
     else if (psFilterNode->psLeftNode && 
              strcasecmp(psFilterNode->pszValue, "NOT") == 0)
     {
-        pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode);
+      pszTmp = FLTGetNodeExpression(psFilterNode->psLeftNode, lp);
         if (!pszTmp)
           return NULL;
 
@@ -3078,10 +3108,11 @@
 /*                                                                      */
 /*      Return the expression for a binary comparison filter node.      */
 /************************************************************************/
-char *FLTGetBinaryComparisonExpresssion(FilterEncodingNode *psFilterNode)
+char *FLTGetBinaryComparisonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp)
 {
     char szBuffer[1024];
-    int i=0, bString=0, nLenght = 0;
+    int bString=0;
+    char szTmp[256];
 
     szBuffer[0] = '\0';
     if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
@@ -3094,18 +3125,12 @@
     bString = 0;
     if (psFilterNode->psRightNode->pszValue)
     {
-        nLenght = strlen(psFilterNode->psRightNode->pszValue);
-        for (i=0; i<nLenght; i++)
-        {
-            if (!isdigit(psFilterNode->psRightNode->pszValue[i]) &&
-                psFilterNode->psRightNode->pszValue[i] != '.')
-            {
-                /* if (psFilterNode->psRightNode->pszValue[i] < '0' || */
-                /* psFilterNode->psRightNode->pszValue[i] > '9') */
-                bString = 1;
-                break;
-            }
-        }
+        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. */
@@ -3179,11 +3204,12 @@
 /*                                                                      */
 /*      Return the expression for a binary comparison filter node.      */
 /************************************************************************/
-char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode)
+char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode,
+                                           layerObj *lp)
 {
     char szBuffer[1024];
-    int i=0, bString=0, nLenght = 0;
-    char szTmp[100];
+    int bString=0;
+    char szTmp[256];
 
     szBuffer[0] = '\0';
     if (!psFilterNode || !
@@ -3197,18 +3223,13 @@
     bString = 0;
     if (psFilterNode->psRightNode->pszValue)
     {
-        nLenght = strlen(psFilterNode->psRightNode->pszValue);
-        for (i=0; i<nLenght; i++)
-        {
-            if (!isdigit(psFilterNode->psRightNode->pszValue[i]) &&
-                psFilterNode->psRightNode->pszValue[i] != '.')
-            {
-                /* if (psFilterNode->psRightNode->pszValue[i] < '0' || */
-                /* psFilterNode->psRightNode->pszValue[i] > '9') */
-                bString = 1;
-                break;
-            }
-        }
+        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. */
@@ -3293,12 +3314,14 @@
 /*                                                                      */
 /*      Build an SQL expresssion for IsBteween Filter.                  */
 /************************************************************************/
-char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode)
+char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode,
+                                              layerObj *lp)
 {
     char szBuffer[1024];
     char **aszBounds = NULL;
     int nBounds = 0;
-    int i=0, bString=0, nLenght = 0;
+    int bString=0;
+    char szTmp[256];
 
 
     szBuffer[0] = '\0';
@@ -3322,29 +3345,19 @@
     bString = 0;
     if (aszBounds[0])
     {
-        nLenght = strlen(aszBounds[0]);
-        for (i=0; i<nLenght; i++)
-        {
-            if (!isdigit(aszBounds[0][i]) && aszBounds[0][i] != '.')
-            {
-                bString = 1;
-                break;
-            }
-        }
+        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(aszBounds[0]) == MS_FALSE)    
+          bString = 1;
     }
     if (!bString)
     {
         if (aszBounds[1])
         {
-            nLenght = strlen(aszBounds[1]);
-            for (i=0; i<nLenght; i++)
-            {
-                if (!isdigit(aszBounds[1][i]) && aszBounds[1][i] != '.')
-                {
-                    bString = 1;
-                    break;
-                }
-            }
+            if (FLTIsNumeric(aszBounds[1]) == MS_FALSE)    
+              bString = 1;
         }
     }
         
@@ -3389,12 +3402,14 @@
 /*                                                                      */
 /*      Build expresssion for IsBteween Filter.                         */
 /************************************************************************/
-char *FLTGetIsBetweenComparisonExpresssion(FilterEncodingNode *psFilterNode)
+char *FLTGetIsBetweenComparisonExpresssion(FilterEncodingNode *psFilterNode,
+                                           layerObj *lp)
 {
     char szBuffer[1024];
     char **aszBounds = NULL;
     int nBounds = 0;
-    int i=0, bString=0, nLenght = 0;
+    int bString=0;
+    char szTmp[256];
 
 
     szBuffer[0] = '\0';
@@ -3418,29 +3433,19 @@
     bString = 0;
     if (aszBounds[0])
     {
-        nLenght = strlen(aszBounds[0]);
-        for (i=0; i<nLenght; i++)
-        {
-            if (!isdigit(aszBounds[0][i]) && aszBounds[0][i] != '.')
-            {
-                bString = 1;
-                break;
-            }
-        }
+        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(aszBounds[0]) == MS_FALSE)    
+          bString = 1;
     }
     if (!bString)
     {
         if (aszBounds[1])
         {
-            nLenght = strlen(aszBounds[1]);
-            for (i=0; i<nLenght; i++)
-            {
-                if (!isdigit(aszBounds[1][i]) && aszBounds[1][i] != '.')
-                {
-                    bString = 1;
-                    break;
-                }
-            }
+            if (FLTIsNumeric(aszBounds[1]) == MS_FALSE)    
+              bString = 1;  
         }
     }
         

Modified: trunk/mapserver/mapogcfilter.h
===================================================================
--- trunk/mapserver/mapogcfilter.h	2009-07-06 16:23:43 UTC (rev 9139)
+++ trunk/mapserver/mapogcfilter.h	2009-07-06 16:29:03 UTC (rev 9140)
@@ -93,15 +93,15 @@
 
 MS_DLL_EXPORT char *FLTGetMapserverExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
 MS_DLL_EXPORT char *FLTGetMapserverExpressionClassItem(FilterEncodingNode *psFilterNode);
-MS_DLL_EXPORT char *FLTGetNodeExpression(FilterEncodingNode *psFilterNode);
+MS_DLL_EXPORT char *FLTGetNodeExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
 MS_DLL_EXPORT char *FLTGetBBOX(FilterEncodingNode *psFilterNode, rectObj *psRect);
 
 MS_DLL_EXPORT shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance,
                       int *pnUnit);
 
-MS_DLL_EXPORT char *FLTGetLogicalComparisonExpresssion(FilterEncodingNode *psFilterNode);
-MS_DLL_EXPORT char *FLTGetBinaryComparisonExpresssion(FilterEncodingNode *psFilterNode);
-MS_DLL_EXPORT char *FLTGetIsBetweenComparisonExpresssion(FilterEncodingNode *psFilterNode);
+MS_DLL_EXPORT char *FLTGetLogicalComparisonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
+MS_DLL_EXPORT char *FLTGetBinaryComparisonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
+MS_DLL_EXPORT char *FLTGetIsBetweenComparisonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
 MS_DLL_EXPORT char *FLTGetIsLikeComparisonExpression(FilterEncodingNode *psFilterNode);
 MS_DLL_EXPORT int FLTHasSpatialFilter(FilterEncodingNode *psFilterNode);
 
@@ -111,8 +111,8 @@
                           int iLayerIndex);
 
 MS_DLL_EXPORT char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode,layerObj *lp);
-MS_DLL_EXPORT char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode);
-MS_DLL_EXPORT char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode);
+MS_DLL_EXPORT char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
+MS_DLL_EXPORT char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp);
 MS_DLL_EXPORT char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode,
                                        int connectiontype);
 MS_DLL_EXPORT char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode,



More information about the mapserver-commits mailing list