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

svn at osgeo.org svn at osgeo.org
Mon Sep 27 22:41:41 EDT 2010


Author: assefa
Date: 2010-09-28 02:41:41 +0000 (Tue, 28 Sep 2010)
New Revision: 10524

Added:
   sandbox/sdlime/common-expressions/mapserver/mapogcfiltercommon.c
Modified:
   sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c
   sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h
   sandbox/sdlime/common-expressions/mapserver/mapwfs.c
Log:
add spatial support for common expressions

Modified: sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c	2010-09-28 02:16:19 UTC (rev 10523)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfilter.c	2010-09-28 02:41:41 UTC (rev 10524)
@@ -44,7 +44,7 @@
     return (*(int*)a) - (*(int*)b);
 }
 
-static int FLTIsNumeric(char *pszValue)
+int FLTIsNumeric(char *pszValue)
 {
     if (pszValue)
     {
@@ -4073,334 +4073,6 @@
 
 
 
-
-
-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;
-
-/* -------------------------------------------------------------------- */
-/*      Get the bounds value which are stored like boundmin;boundmax    */
-/* -------------------------------------------------------------------- */
-    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])
-    {
-        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;  
-        }
-    }
-        
-
-/* -------------------------------------------------------------------- */
-/*      build expresssion.                                              */
-/* -------------------------------------------------------------------- */
-    /* 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)
-    {
-        sprintf(szBuffer,"%s", "\"");
-        pszExpression = msStringConcatenate(pszExpression, szBuffer); 
-    }
-
-    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); 
-
-    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)
-{
-     char szTmp[256];
-     char *pszExpression = NULL;
-     int bString;
-
-     if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
-      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 (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;
-
-    /* attribute */
-    if (bString)
-      sprintf(szTmp, "%s", " (\"[");
-    else
-      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);
-
-    if (strcasecmp(psFilterNode->pszValue, 
-                   "PropertyIsEqualTo") == 0)
-    {
-        /*case insensitive set ? */
-        if (psFilterNode->psRightNode->pOther && 
-            (*(int *)psFilterNode->psRightNode->pOther) == 1)
-        {
-          sprintf(szTmp,  "%s", "=="); /*TODO whar should be this??*/
-        }
-        else
-          sprintf(szTmp,  "%s", "==");
-    
-    }
-    else if (strcasecmp(psFilterNode->pszValue, 
-                        "PropertyIsNotEqualTo") == 0)
-      sprintf(szTmp,  "%s", " != "); 
-    else if (strcasecmp(psFilterNode->pszValue, 
-                        "PropertyIsLessThan") == 0)
-      sprintf(szTmp,  "%s", " < ");
-    else if (strcasecmp(psFilterNode->pszValue, 
-                        "PropertyIsGreaterThan") == 0)
-      sprintf(szTmp,  "%s", " > ");
-    else if (strcasecmp(psFilterNode->pszValue, 
-                        "PropertyIsLessThanOrEqualTo") == 0)
-      sprintf(szTmp,  "%s", " <= ");
-    else if (strcasecmp(psFilterNode->pszValue, 
-                        "PropertyIsGreaterThanOrEqualTo") == 0)
-      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);
-
-    if (bString)
-      sprintf(szTmp,  "%s", "\") ");
-    
-    pszExpression = msStringConcatenate(pszExpression, szTmp);
-
-    return pszExpression;
-}
-
-
-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;
-}
-
-char *FLTFilterNodeToCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp)
-{
-    char *pszExpression = NULL;
-
-    if (!psFilterNode)
-      return NULL;
-
-    if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON)
-    {
-        if ( psFilterNode->psLeftNode && psFilterNode->psRightNode)
-        {
-            if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))
-            {
-                pszExpression = FLTGetBinaryComparisonCommonExpression(psFilterNode, lp);
-            }
-        }
-        else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)
-        {
-            pszExpression = FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp);
-        }
-    }
-    
-    else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL)
-      pszExpression = FLTGetLogicalComparisonCommonExpression(psFilterNode, lp);
-    
-    return pszExpression;
-}
-
-
-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-28 02:16:19 UTC (rev 10523)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfilter.h	2010-09-28 02:41:41 UTC (rev 10524)
@@ -123,9 +123,10 @@
 MS_DLL_EXPORT int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS);
 MS_DLL_EXPORT  int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS);
 
+MS_DLL_EXPORT int FLTIsNumeric(char *pszValue);
 /*common-expressions*/
 MS_DLL_EXPORT   char *FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
-MS_DLL_EXPORT  char *FLTFilterNodeToCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
+MS_DLL_EXPORT  char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp);
 MS_DLL_EXPORT int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, char *pszExpression);
 
 

Added: sandbox/sdlime/common-expressions/mapserver/mapogcfiltercommon.c
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapogcfiltercommon.c	                        (rev 0)
+++ sandbox/sdlime/common-expressions/mapserver/mapogcfiltercommon.c	2010-09-28 02:41:41 UTC (rev 10524)
@@ -0,0 +1,495 @@
+/**********************************************************************
+ * $Id: mapogcfilter.c 10508 2010-09-17 20:52:33Z assefa $
+ *
+ * Project:  MapServer
+ * Purpose:  OGC Filter Encoding implementation
+ * Author:   Y. Assefa, DM Solutions Group (assefa at dmsolutions.ca)
+ *
+ **********************************************************************
+ * Copyright (c) 2003, Y. Assefa, DM Solutions Group Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in 
+ * all copies of this Software or works derived from this Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ ****************************************************************************/
+
+#ifdef USE_OGR
+#include "cpl_minixml.h"
+#endif
+
+#include "mapogcfilter.h"
+#include "mapserver.h"
+#include "mapowscommon.h"
+
+MS_CVSID("$Id: $")
+
+#ifdef USE_OGR
+
+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;
+
+/* -------------------------------------------------------------------- */
+/*      Get the bounds value which are stored like boundmin;boundmax    */
+/* -------------------------------------------------------------------- */
+    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])
+    {
+        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;  
+        }
+    }
+        
+
+/* -------------------------------------------------------------------- */
+/*      build expresssion.                                              */
+/* -------------------------------------------------------------------- */
+    /* 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)
+    {
+        sprintf(szBuffer,"%s", "\"");
+        pszExpression = msStringConcatenate(pszExpression, szBuffer); 
+    }
+
+    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); 
+
+    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)
+{
+     char szTmp[256];
+     char *pszExpression = NULL;
+     int bString;
+
+     if (psFilterNode == NULL)
+      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 (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. */
+    /*propertyislike is always treated as string*/
+    if (psFilterNode->psRightNode->pszValue == NULL || 
+        strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0)
+      bString = 1;
+    
+    
+      
+    /* attribute */
+    if (bString)
+      sprintf(szTmp, "%s", " (\"[");
+    else
+      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);
+
+    if (strcasecmp(psFilterNode->pszValue, 
+                   "PropertyIsEqualTo") == 0)
+    {
+        /*case insensitive set ? */
+        if (psFilterNode->psRightNode->pOther && 
+            (*(int *)psFilterNode->psRightNode->pOther) == 1)
+        {
+          sprintf(szTmp,  "%s", "=="); /*TODO whar should be this??*/
+        }
+        else
+          sprintf(szTmp,  "%s", "==");
+    
+    }
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsNotEqualTo") == 0)
+      sprintf(szTmp,  "%s", " != "); 
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsLessThan") == 0)
+      sprintf(szTmp,  "%s", " < ");
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsGreaterThan") == 0)
+      sprintf(szTmp,  "%s", " > ");
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsLessThanOrEqualTo") == 0)
+      sprintf(szTmp,  "%s", " <= ");
+    else if (strcasecmp(psFilterNode->pszValue, 
+                        "PropertyIsGreaterThanOrEqualTo") == 0)
+      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);
+
+    if (bString)
+    {
+        sprintf(szTmp,  "%s", "\"");
+        pszExpression = msStringConcatenate(pszExpression, szTmp);
+    }
+
+     sprintf(szTmp,  "%s", ")");
+     pszExpression = msStringConcatenate(pszExpression, szTmp);
+
+    return pszExpression;
+}
+
+
+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 = FLTGetCommonExpression(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 = FLTGetCommonExpression(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 = FLTGetCommonExpression(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;
+}
+
+
+char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerObj *lp)
+{
+    char *pszExpression = NULL;
+    shapeObj *psQueryShape = NULL;
+    double dfDistance = -1;
+    int nUnit = -1;
+    char *pszWktText = NULL;
+    char szBuffer[256];
+    char *pszTmp=NULL;
+    projectionObj sProjTmp;
+    char *pszEPSG= NULL;
+    rectObj sQueryRect;
+    shapeObj *psTmpShape=NULL, *psBufferShape=NULL;
+    int bBBoxQuery = 0;
+    
+    if (psNode == NULL || lp == NULL)
+      return NULL;
+
+    if (psNode->eType != FILTER_NODE_TYPE_SPATIAL)
+      return NULL;
+
+    /* get the shape*/
+    /*BBOX case: replace it with NOT DISJOINT.*/
+    if(FLTIsBBoxFilter(psNode))
+    {
+        pszEPSG = FLTGetBBOX(psNode, &sQueryRect);
+        /*this should be removed and bbox should parse and strore the srs properly, 
+          using now legacy code*/
+        if (pszEPSG)
+          psNode->pszSRS = strdup(pszEPSG);
+        
+        psTmpShape = (shapeObj *)malloc(sizeof(shapeObj));
+        msInitShape(psTmpShape);
+        msRectToPolygon(sQueryRect, psTmpShape);
+        bBBoxQuery = 1;
+
+    }
+    else
+    {
+        /*other geos type operations*/
+
+        /*project shape to layer projection. If the proj is not part of the filter query,
+          assume that the cooredinates are in the map projection*/
+      
+        psQueryShape = FLTGetShape(psNode, &dfDistance, &nUnit);
+    
+        if ((strcasecmp(psNode->pszValue, "DWithin") == 0 ||
+             strcasecmp(psNode->pszValue, "Beyond") == 0 ) &&
+            dfDistance > 0)
+        {
+            if (nUnit >=0 && nUnit != lp->map->units)
+              dfDistance *= msInchesPerUnit(nUnit,0)/msInchesPerUnit(lp->map->units,0);
+
+            psBufferShape = msGEOSBuffer(psQueryShape, dfDistance);
+        }
+        if (psBufferShape)
+          psTmpShape = psBufferShape;
+        else
+          psTmpShape = psQueryShape;
+    }
+
+    if (psTmpShape)
+    {
+        if( lp->projection.numargs > 0)
+        {
+            if (psNode->pszSRS && FTLParseEpsgString(psNode->pszSRS, &sProjTmp))
+              msProjectShape(&sProjTmp, &lp->projection, psTmpShape);
+            else if (lp->map->projection.numargs > 0)
+              msProjectShape(&lp->map->projection, &lp->projection, psTmpShape);
+        }
+        if (bBBoxQuery)
+          sprintf(szBuffer, "%s", " (NOT ([shape] ");
+        else
+          sprintf(szBuffer, "%s", " ([shape] ");
+
+        pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+
+        if (strcasecmp(psNode->pszValue, "intersect") == 0)
+          pszTmp = strdup(psNode->pszValue);
+        else
+          pszTmp = strdup(psNode->pszValue);
+        msStringToLower(pszTmp);
+        if (bBBoxQuery)
+          sprintf(szBuffer, " %s ", "disjoint");
+        else
+           sprintf(szBuffer, " %s ", pszTmp);
+
+        pszExpression = msStringConcatenate(pszExpression, szBuffer);
+        msFree(pszTmp);
+
+        pszWktText = msGEOSShapeToWKT(psTmpShape);
+        sprintf(szBuffer, "%s", " fromText('");
+        pszExpression = msStringConcatenate(pszExpression, szBuffer);
+        pszExpression = msStringConcatenate(pszExpression, pszWktText);
+        sprintf(szBuffer, "%s", "')");
+        pszExpression = msStringConcatenate(pszExpression, szBuffer);
+        
+    }
+    if (psBufferShape)
+      msFreeShape(psBufferShape);
+
+    
+    sprintf(szBuffer, "%s", ")");
+    pszExpression = msStringConcatenate(pszExpression, szBuffer);
+
+     if (bBBoxQuery)
+     {
+          sprintf(szBuffer, "%s", ")");
+          pszExpression = msStringConcatenate(pszExpression, szBuffer);
+     }
+    return pszExpression;
+}
+
+
+char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp)
+{
+    char *pszExpression = NULL;
+
+    if (!psFilterNode)
+      return NULL;
+
+    if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON)
+    {
+        if ( psFilterNode->psLeftNode && psFilterNode->psRightNode)
+        {
+            if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue) ||
+                strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0)
+              pszExpression = FLTGetBinaryComparisonCommonExpression(psFilterNode, lp);
+
+            else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)
+              pszExpression = FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp);
+        }
+    }
+    else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL)
+      pszExpression = FLTGetLogicalComparisonCommonExpression(psFilterNode, lp);
+
+     else if (psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL)
+       pszExpression = FLTGetSpatialComparisonCommonExpression(psFilterNode, lp);
+    
+    return pszExpression;
+}
+
+
+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;
+
+    /*TODO: if there is a bbox in the node, get it and set the map extent*/
+    map->query.rect = map->extent;
+
+    retval = msQueryByFilter(map);
+    
+    return retval;
+}
+
+#endif


Property changes on: sandbox/sdlime/common-expressions/mapserver/mapogcfiltercommon.c
___________________________________________________________________
Added: svn:executable
   + *

Modified: sandbox/sdlime/common-expressions/mapserver/mapwfs.c
===================================================================
--- sandbox/sdlime/common-expressions/mapserver/mapwfs.c	2010-09-28 02:16:19 UTC (rev 10523)
+++ sandbox/sdlime/common-expressions/mapserver/mapwfs.c	2010-09-28 02:41:41 UTC (rev 10524)
@@ -1815,7 +1815,7 @@
         /*preparse the filter for gml aliases*/
         FLTPreParseFilterForAlias(psNode, map, iLayerIndex, "G");
 
-        pszExpression = FLTFilterNodeToCommonExpression(psNode,  GET_LAYER(map, iLayerIndex));
+        pszExpression = FLTGetCommonExpression(psNode,  GET_LAYER(map, iLayerIndex));
         /* run filter.  If no results are found, do not throw exception */
         /* this is a null result */
 



More information about the mapserver-commits mailing list