[postgis-commits] svn - r2718 - trunk/lwgeom

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Tue Nov 27 14:19:32 PST 2007


Author: mcayland
Date: 2007-11-27 14:19:30 -0800 (Tue, 27 Nov 2007)
New Revision: 2718

Modified:
   trunk/lwgeom/lwgeom_transform.c
Log:
Extend the PROJ.4 search path to include $sharedir/contrib/postgis/nad when looking for grid files. This is mainly to allow Win32 builds to find grid files without having to use a PROJ.4 DLL compiled containing a fixed path.

Modified: trunk/lwgeom/lwgeom_transform.c
===================================================================
--- trunk/lwgeom/lwgeom_transform.c	2007-11-23 10:42:09 UTC (rev 2717)
+++ trunk/lwgeom/lwgeom_transform.c	2007-11-27 22:19:30 UTC (rev 2718)
@@ -18,10 +18,12 @@
 
 #include "postgres.h"
 #include "fmgr.h"
+#include "miscadmin.h"
 
 #include "liblwgeom.h"
 #include "lwgeom_pg.h"
 
+
 Datum transform(PG_FUNCTION_ARGS);
 Datum transform_geom(PG_FUNCTION_ARGS);
 Datum postgis_proj_version(PG_FUNCTION_ARGS);
@@ -141,6 +143,10 @@
 void AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid);
 void DeleteFromPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid);
 
+/* Search path for PROJ.4 library */
+static bool IsPROJ4LibPathSet = false;
+void SetPROJ4LibPath();
+
 /* Memory context cache functions */
 static void PROJ4SRSCacheInit(MemoryContext context);
 static void PROJ4SRSCacheDelete(MemoryContext context);
@@ -563,6 +569,38 @@
 
 
 /*
+ * Specify an alternate directory for the PROJ.4 grid files
+ * (this should augment the PROJ.4 compile-time path)
+ *
+ * It's main purpose is to allow Win32 PROJ.4 installations
+ * to find a set grid shift files, although other platforms
+ * may find this useful too.
+ */
+void SetPROJ4LibPath()
+{
+	char *path;
+	const char **proj_lib_path;
+
+	/* 
+	 * Get the sharepath and append /contrib/postgis/nad to form a suitable
+	 * directory in which to store the grid shift files
+	 */	
+	proj_lib_path = palloc(sizeof(char *));
+	path = palloc(MAXPGPATH);
+	*proj_lib_path = path;
+
+	get_share_path(my_exec_path, path);
+	strncat(path, "/contrib/postgis/nad", MAXPGPATH - strlen(path) - 1);
+
+	/* Set the search path for PROJ.4 */
+	pj_set_searchpath(1, proj_lib_path);
+
+	/* Ensure we only do this once... */
+	IsPROJ4LibPathSet = true;
+}
+
+
+/*
  * This is *exactly* the same as PROJ.4's pj_transform(),
  * but it doesn't do the datum shift.
  */
@@ -771,6 +809,8 @@
 }
 
 
+
+
 /*
  * transform( GEOMETRY, INT (output srid) )
  * tmpPts - if there is a nadgrid error (-38), we re-try the transform
@@ -805,6 +845,10 @@
 		PG_RETURN_NULL();
 	}
 
+	/* Set the search path if we haven't already */
+	if (!IsPROJ4LibPathSet)
+		SetPROJ4LibPath();
+
 	/*
 	 * If input SRID and output SRID are equal, return geometry
 	 * without transform it
@@ -918,6 +962,7 @@
 	uchar *srl;
 	int* pj_errno_ref;
 
+
 	result_srid = PG_GETARG_INT32(3);
 	if (result_srid == -1)
 	{
@@ -933,6 +978,10 @@
 		PG_RETURN_NULL();
 	}
 
+	/* Set the search path if we haven't already */
+	if (!IsPROJ4LibPathSet)
+		SetPROJ4LibPath();
+
 	input_proj4_text  = (PG_GETARG_TEXT_P(1));
 	output_proj4_text = (PG_GETARG_TEXT_P(2));
 



More information about the postgis-commits mailing list