[mapserver-commits] r11376 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Tue Mar 29 21:11:13 EDT 2011


Author: dmorissette
Date: 2011-03-29 18:11:13 -0700 (Tue, 29 Mar 2011)
New Revision: 11376

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapobject.c
   trunk/mapserver/mapproject.c
   trunk/mapserver/mapproject.h
   trunk/mapserver/maputil.c
Log:
Fixed handling of PROJ_LIB value relative to mapfile path (#3094)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2011-03-30 00:26:02 UTC (rev 11375)
+++ trunk/mapserver/HISTORY.TXT	2011-03-30 01:11:13 UTC (rev 11376)
@@ -15,6 +15,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Fixed handling of PROJ_LIB value relative to mapfile path (#3094)
+
 - Fixed compilation error with opengl support (#3769)
 
 - add support for gml:Box for spatial filters (#3789)

Modified: trunk/mapserver/mapobject.c
===================================================================
--- trunk/mapserver/mapobject.c	2011-03-30 00:26:02 UTC (rev 11375)
+++ trunk/mapserver/mapobject.c	2011-03-30 01:11:13 UTC (rev 11376)
@@ -29,8 +29,6 @@
  ****************************************************************************/
 
 #include "mapserver.h"
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #ifdef USE_GDAL
 #  include "gdal.h"
@@ -161,33 +159,8 @@
     /* in effect when the projection blocks are parsed and pj_init is called. */
     if( strcasecmp(key,"PROJ_LIB") == 0 )
     {
-        /* check if this is map relative */
-        if( !map->mappath 
-            || value[0] == '/'
-            || value[0] == '\\'
-            || (value[0] != '\0' && value[1] == ':') )
-        {
-            msSetPROJ_LIB( value );
-        }
-        else
-        {
-            struct stat stat_buf;
-            char *extended_path = (char*) malloc(strlen(map->mappath)
-                                                 + strlen(value) + 10);
-            sprintf( extended_path, "%s/%s", map->mappath, value );
-
-#ifndef S_ISDIR
-#  define S_ISDIR(x) ((x) & S_IFDIR)
-#endif            
-            
-            if( stat( extended_path, &stat_buf ) == 0 
-                && S_ISDIR(stat_buf.st_mode) )
-                msSetPROJ_LIB( extended_path );
-            else
-                msSetPROJ_LIB( value );
-            
-            free( extended_path );
-        }
+        /* value may be relative to map path */
+        msSetPROJ_LIB( value, map->mappath );
     }
 
     /* Same for MS_ERRORFILE, we want it to kick in as early as possible
@@ -243,7 +216,7 @@
         const char *value = msLookupHashTable( &(map->configoptions), key );
         if( strcasecmp(key,"PROJ_LIB") == 0 )
         {
-            msSetPROJ_LIB( value );
+            msSetPROJ_LIB( value, map->mappath );
         }
         else if( strcasecmp(key,"MS_ERRORFILE") == 0 )
         {

Modified: trunk/mapserver/mapproject.c
===================================================================
--- trunk/mapserver/mapproject.c	2011-03-30 00:26:02 UTC (rev 11375)
+++ trunk/mapserver/mapproject.c	2011-03-30 01:11:13 UTC (rev 11376)
@@ -31,6 +31,8 @@
 #include "mapproject.h"
 #include "mapthread.h"
 #include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 MS_CVSID("$Id$")
 
@@ -1053,12 +1055,34 @@
 /************************************************************************/
 /*                           msSetPROJ_LIB()                            */
 /************************************************************************/
-void msSetPROJ_LIB( const char *proj_lib )
+void msSetPROJ_LIB( const char *proj_lib, const char *pszRelToPath )
 
 {
 #ifdef USE_PROJ
     static int finder_installed = 0;
+    char *extended_path = NULL;
 
+    /* Handle relative path if applicable */
+    if( proj_lib && pszRelToPath
+        && proj_lib[0] != '/'
+        && proj_lib[0] != '\\'
+        && !(proj_lib[0] != '\0' && proj_lib[1] == ':') )
+    {
+        struct stat stat_buf;
+        extended_path = (char*) msSmallMalloc(strlen(pszRelToPath)
+                                              + strlen(proj_lib) + 10);
+        sprintf( extended_path, "%s/%s", pszRelToPath, proj_lib );
+
+#ifndef S_ISDIR
+#  define S_ISDIR(x) ((x) & S_IFDIR)
+#endif            
+            
+        if( stat( extended_path, &stat_buf ) == 0 
+            && S_ISDIR(stat_buf.st_mode) )
+            proj_lib = extended_path;
+    }
+
+
     msAcquireLock( TLOCK_PROJ );
 
     if( finder_installed == 0 && proj_lib != NULL)
@@ -1085,6 +1109,9 @@
         ms_proj_lib = msStrdup( proj_lib );
     
     msReleaseLock( TLOCK_PROJ );
+
+    if ( extended_path )
+        msFree( extended_path );
 #endif
 }
 

Modified: trunk/mapserver/mapproject.h
===================================================================
--- trunk/mapserver/mapproject.h	2011-03-30 00:26:02 UTC (rev 11375)
+++ trunk/mapserver/mapproject.h	2011-03-30 01:11:13 UTC (rev 11376)
@@ -83,7 +83,7 @@
 MS_DLL_EXPORT void msAxisDenormalizePoints( projectionObj *proj, int count,
                                             double *x, double *y );
 
-MS_DLL_EXPORT void msSetPROJ_LIB( const char * );
+MS_DLL_EXPORT void msSetPROJ_LIB( const char *, const char * );
 
 /* Provides compatiblity with PROJ.4 4.4.2 */
 #ifndef PJ_VERSION

Modified: trunk/mapserver/maputil.c
===================================================================
--- trunk/mapserver/maputil.c	2011-03-30 00:26:02 UTC (rev 11375)
+++ trunk/mapserver/maputil.c	2011-03-30 01:11:13 UTC (rev 11376)
@@ -1818,7 +1818,7 @@
   pj_clear_initcache();
 #  endif
   pj_deallocate_grids();
-  msSetPROJ_LIB( NULL );
+  msSetPROJ_LIB( NULL, NULL );
 #endif
 #if defined(USE_CURL)
   msHTTPCleanup();



More information about the mapserver-commits mailing list