From 3e48d718449b53a1959f3309e452c9c86cfd5910 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 3 Jun 2023 16:37:35 +0200 Subject: [PATCH] Remove support for PROJ < 6 Require PROJ >= 6.1 (6.0 was not supported) 6.1 was released in May 2019, 4 years ago. None of our CI tests PROJ < 6 anymore. --- cmake/FindProj.cmake | 12 +- mapogr.cpp | 5 +- mapproject.c | 422 +------------------------------------------ mapproject.h | 31 +--- maprasterquery.c | 26 --- mapresample.c | 104 ----------- maputil.c | 7 - 7 files changed, 11 insertions(+), 596 deletions(-) diff --git a/cmake/FindProj.cmake b/cmake/FindProj.cmake index d71cea721e..e28b1d4af3 100644 --- a/cmake/FindProj.cmake +++ b/cmake/FindProj.cmake @@ -6,7 +6,7 @@ # PROJ_LIBRARY -FIND_PATH(PROJ_INCLUDE_DIR NAMES proj.h proj_api.h) +FIND_PATH(PROJ_INCLUDE_DIR NAMES proj.h) FIND_LIBRARY(PROJ_LIBRARY NAMES proj proj_i) @@ -20,7 +20,6 @@ IF (PROJ_INCLUDE_DIR AND PROJ_LIBRARY) ENDIF (PROJ_INCLUDE_DIR AND PROJ_LIBRARY) IF (PROJ_FOUND) - IF (EXISTS ${PROJ_INCLUDE_DIR}/proj.h) FILE(READ ${PROJ_INCLUDE_DIR}/proj.h proj_version) STRING(REGEX REPLACE "^.*PROJ_VERSION_MAJOR +([0-9]+).*$" "\\1" PROJ_VERSION_MAJOR "${proj_version}") STRING(REGEX REPLACE "^.*PROJ_VERSION_MINOR +([0-9]+).*$" "\\1" PROJ_VERSION_MINOR "${proj_version}") @@ -28,13 +27,12 @@ IF (PROJ_FOUND) MESSAGE(STATUS "Found Proj ${PROJ_VERSION_MAJOR}.${PROJ_VERSION_MINOR}") + IF (PROJ_VERSION_MAJOR EQUAL 6 AND PROJ_VERSION_MINOR EQUAL 0) + MESSAGE (FATAL_ERROR "PROJ 6.0 is not supported. Use 6.1.0 or higher.") + ENDIF() IF ((PROJ_VERSION_MAJOR EQUAL 6) AND (PROJ_VERSION_MINOR EQUAL 3) AND (PROJ_VERSION_PATCH EQUAL 0)) MESSAGE (FATAL_ERROR "MapServer known to crash with PROJ 6.3.0. Use 6.3.1 or higher.") - ENDIF ((PROJ_VERSION_MAJOR EQUAL 6) AND (PROJ_VERSION_MINOR EQUAL 3) AND (PROJ_VERSION_PATCH EQUAL 0)) + ENDIF() ADD_DEFINITIONS(-DPROJ_VERSION_MAJOR=${PROJ_VERSION_MAJOR}) - ELSE() - MESSAGE(STATUS "Found Proj 4.x") - ADD_DEFINITIONS(-DPROJ_VERSION_MAJOR=4) - ENDIF() ENDIF (PROJ_FOUND) diff --git a/mapogr.cpp b/mapogr.cpp index b9a91316ad..9218e97508 100644 --- a/mapogr.cpp +++ b/mapogr.cpp @@ -1000,9 +1000,7 @@ static int msOGRSpatialRef2ProjectionObj(OGRSpatialReferenceH hSRS, return MS_SUCCESS; } -#if PROJ_VERSION_MAJOR >= 6 - // This could be done also in the < 6 case, but would be useless. - // Here this helps avoiding going through potentially lossy PROJ4 strings + // This helps avoiding going through potentially lossy PROJ4 strings const char* pszAuthName = OSRGetAuthorityName(hSRS, NULL); if( pszAuthName && EQUAL(pszAuthName, "EPSG") ) { @@ -1018,7 +1016,6 @@ static int msOGRSpatialRef2ProjectionObj(OGRSpatialReferenceH hSRS, return msLoadProjectionString(proj, szInitStr) == 0 ? MS_SUCCESS : MS_FAILURE; } } -#endif // Export OGR SRS to a PROJ4 string char *pszProj = NULL; diff --git a/mapproject.c b/mapproject.c index c80f7e0ad6..bd9ca1d5b0 100644 --- a/mapproject.c +++ b/mapproject.c @@ -39,11 +39,10 @@ #include "cpl_conv.h" #include "cpl_string.h" #include "ogr_srs_api.h" +#include "proj_experimental.h" static char *ms_proj_data = NULL; -#if PROJ_VERSION_MAJOR >= 6 static unsigned ms_proj_data_change_counter = 0; -#endif typedef struct LinkedListOfProjContext LinkedListOfProjContext; struct LinkedListOfProjContext @@ -61,10 +60,6 @@ static int msTestNeedWrap( pointObj pt1, pointObj pt2, pointObj pt2_geo, static projectionContext* msProjectionContextCreate(void); static void msProjectionContextUnref(projectionContext* ctx); -#if PROJ_VERSION_MAJOR >= 6 - -#include "proj_experimental.h" - /* Helps considerably for use cases like msautotest/wxs/wms_inspire.map */ /* which involve a number of layers with same SRS, and a number of exposed */ /* output SRS */ @@ -137,12 +132,7 @@ static PJ* createNormalizedPJ(projectionObj *in, projectionObj *out, int* pbFree { /* Special case to avoid out_str below to cause in_str to become invalid */ *pbFreePJ = TRUE; -#if PROJ_VERSION_MAJOR == 6 && PROJ_VERSION_MINOR == 0 - /* 6.0 didn't support proj=noop */ - return proj_create(in->proj_ctx->proj_ctx, "+proj=affine"); -#else return proj_create(in->proj_ctx->proj_ctx, "+proj=noop"); -#endif } const char* const wkt_options[] = { "MULTILINE=NO", NULL }; @@ -354,11 +344,7 @@ static void msProjErrorLogger(void * user_data, int level, const char * message) { (void)user_data; -#if PROJ_VERSION_MAJOR >= 6 if( level == PJ_LOG_ERROR && msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_VV ) -#else - if( level == PJ_LOG_ERROR ) -#endif { msDebug( "PROJ: Error: %s\n", message ); } @@ -529,96 +515,6 @@ int msProjectTransformPoints( reprojectionObj* reprojector, return MS_SUCCESS; } -#else - -/************************************************************************/ -/* msProjectionContextCreate() */ -/************************************************************************/ - -projectionContext* msProjectionContextCreate(void) -{ - return NULL; -} - -/************************************************************************/ -/* msProjectionContextUnref() */ -/************************************************************************/ - -void msProjectionContextUnref(projectionContext* ctx) -{ - (void)ctx; -} - -/************************************************************************/ -/* msProjectCreateReprojector() */ -/************************************************************************/ - -reprojectionObj* msProjectCreateReprojector(projectionObj* in, projectionObj* out) -{ - reprojectionObj* obj; - obj = (reprojectionObj*)msSmallCalloc(1, sizeof(reprojectionObj)); - obj->in = in; - obj->out = out; - obj->generation_number_in = in ? in->generation_number : 0; - obj->generation_number_out = out ? out->generation_number : 0; - obj->lineCuttingCase = LINE_CUTTING_UNKNOWN; - - /* -------------------------------------------------------------------- */ - /* If the source and destination are equal, then do nothing. */ - /* -------------------------------------------------------------------- */ - if( in && out && in->numargs == out->numargs && in->numargs > 0 - && strcmp(in->args[0],out->args[0]) == 0 ) - { - int i; - obj->no_op = MS_TRUE; - for( i = 1; i < in->numargs; i++ ) - { - if( strcmp(in->args[i],out->args[i]) != 0 ) { - obj->no_op = MS_FALSE; - break; - } - } - } - - /* -------------------------------------------------------------------- */ - /* If we have a fully defined input coordinate system and */ - /* output coordinate system, then we will use pj_transform */ - /* -------------------------------------------------------------------- */ - else if( in && in->proj && out && out->proj ) { - /* do nothing for now */ - } - /* nothing to do if the other coordinate system is also lat/long */ - else if( in == NULL && (out == NULL || msProjIsGeographicCRS(out) )) - { - obj->no_op = MS_TRUE; - } - else if( out == NULL && in != NULL && msProjIsGeographicCRS(in) ) - { - obj->no_op = MS_TRUE; - } - else if( (in == NULL || in->proj == NULL) && - (out == NULL || out->proj == NULL) ) - { - msProjectDestroyReprojector(obj); - return NULL; - } - return obj; -} - -/************************************************************************/ -/* msProjectDestroyReprojector() */ -/************************************************************************/ - -void msProjectDestroyReprojector(reprojectionObj* reprojector) -{ - if( !reprojector ) - return; - msFreeShape(&(reprojector->splitShape)); - msFree(reprojector); -} - -#endif - /* ** Initialize, load and free a projectionObj structure */ @@ -631,34 +527,17 @@ int msInitProjection(projectionObj *p) p->proj = NULL; p->args = (char **)malloc(MS_MAXPROJARGS*sizeof(char *)); MS_CHECK_ALLOC(p->args, MS_MAXPROJARGS*sizeof(char *), -1); -#if PROJ_VERSION_MAJOR >= 6 p->proj_ctx = NULL; -#elif PJ_VERSION >= 480 - p->proj_ctx = NULL; -#endif p->generation_number = 0; return(0); } void msFreeProjection(projectionObj *p) { -#if PROJ_VERSION_MAJOR >= 6 proj_destroy(p->proj); p->proj = NULL; msProjectionContextUnref(p->proj_ctx); p->proj_ctx = NULL; -#else - if(p->proj) { - pj_free(p->proj); - p->proj = NULL; - } -#if PJ_VERSION >= 480 - if(p->proj_ctx) { - pj_ctx_free(p->proj_ctx); - p->proj_ctx = NULL; - } -#endif -#endif p->gt.need_geotransform = MS_FALSE; p->wellknownprojection = wkp_none; @@ -670,14 +549,10 @@ void msFreeProjection(projectionObj *p) void msFreeProjectionExceptContext(projectionObj *p) { -#if PROJ_VERSION_MAJOR >= 6 projectionContext* ctx = p->proj_ctx; p->proj_ctx = NULL; msFreeProjection(p); p->proj_ctx = ctx; -#else - msFreeProjection(p); -#endif } /************************************************************************/ @@ -686,16 +561,11 @@ void msFreeProjectionExceptContext(projectionObj *p) void msProjectionInheritContextFrom(projectionObj *pDst, const projectionObj* pSrc) { -#if PROJ_VERSION_MAJOR >= 6 if( pDst->proj_ctx == NULL && pSrc->proj_ctx != NULL) { pDst->proj_ctx = pSrc->proj_ctx; pDst->proj_ctx->ref_count ++; } -#else - (void)pDst; - (void)pSrc; -#endif } /************************************************************************/ @@ -704,16 +574,11 @@ void msProjectionInheritContextFrom(projectionObj *pDst, const projectionObj* pS void msProjectionSetContext(projectionObj *p, projectionContext* ctx) { -#if PROJ_VERSION_MAJOR >= 6 if( p->proj_ctx == NULL && ctx != NULL) { p->proj_ctx = ctx; p->proj_ctx->ref_count ++; } -#else - (void)p; - (void)ctx; -#endif } /* @@ -827,7 +692,6 @@ static int _msProcessAutoProjection(projectionObj *p) /* OK, pass the definition to pj_init() */ args = msStringSplit(szProjBuf, '+', &numargs); -#if PROJ_VERSION_MAJOR >= 6 if( !(p->proj = proj_create_argv(p->proj_ctx->proj_ctx, numargs, args)) ) { int l_pj_errno = proj_context_errno (p->proj_ctx->proj_ctx); msSetError(MS_PROJERR, "proj error \"%s\" for \"%s\"", @@ -835,18 +699,6 @@ static int _msProcessAutoProjection(projectionObj *p) msFreeCharArray(args, numargs); return(-1); } -#else - msAcquireLock( TLOCK_PROJ ); - if( !(p->proj = pj_init(numargs, args)) ) { - int *pj_errno_ref = pj_get_errno_ref(); - msReleaseLock( TLOCK_PROJ ); - msSetError(MS_PROJERR, "proj error \"%s\" for \"%s\"", - "msProcessProjection()", pj_strerrno(*pj_errno_ref), szProjBuf) ; - msFreeCharArray(args, numargs); - return(-1); - } - msReleaseLock( TLOCK_PROJ ); -#endif msFreeCharArray(args, numargs); @@ -874,7 +726,6 @@ int msProcessProjection(projectionObj *p) return 0; } -#if PROJ_VERSION_MAJOR >= 6 if( p->proj_ctx == NULL ) { p->proj_ctx = msProjectionContextCreate(); @@ -908,7 +759,6 @@ int msProcessProjection(projectionObj *p) } msReleaseLock( TLOCK_PROJ ); } -#endif if (strncasecmp(p->args[0], "AUTO:", 5) == 0 || strncasecmp(p->args[0], "AUTO2:", 6) == 0) { @@ -917,7 +767,6 @@ int msProcessProjection(projectionObj *p) return _msProcessAutoProjection(p); } -#if PROJ_VERSION_MAJOR >= 6 if( p->numargs == 1 && strncmp(p->args[0], "init=", 5) != 0 ) { /* Deal e.g. with EPSG:XXXX or ESRI:XXXX */ @@ -967,29 +816,6 @@ int msProcessProjection(projectionObj *p) } free(args); } -#else - 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 ); - if(p->numargs>1) { - msSetError(MS_PROJERR, "proj error \"%s\" for \"%s:%s\"", - "msProcessProjection()", pj_strerrno(*pj_errno_ref), p->args[0],p->args[1]) ; - } else { - msSetError(MS_PROJERR, "proj error \"%s\" for \"%s\"", - "msProcessProjection()", pj_strerrno(*pj_errno_ref), p->args[0]) ; - } - return(-1); - } - - msReleaseLock( TLOCK_PROJ ); -#endif #ifdef USE_PROJ_FASTPATHS if(strcasestr(p->args[0],"epsg:4326")) { @@ -1060,7 +886,6 @@ int msProjectPointEx(reprojectionObj* reprojector, pointObj *point) point->y = y_out; } -#if PROJ_VERSION_MAJOR >= 6 if( reprojector->pj ) { PJ_COORD c; c.xyzt.x = point->x; @@ -1074,73 +899,6 @@ int msProjectPointEx(reprojectionObj* reprojector, pointObj *point) point->x = c.xyzt.x; point->y = c.xyzt.y; } -#else - if( reprojector->no_op ) { - /* do nothing, no transformation required */ - } - - /* -------------------------------------------------------------------- */ - /* If we have a fully defined input coordinate system and */ - /* output coordinate system, then we will use pj_transform. */ - /* -------------------------------------------------------------------- */ - else if( in && in->proj && out && out->proj ) { - int error; - double z = 0.0; - - if( pj_is_latlong(in->proj) ) { - point->x *= DEG_TO_RAD; - 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 ) { -// msSetError(MS_PROJERR,"proj says: %s","msProjectPoint()",pj_strerrno(error)); - return MS_FAILURE; - } - - if( pj_is_latlong(out->proj) ) { - point->x *= RAD_TO_DEG; - point->y *= RAD_TO_DEG; - } - } - - /* -------------------------------------------------------------------- */ - /* Otherwise we fallback to using pj_fwd() or pj_inv() and */ - /* assuming that the NULL projectionObj is supposed to be */ - /* lat/long in the same datum as the other projectionObj. This */ - /* is essentially a backwards compatibility mode. */ - /* -------------------------------------------------------------------- */ - else { - projUV p; - - p.u = point->x; - p.v = point->y; - - if(in==NULL || in->proj==NULL) { /* input coordinates are lat/lon */ - p.u *= DEG_TO_RAD; /* convert to radians */ - p.v *= DEG_TO_RAD; - p = pj_fwd(p, out->proj); - } else /* if(out==NULL || out->proj==NULL) */ { /* output coordinates are lat/lon */ - p = pj_inv(p, in->proj); - p.u *= RAD_TO_DEG; /* convert to decimal degrees */ - p.v *= RAD_TO_DEG; - } - - point->x = p.u; - point->y = p.v; - if( point->x == HUGE_VAL || point->y == HUGE_VAL ) { - return MS_FAILURE; - } - } -#endif if( out && out->gt.need_geotransform ) { double x_out, y_out; @@ -2291,84 +2049,6 @@ int msProjectRect(projectionObj *in, projectionObj *out, rectObj *rect) return ret; } -#if PROJ_VERSION_MAJOR < 6 - -static int msProjectSortString(const void* firstelt, const void* secondelt) -{ - char* firststr = *(char**)firstelt; - char* secondstr = *(char**)secondelt; - return strcmp(firststr, secondstr); -} - -/************************************************************************/ -/* msGetProjectNormalized() */ -/************************************************************************/ - -static projectionObj* msGetProjectNormalized( const projectionObj* p ) -{ - int i; -#if PROJ_VERSION_MAJOR >= 6 - const char* pszNewProj4Def; -#else - char* pszNewProj4Def; -#endif - projectionObj* pnew; - - pnew = (projectionObj*)msSmallMalloc(sizeof(projectionObj)); - msInitProjection(pnew); - msCopyProjection(pnew, (projectionObj*)p); - - if(p->proj == NULL ) - return pnew; - - /* Normalize definition so that msProjectDiffers() works better */ -#if PROJ_VERSION_MAJOR >= 6 - pszNewProj4Def = proj_as_proj_string(p->proj_ctx->proj_ctx, p->proj, PJ_PROJ_4, NULL); -#else - pszNewProj4Def = pj_get_def( p->proj, 0 ); -#endif - msFreeCharArray(pnew->args, pnew->numargs); - pnew->args = msStringSplit(pszNewProj4Def,'+', &pnew->numargs); - for(i = 0; i < pnew->numargs; i++) - { - /* Remove trailing space */ - if( strlen(pnew->args[i]) > 0 && pnew->args[i][strlen(pnew->args[i])-1] == ' ' ) - pnew->args[i][strlen(pnew->args[i])-1] = '\0'; - /* Remove spurious no_defs or init= */ - if( strcmp(pnew->args[i], "no_defs") == 0 || - strncmp(pnew->args[i], "init=", 5) == 0 ) - { - if( i < pnew->numargs - 1 ) - { - msFree(pnew->args[i]); - memmove(pnew->args + i, pnew->args + i + 1, - sizeof(char*) * (pnew->numargs - 1 -i )); - } - else - { - msFree(pnew->args[i]); - } - pnew->numargs --; - i --; - continue; - } - } - /* Sort the strings so they can be compared */ - qsort(pnew->args, pnew->numargs, sizeof(char*), msProjectSortString); - /*{ - fprintf(stderr, "'%s' =\n", pszNewProj4Def); - for(i = 0; i < p->numargs; i++) - fprintf(stderr, "'%s' ", p->args[i]); - fprintf(stderr, "\n"); - }*/ -#if PROJ_VERSION_MAJOR < 6 - pj_dalloc(pszNewProj4Def); -#endif - - return pnew; -} -#endif - /************************************************************************/ /* msProjectionsDiffer() */ /************************************************************************/ @@ -2410,29 +2090,7 @@ static int msProjectionsDifferInternal( projectionObj *proj1, projectionObj *pro int msProjectionsDiffer( projectionObj *proj1, projectionObj *proj2 ) { - int ret; - - ret = msProjectionsDifferInternal(proj1, proj2); -#if PROJ_VERSION_MAJOR < 6 - if( ret && - /* to speed up things, do normalization only if one proj is */ - /* likely of the form init=epsg:XXX and the other proj=XXX datum=YYY... */ - ( (proj1->numargs == 1 && proj2->numargs > 1) || - (proj1->numargs > 1 && proj2->numargs == 1) ) ) - { - projectionObj* p1normalized; - projectionObj* p2normalized; - - p1normalized = msGetProjectNormalized( proj1 ); - p2normalized = msGetProjectNormalized( proj2 ); - ret = msProjectionsDifferInternal(p1normalized, p2normalized); - msFreeProjection(p1normalized); - msFree(p1normalized); - msFreeProjection(p2normalized); - msFree(p2normalized); - } -#endif - return ret; + return msProjectionsDifferInternal(proj1, proj2); } /************************************************************************/ @@ -2544,32 +2202,6 @@ static int msTestNeedWrap( pointObj pt1, pointObj pt2, pointObj pt2_geo, return 0; } -/************************************************************************/ -/* msProjFinder() */ -/************************************************************************/ - -#if PROJ_VERSION_MAJOR < 6 -static char *last_filename = NULL; - -static const char *msProjFinder( const char *filename) - -{ - if( last_filename != NULL ) - free( last_filename ); - - if( filename == NULL ) - return NULL; - - if( ms_proj_data == NULL ) - return filename; - - last_filename = (char *) malloc(strlen(filename)+strlen(ms_proj_data)+2); - sprintf( last_filename, "%s/%s", ms_proj_data, filename ); - - return last_filename; -} -#endif - /************************************************************************/ /* msProjDataInitFromEnv() */ /************************************************************************/ @@ -2612,7 +2244,7 @@ void msSetPROJ_DATA( const char *proj_data, const char *pszRelToPath ) msAcquireLock( TLOCK_PROJ ); -#if PROJ_VERSION_MAJOR >= 6 + if( proj_data == NULL && ms_proj_data == NULL ) { /* do nothing */ @@ -2628,30 +2260,7 @@ void msSetPROJ_DATA( const char *proj_data, const char *pszRelToPath ) free( ms_proj_data ); ms_proj_data = proj_data ? msStrdup(proj_data) : NULL; } -#else - { - static int finder_installed = 0; - if( finder_installed == 0 && proj_data != NULL) { - finder_installed = 1; - pj_set_finder( msProjFinder ); - } - } - - if (proj_data == NULL) pj_set_finder(NULL); - - if( ms_proj_data != NULL ) { - free( ms_proj_data ); - ms_proj_data = NULL; - } - if( last_filename != NULL ) { - free( last_filename ); - last_filename = NULL; - } - - if( proj_data != NULL ) - ms_proj_data = msStrdup( proj_data ); -#endif msReleaseLock( TLOCK_PROJ ); #if GDAL_VERSION_MAJOR >= 3 @@ -2832,7 +2441,6 @@ void msAxisDenormalizePoints( projectionObj *proj, int count, int msProjIsGeographicCRS(projectionObj* proj) { -#if PROJ_VERSION_MAJOR >= 6 PJ_TYPE type; if( !proj->proj ) return FALSE; @@ -2847,9 +2455,6 @@ int msProjIsGeographicCRS(projectionObj* proj) return type == PJ_TYPE_GEOGRAPHIC_2D_CRS || type == PJ_TYPE_GEOGRAPHIC_3D_CRS; } return FALSE; -#else - return proj->proj != NULL && pj_is_latlong(proj->proj); -#endif } /************************************************************************/ @@ -2886,20 +2491,10 @@ static int ConvertProjUnitStringToMS(const char *pszProjUnit) /************************************************************************/ int GetMapserverUnitUsingProj(projectionObj *psProj) { -#if PROJ_VERSION_MAJOR >= 6 - const char *proj_str; -#else - char *proj_str; -#endif - if( msProjIsGeographicCRS( psProj ) ) return MS_DD; -#if PROJ_VERSION_MAJOR >= 6 - proj_str = proj_as_proj_string(psProj->proj_ctx->proj_ctx, psProj->proj, PJ_PROJ_4, NULL); -#else - proj_str = pj_get_def( psProj->proj, 0 ); -#endif + const char* proj_str = proj_as_proj_string(psProj->proj_ctx->proj_ctx, psProj->proj, PJ_PROJ_4, NULL); if( proj_str == NULL ) return -1; @@ -2911,9 +2506,6 @@ int GetMapserverUnitUsingProj(projectionObj *psProj) char *blank; strlcpy( units, (strstr(proj_str,"units=")+6), sizeof(units) ); -#if PROJ_VERSION_MAJOR < 6 - pj_dalloc( proj_str ); -#endif blank = strchr(units, ' '); if( blank != NULL ) @@ -2932,9 +2524,6 @@ int GetMapserverUnitUsingProj(projectionObj *psProj) strlcpy(to_meter_str,(strstr(proj_str,"to_meter=")+9), sizeof(to_meter_str)); -#if PROJ_VERSION_MAJOR < 6 - pj_dalloc( proj_str ); -#endif blank = strchr(to_meter_str, ' '); if( blank != NULL ) @@ -2958,9 +2547,6 @@ int GetMapserverUnitUsingProj(projectionObj *psProj) return -1; } -#if PROJ_VERSION_MAJOR < 6 - pj_dalloc( proj_str ); -#endif return -1; } diff --git a/mapproject.h b/mapproject.h index b84574c9a6..8cd3aa2429 100644 --- a/mapproject.h +++ b/mapproject.h @@ -37,17 +37,7 @@ extern "C" { #endif -#if PROJ_VERSION_MAJOR >= 6 -# include -#if PROJ_VERSION_MAJOR == 6 && PROJ_VERSION_MINOR == 0 -#error "PROJ 6.0 is not supported. Use PROJ 6.1 or later" -#endif -#else -# include -#if PJ_VERSION >= 470 && PJ_VERSION < 480 - void pj_clear_initcache(); -#endif -#endif +#include #define wkp_none 0 #define wkp_lonlat 1 @@ -73,15 +63,8 @@ but are not directly exposed by the mapscript module typedef struct { #ifndef SWIG char **args; /* variable number of projection args */ -#if PROJ_VERSION_MAJOR >= 6 PJ* proj; projectionContext* proj_ctx; -#else - projPJ proj; /* a projection structure for the PROJ package */ -#if PJ_VERSION >= 480 - projCtx proj_ctx; -#endif -#endif geotransformObj gt; /* extra transformation to apply */ #endif @@ -99,7 +82,6 @@ but are not directly exposed by the mapscript module } projectionObj; typedef struct { -#if PROJ_VERSION_MAJOR >= 6 #ifndef SWIG projectionObj* in; projectionObj* out; @@ -107,15 +89,6 @@ but are not directly exposed by the mapscript module msLineCuttingCase lineCuttingCase; shapeObj splitShape; int bFreePJ; -#endif -#else -#ifndef SWIG - projectionObj* in; - projectionObj* out; - msLineCuttingCase lineCuttingCase; - shapeObj splitShape; - int no_op; -#endif #endif unsigned short generation_number_in; unsigned short generation_number_out; @@ -164,10 +137,8 @@ but are not directly exposed by the mapscript module MS_DLL_EXPORT void msProjDataInitFromEnv(); int msProjIsGeographicCRS(projectionObj* proj); -#if PROJ_VERSION_MAJOR >= 6 int msProjectTransformPoints( reprojectionObj* reprojector, int npoints, double* x, double* y ); -#endif /*utility functions */ MS_DLL_EXPORT int GetMapserverUnitUsingProj(projectionObj *psProj); diff --git a/maprasterquery.c b/maprasterquery.c index 8d0dda8a6f..3434950438 100644 --- a/maprasterquery.c +++ b/maprasterquery.c @@ -415,9 +415,6 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS, CPLErr eErr; rasterLayerInfo *rlinfo; rectObj searchrect; -#if PROJ_VERSION_MAJOR < 6 - int mayNeedLonWrapAdjustment = MS_FALSE; -#endif rlinfo = (rasterLayerInfo *) layer->layerinfo; @@ -554,16 +551,6 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS, + sqrt( rlinfo->range_dist ); dfAdjustedRange = dfAdjustedRange * dfAdjustedRange; -#if PROJ_VERSION_MAJOR < 6 - if( layer->project && - msProjIsGeographicCRS(&(layer->projection)) && - msProjIsGeographicCRS(&(map->projection)) ) - { - double dfLonWrap = 0; - mayNeedLonWrapAdjustment = msProjectHasLonWrap(&(layer->projection), &dfLonWrap); - } -#endif - reprojectionObj* reprojector = NULL; if( layer->project ) { @@ -596,19 +583,6 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS, pointObj sReprojectedPixelLocation = sPixelLocation; if( reprojector ) { -#if PROJ_VERSION_MAJOR < 6 - /* Works around a bug in PROJ < 6 when reprojecting from a lon_wrap */ - /* geogCRS to a geogCRS, and the input abs(longitude) is > 180. Then */ - /* lon_wrap was ignored and the output longitude remained as the source */ - if( mayNeedLonWrapAdjustment ) - { - if( rlinfo->target_point.x < sReprojectedPixelLocation.x - 180 ) - sReprojectedPixelLocation.x -= 360; - else if( rlinfo->target_point.x > sReprojectedPixelLocation.x + 180 ) - sReprojectedPixelLocation.x += 360; - } -#endif - msProjectPointEx( reprojector, &sReprojectedPixelLocation); } diff --git a/mapresample.c b/mapresample.c index d0dfb9cf77..9723f07318 100644 --- a/mapresample.c +++ b/mapresample.c @@ -673,9 +673,7 @@ typedef struct { double adfDstGeoTransform[6]; int bUseProj; -#if PROJ_VERSION_MAJOR >= 6 reprojectionObj* pReprojectionDstToSrc; -#endif } msProjTransformInfo; /************************************************************************/ @@ -736,7 +734,6 @@ void *msInitProjTransformer( projectionObj *psSrc, memcpy( psPTInfo->adfDstGeoTransform, padfDstGeoTransform, sizeof(double) * 6 ); -#if PROJ_VERSION_MAJOR >= 6 if( psPTInfo->bUseProj ) { psPTInfo->pReprojectionDstToSrc = @@ -747,7 +744,6 @@ void *msInitProjTransformer( projectionObj *psSrc, return NULL; } } -#endif return psPTInfo; } @@ -759,13 +755,11 @@ void *msInitProjTransformer( projectionObj *psSrc, void msFreeProjTransformer( void * pCBData ) { -#if PROJ_VERSION_MAJOR >= 6 if( pCBData ) { msProjTransformInfo *psPTInfo = (msProjTransformInfo *)pCBData; msProjectDestroyReprojector(psPTInfo->pReprojectionDstToSrc); } -#endif free( pCBData ); } @@ -796,7 +790,6 @@ int msProjTransformer( void *pCBData, int nPoints, panSuccess[i] = 1; } -#if PROJ_VERSION_MAJOR >= 6 if( psPTInfo->bUseProj ) { if( msProjectTransformPoints( psPTInfo->pReprojectionDstToSrc, nPoints, x, y ) != MS_SUCCESS ) { @@ -810,58 +803,6 @@ int msProjTransformer( void *pCBData, int nPoints, panSuccess[i] = 0; } } -#else - /* -------------------------------------------------------------------- */ - /* Transform from degrees to radians if geographic. */ - /* -------------------------------------------------------------------- */ - if( psPTInfo->bDstIsGeographic ) { - for( i = 0; i < nPoints; i++ ) { - x[i] = x[i] * DEG_TO_RAD; - y[i] = y[i] * DEG_TO_RAD; - } - } - - /* -------------------------------------------------------------------- */ - /* Transform back to source projection space. */ - /* -------------------------------------------------------------------- */ - if( psPTInfo->bUseProj ) { - double *z; - int tr_result; - - z = (double *) msSmallCalloc(sizeof(double),nPoints); - - msAcquireLock( TLOCK_PROJ ); - tr_result = pj_transform( psPTInfo->psDstProjObj->proj, psPTInfo->psSrcProjObj->proj, - nPoints, 1, x, y, z); - msReleaseLock( TLOCK_PROJ ); - - if( tr_result != 0 ) { - free( z ); - for( i = 0; i < nPoints; i++ ) - panSuccess[i] = 0; - - return MS_FALSE; - } - free( z ); - - for( i = 0; i < nPoints; i++ ) { - if( x[i] == HUGE_VAL || y[i] == HUGE_VAL ) - panSuccess[i] = 0; - } - } - - /* -------------------------------------------------------------------- */ - /* Transform back to degrees if source is geographic. */ - /* -------------------------------------------------------------------- */ - if( psPTInfo->bSrcIsGeographic ) { - for( i = 0; i < nPoints; i++ ) { - if( panSuccess[i] ) { - x[i] = x[i] * RAD_TO_DEG; - y[i] = y[i] * RAD_TO_DEG; - } - } - } -#endif /* -------------------------------------------------------------------- */ /* Transform to source raster space. */ @@ -1039,9 +980,6 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize, int i, nSamples = 0, bOutInit = 0; double dfRatio; double x[MAX_SIZE], y[MAX_SIZE]; -#if PROJ_VERSION_MAJOR < 6 - double z[MAX_SIZE]; -#endif /* -------------------------------------------------------------------- */ /* Collect edges in map image pixel/line coordinates */ @@ -1091,16 +1029,12 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize, x[i] = x_out; y[i] = y_out; -#if PROJ_VERSION_MAJOR < 6 - z[i] = 0.0; -#endif } /* -------------------------------------------------------------------- */ /* Transform to layer georeferenced coordinates. */ /* -------------------------------------------------------------------- */ if( psDstProj->proj && psSrcProj->proj ) { -#if PROJ_VERSION_MAJOR >= 6 reprojectionObj* reprojector = msProjectCreateReprojector(psDstProj, psSrcProj); if( !reprojector ) return MS_FALSE; @@ -1109,32 +1043,6 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize, return MS_FALSE; } msProjectDestroyReprojector(reprojector); -#else - int tr_result; - if( msProjIsGeographicCRS(psDstProj) ) { - for( i = 0; i < nSamples; i++ ) { - x[i] = x[i] * DEG_TO_RAD; - y[i] = y[i] * DEG_TO_RAD; - } - } - - msAcquireLock( TLOCK_PROJ ); - tr_result = pj_transform( psDstProj->proj, psSrcProj->proj, - nSamples, 1, x, y, z ); - msReleaseLock( TLOCK_PROJ ); - - if( tr_result != 0 ) - return MS_FALSE; - - if( msProjIsGeographicCRS(psSrcProj) ) { - for( i = 0; i < nSamples; i++ ) { - if( x[i] != HUGE_VAL && y[i] != HUGE_VAL ) { - x[i] = x[i] * RAD_TO_DEG; - y[i] = y[i] * RAD_TO_DEG; - } - } - } -#endif } /* -------------------------------------------------------------------- */ @@ -1196,9 +1104,6 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize, if( bHasLonWrap ) { double x2[2], y2[2]; -#if PROJ_VERSION_MAJOR < 6 - double z2[2]; -#endif int nCountY = 0; double dfY = 0.0; double dfXMinOut = 0.0; @@ -1237,7 +1142,6 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize, x2[1] = dfLonWrap+180-1e-7; y2[1] = dfY; -#if PROJ_VERSION_MAJOR >= 6 { reprojectionObj* reprojector = msProjectCreateReprojector(psSrcProj, psDstProj); if( reprojector ) @@ -1246,14 +1150,6 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize, msProjectDestroyReprojector(reprojector); } } -#else - z2[0] = 0.0; - z2[1] = 0.0; - msAcquireLock( TLOCK_PROJ ); - pj_transform( psSrcProj->proj, psDstProj->proj, - 2, 1, x2, y2, z2 ); - msReleaseLock( TLOCK_PROJ ); -#endif if( x2[0] >= dfXMinOut - dfHalfRes && x2[0] <= dfXMaxOut + dfHalfRes && y2[0] >= dfYMinOut && y2[0] <= dfYMaxOut ) diff --git a/maputil.c b/maputil.c index 9073ca0972..272b468c55 100644 --- a/maputil.c +++ b/maputil.c @@ -2069,13 +2069,6 @@ void msCleanup() #endif msReleaseLock( TLOCK_GDAL ); - -#if PROJ_VERSION_MAJOR < 6 -# if PJ_VERSION >= 480 - pj_clear_initcache(); -# endif - pj_deallocate_grids(); -#endif msSetPROJ_DATA( NULL, NULL ); msProjectionContextPoolCleanup();