Skip to content

Commit

Permalink
implement shortcutting proj.4 for 4326->3857 transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Apr 11, 2012
1 parent dee0e49 commit 2586506
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
21 changes: 21 additions & 0 deletions configure
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions configure.in
Expand Up @@ -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 ---------------------------------------------------------------------
Expand Down Expand Up @@ -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}])
Expand Down
1 change: 1 addition & 0 deletions mapcopy.c
Expand Up @@ -72,6 +72,7 @@ int msCopyProjection(projectionObj *dst, projectionObj *src) {

}
#endif
MS_COPYSTELEM(wellknownprojection);
return MS_SUCCESS;
}

Expand Down
10 changes: 10 additions & 0 deletions mapfile.c
Expand Up @@ -1308,7 +1308,17 @@ int msLoadProjectionStringEPSG(projectionObj *p, const char *value)
#ifdef USE_PROJ
if(p) msFreeProjection(p);

#ifdef USE_FASTPATH_PROJS
p->gt.need_geotransform = MS_FALSE;
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)
{
Expand Down
48 changes: 48 additions & 0 deletions mapproject.c
Expand Up @@ -292,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);

Expand Down Expand Up @@ -473,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-- )
{
Expand Down
5 changes: 5 additions & 0 deletions mapproject.h
Expand Up @@ -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
Expand All @@ -63,6 +67,7 @@ typedef struct {
#endif
geotransformObj gt; /* extra transformation to apply */
#endif
int wellknownprojection;
} projectionObj;

#ifndef SWIG
Expand Down

0 comments on commit 2586506

Please sign in to comment.