Permalink
Browse files

Merge branch 'proj'

  • Loading branch information...
2 parents 7b6b275 + 9911244 commit cce10c1fd1b284a2dbe41a1dbab4a812597b1da4 @tbonfort tbonfort committed Apr 19, 2012
Showing with 131 additions and 5 deletions.
  1. +21 −0 configure
  2. +11 −0 configure.in
  3. +1 −0 mapcopy.c
  4. +38 −5 mapfile.c
  5. +52 −0 mapproject.c
  6. +8 −0 mapproject.h
View
@@ -639,6 +639,7 @@ PHP_REGEX_INC
PHP_VERSION_FLAG
PHPCONFIG
DEBUG_FLAGS
+PROJ_FASTPATH_ENABLED
USE_NINT
USE_POINT_Z_M
IGNORE_MISSING_DATA
@@ -898,6 +899,7 @@ enable_ignore_missing_data
enable_point_z_m
with_warnings
enable_debug
+enable_proj_fastpath
enable_cgi_cl_debug_args
enable_gcov
with_php
@@ -1550,6 +1552,8 @@ Optional Features:
--disable-fast-nint Use safe MS_NINT with reliable rounding
--enable-debug Include "-g" in CFLAGS for debugging.
--disable-debug Do not include "-g" in CFLAGS (the default).
+ --enable-proj-fastpath bypass proj.4 for epsg:4326 to epsg:3857
+ reprojections
--enable-cgi-cl-debug-args
Enable mapserv CGI command-line debug arguments
(disabled by default). These command-line args may
@@ -21972,6 +21976,21 @@ else
CFLAGS=`echo "$CFLAGS -DNDEBUG " | sed "s/-g //"`
fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable proj shortcuts..." >&5
+$as_echo "$as_me: checking whether to enable proj shortcuts..." >&6;}
+# Check whether --enable-proj-fastpath was given.
+if test "${enable_proj_fastpath+set}" = set; then :
+ enableval=$enable_proj_fastpath;
+fi
+
+
+if test "$enable_proj_fastpath" = "yes" ; then
+ PROJ_FASTPATH_ENABLED="-DUSE_PROJ_FASTPATHS"
+ ALL_ENABLED="$PROJ_FASTPATH_ENABLED $ALL_ENABLED"
+fi
+PROJ_FASTPATH_ENABLED=$PROJ_FASTPATH_ENABLED
+
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we should enable mapserv CGI command-line debug arguments..." >&5
$as_echo "$as_me: checking whether we should enable mapserv CGI command-line debug arguments..." >&6;}
@@ -25153,6 +25172,8 @@ $as_echo "" >&6; }
$as_echo " -------------- Support Libraries --------- " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Proj.4 support: ${PROJ_ENABLED}" >&5
$as_echo " Proj.4 support: ${PROJ_ENABLED}" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Proj Fastpaths: ${PROJ_FASTPATH_ENABLED}" >&5
+$as_echo " Proj Fastpaths: ${PROJ_FASTPATH_ENABLED}" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Libxml2 support: ${XML2_ENABLED}" >&5
$as_echo " Libxml2 support: ${XML2_ENABLED}" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: FriBidi support: ${FRIBIDI_ENABLED}" >&5
View
@@ -2529,6 +2529,16 @@ else
CFLAGS=`echo "$CFLAGS -DNDEBUG " | sed "s/-g //"`
fi
+AC_CHECKING(whether to enable proj shortcuts)
+AC_ARG_ENABLE(proj-fastpath,
+ AC_HELP_STRING([--enable-proj-fastpath], [bypass proj.4 for epsg:4326 to epsg:3857 reprojections]),,)
+
+if test "$enable_proj_fastpath" = "yes" ; then
+ PROJ_FASTPATH_ENABLED="-DUSE_PROJ_FASTPATHS"
+ ALL_ENABLED="$PROJ_FASTPATH_ENABLED $ALL_ENABLED"
+fi
+AC_SUBST(PROJ_FASTPATH_ENABLED,$PROJ_FASTPATH_ENABLED)
+
dnl ---------------------------------------------------------------------
dnl Check --enable-cgi-cl-debug-args option (OFF by default)
dnl ---------------------------------------------------------------------
@@ -2836,6 +2846,7 @@ AC_MSG_RESULT()
AC_MSG_RESULT([ -------------- Support Libraries --------- ])
AC_MSG_RESULT([ Proj.4 support: ${PROJ_ENABLED}])
+AC_MSG_RESULT([ Proj Fastpaths: ${PROJ_FASTPATH_ENABLED}])
AC_MSG_RESULT([ Libxml2 support: ${XML2_ENABLED}])
AC_MSG_RESULT([ FriBidi support: ${FRIBIDI_ENABLED}])
AC_MSG_RESULT([ Curl support: ${CURL_ENABLED}])
View
@@ -72,6 +72,7 @@ int msCopyProjection(projectionObj *dst, projectionObj *src) {
}
#endif
+ MS_COPYSTELEM(wellknownprojection);
return MS_SUCCESS;
}
View
@@ -1026,6 +1026,7 @@ int msInitProjection(projectionObj *p)
p->gt.need_geotransform = MS_FALSE;
p->numargs = 0;
p->args = NULL;
+ p->wellknownprojection = wkp_none;
#ifdef USE_PROJ
p->proj = NULL;
p->args = (char **)malloc(MS_MAXPROJARGS*sizeof(char *));
@@ -1038,7 +1039,12 @@ void msFreeProjection(projectionObj *p) {
#ifdef USE_PROJ
if(p->proj)
{
+#if PJ_VERSION < 480
pj_free(p->proj);
+#else
+ pj_ctx_free(p->proj_ctx);
+ p->proj_ctx = NULL;
+#endif
p->proj = NULL;
}
@@ -1165,8 +1171,8 @@ static int _msProcessAutoProjection(projectionObj *p)
if( !(p->proj = pj_init(numargs, args)) ) {
int *pj_errno_ref = pj_get_errno_ref();
msReleaseLock( TLOCK_PROJ );
- msSetError(MS_PROJERR, pj_strerrno(*pj_errno_ref),
- "msProcessProjection()");
+ msSetError(MS_PROJERR, "proj error \"%s\" for \"%s\"",
+ "msProcessProjection()", pj_strerrno(*pj_errno_ref), szProjBuf) ;
return(-1);
}
@@ -1194,7 +1200,7 @@ int msProcessProjection(projectionObj *p)
}
if (strcasecmp(p->args[0], "AUTO") == 0) {
- p->proj = NULL;
+ p->proj = NULL;
return 0;
}
@@ -1206,16 +1212,33 @@ int msProcessProjection(projectionObj *p)
return _msProcessAutoProjection(p);
}
msAcquireLock( TLOCK_PROJ );
+#if PJ_VERSION < 480
if( !(p->proj = pj_init(p->numargs, p->args)) ) {
+#else
+ p->proj_ctx = pj_ctx_alloc();
+ if( !(p->proj=pj_init_ctx(p->proj_ctx, p->numargs, p->args)) ) {
+#endif
+
int *pj_errno_ref = pj_get_errno_ref();
msReleaseLock( TLOCK_PROJ );
- msSetError(MS_PROJERR, pj_strerrno(*pj_errno_ref),
- "msProcessProjection()");
+ msSetError(MS_PROJERR, "proj error \"%s\" for \"%s:%s\"",
+ "msProcessProjection()", pj_strerrno(*pj_errno_ref), p->args[0],p->args[1]) ;
return(-1);
}
msReleaseLock( TLOCK_PROJ );
+#ifdef USE_PROJ_FASTPATHS
+ if(strcasestr(p->args[0],"epsg:4326")) {
+ p->wellknownprojection = wkp_lonlat;
+ } else if(strcasestr(p->args[0],"epsg:3857")) {
+ p->wellknownprojection = wkp_gmerc;
+ } else {
+ p->wellknownprojection = wkp_none;
+ }
+#endif
+
+
return(0);
#else
msSetError(MS_PROJERR, "Projection support is not available.",
@@ -1298,6 +1321,16 @@ int msLoadProjectionStringEPSG(projectionObj *p, const char *value)
if(p) msFreeProjection(p);
p->gt.need_geotransform = MS_FALSE;
+#ifdef USE_PROJ_FASTPATHS
+ if(strcasestr(value,"epsg:4326")) {
+ p->wellknownprojection = wkp_lonlat;
+ } else if(strcasestr(value,"epsg:3857")) {
+ p->wellknownprojection = wkp_gmerc;
+ } else {
+ p->wellknownprojection = wkp_none;
+ }
+#endif
+
if (strncasecmp(value, "EPSG:", 5) == 0)
{
View
@@ -90,10 +90,14 @@ int msProjectPoint(projectionObj *in, projectionObj *out, pointObj *point)
point->y *= DEG_TO_RAD;
}
+#if PJ_VERSION < 480
msAcquireLock( TLOCK_PROJ );
+#endif
error = pj_transform( in->proj, out->proj, 1, 0,
&(point->x), &(point->y), &z );
+#if PJ_VERSION < 480
msReleaseLock( TLOCK_PROJ );
+#endif
if( error || point->x == HUGE_VAL || point->y == HUGE_VAL )
return MS_FAILURE;
@@ -288,6 +292,30 @@ msProjectShapeLine(projectionObj *in, projectionObj *out,
int line_alloc = numpoints_in;
int wrap_test;
+#ifdef USE_PROJ_FASTPATHS
+#define MAXEXTENT 20037508.34
+#define M_PIby360 .0087266462599716479
+#define MAXEXTENTby180 111319.4907777777777777777
+ if(in->wellknownprojection == wkp_lonlat && out->wellknownprojection == wkp_gmerc) {
+ for( i = line->numpoints-1; i >= 0; i-- ) {
+#define p_x line->point[i].x
+#define p_y line->point[i].y
+ p_x *= MAXEXTENTby180;
+ p_y = log(tan((90 + p_y) * M_PIby360)) * MS_RAD_TO_DEG;
+ p_y *= MAXEXTENTby180;
+ if (p_x > MAXEXTENT) p_x = MAXEXTENT;
+ if (p_x < -MAXEXTENT) p_x = -MAXEXTENT;
+ if (p_y > MAXEXTENT) p_y = MAXEXTENT;
+ if (p_y < -MAXEXTENT) p_y = -MAXEXTENT;
+#undef p_x
+#undef p_y
+ }
+ return MS_SUCCESS;
+ }
+#endif
+
+
+
wrap_test = out != NULL && out->proj != NULL && pj_is_latlong(out->proj)
&& !pj_is_latlong(in->proj);
@@ -469,6 +497,30 @@ int msProjectShape(projectionObj *in, projectionObj *out, shapeObj *shape)
{
#ifdef USE_PROJ
int i;
+#ifdef USE_PROJ_FASTPATHS
+ int j;
+
+ if(in->wellknownprojection == wkp_lonlat && out->wellknownprojection == wkp_gmerc) {
+ for( i = shape->numlines-1; i >= 0; i-- ) {
+ for( j = shape->line[i].numpoints-1; j >= 0; j-- ) {
+#define p_x shape->line[i].point[j].x
+#define p_y shape->line[i].point[j].y
+ p_x *= MAXEXTENTby180;
+ p_y = log(tan((90 + p_y) * M_PIby360)) * MS_RAD_TO_DEG;
+ p_y *= MAXEXTENTby180;
+ if (p_x > MAXEXTENT) p_x = MAXEXTENT;
+ if (p_x < -MAXEXTENT) p_x = -MAXEXTENT;
+ if (p_y > MAXEXTENT) p_y = MAXEXTENT;
+ if (p_y < -MAXEXTENT) p_y = -MAXEXTENT;
+#undef p_x
+#undef p_y
+ }
+ }
+ return MS_SUCCESS;
+ }
+#endif
+
+
for( i = shape->numlines-1; i >= 0; i-- )
{
View
@@ -41,6 +41,10 @@ extern "C" {
# include <proj_api.h>
#endif
+#define wkp_none 0
+#define wkp_lonlat 1
+#define wkp_gmerc 2
+
typedef struct {
#ifdef SWIG
@@ -55,11 +59,15 @@ typedef struct {
char **args; /* variable number of projection args */
#ifdef USE_PROJ
projPJ proj; /* a projection structure for the PROJ package */
+#if PJ_VERSION >= 480
+ projCtx proj_ctx;
+#endif
#else
void *proj;
#endif
geotransformObj gt; /* extra transformation to apply */
#endif
+ int wellknownprojection;
} projectionObj;
#ifndef SWIG

0 comments on commit cce10c1

Please sign in to comment.