Skip to content

Commit

Permalink
Merge branch 'proj'
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Apr 19, 2012
2 parents 7b6b275 + 9911244 commit cce10c1
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 5 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
43 changes: 38 additions & 5 deletions mapfile.c
Expand Up @@ -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 *));
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -1194,7 +1200,7 @@ int msProcessProjection(projectionObj *p)
}

if (strcasecmp(p->args[0], "AUTO") == 0) {
p->proj = NULL;
p->proj = NULL;
return 0;
}

Expand All @@ -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.",
Expand Down Expand Up @@ -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)
{
Expand Down
52 changes: 52 additions & 0 deletions mapproject.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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-- )
{
Expand Down
8 changes: 8 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 @@ -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
Expand Down

0 comments on commit cce10c1

Please sign in to comment.