Skip to content

Commit 680e7e0

Browse files
committed
Initial port to PROJ 6 API
1 parent 7506203 commit 680e7e0

15 files changed

Lines changed: 896 additions & 371 deletions

cmake/FindProj.cmake

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ FIND_PATH(PROJ_INCLUDE_DIR proj_api.h)
1010

1111
FIND_LIBRARY(PROJ_LIBRARY NAMES proj proj_i)
1212

13-
set(PROJ_INCLUDE_DIRS ${PROJ_INCLUDE_DIR})
14-
set(PROJ_LIBRARIES ${PROJ_LIBRARY})
1513
include(FindPackageHandleStandardArgs)
1614
find_package_handle_standard_args(PROJ DEFAULT_MSG PROJ_LIBRARY PROJ_INCLUDE_DIR)
1715
mark_as_advanced(PROJ_LIBRARY PROJ_INCLUDE_DIR)
16+
17+
18+
IF (PROJ_INCLUDE_DIR AND PROJ_LIBRARY)
19+
SET(PROJ_FOUND TRUE)
20+
ENDIF (PROJ_INCLUDE_DIR AND PROJ_LIBRARY)
21+
22+
IF (PROJ_FOUND)
23+
IF (EXISTS ${PROJ_INCLUDE_DIR}/proj.h)
24+
FILE(READ ${PROJ_INCLUDE_DIR}/proj.h proj_version)
25+
STRING(REGEX REPLACE "^.*PROJ_VERSION_MAJOR +([0-9]+).*$" "\\1" PROJ_VERSION_MAJOR "${proj_version}")
26+
STRING(REGEX REPLACE "^.*PROJ_VERSION_MINOR +([0-9]+).*$" "\\1" PROJ_VERSION_MINOR "${proj_version}")
27+
STRING(REGEX REPLACE "^.*PROJ_VERSION_PATCH +([0-9]+).*$" "\\1" PROJ_VERSION_PATCH "${proj_version}")
28+
29+
MESSAGE(STATUS "Found Proj ${PROJ_VERSION_MAJOR}.${PROJ_VERSION_MINOR}")
30+
ADD_DEFINITIONS(-DPROJ_VERSION_MAJOR=${PROJ_VERSION_MAJOR})
31+
ELSE()
32+
MESSAGE(STATUS "Found Proj 4.x")
33+
ADD_DEFINITIONS(-DPROJ_VERSION_MAJOR=4)
34+
ENDIF()
35+
ENDIF (PROJ_FOUND)

mapdraw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,8 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
985985
/* the layer projection. */
986986
if( layer->connectiontype == MS_UVRASTER &&
987987
!layer->projection.gt.need_geotransform &&
988-
!(pj_is_latlong(map->projection.proj) &&
989-
pj_is_latlong(layer->projection.proj)) ) {
988+
!(msProjIsGeographicCRS(&(map->projection)) &&
989+
msProjIsGeographicCRS(&(layer->projection))) ) {
990990
rectObj layer_ori_extent;
991991

992992
if( msLayerGetExtent(layer, &layer_ori_extent) == MS_SUCCESS ) {

mapfile.c

Lines changed: 0 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,240 +1113,6 @@ static void writeGrid(FILE *stream, int indent, graticuleObj *pGraticule)
11131113
writeBlockEnd(stream, indent, "GRID");
11141114
}
11151115

1116-
/*
1117-
** Initialize, load and free a projectionObj structure
1118-
*/
1119-
int msInitProjection(projectionObj *p)
1120-
{
1121-
p->gt.need_geotransform = MS_FALSE;
1122-
p->numargs = 0;
1123-
p->args = NULL;
1124-
p->wellknownprojection = wkp_none;
1125-
#ifdef USE_PROJ
1126-
p->proj = NULL;
1127-
p->args = (char **)malloc(MS_MAXPROJARGS*sizeof(char *));
1128-
MS_CHECK_ALLOC(p->args, MS_MAXPROJARGS*sizeof(char *), -1);
1129-
#if PJ_VERSION >= 480
1130-
p->proj_ctx = NULL;
1131-
#endif
1132-
#endif
1133-
return(0);
1134-
}
1135-
1136-
void msFreeProjection(projectionObj *p)
1137-
{
1138-
#ifdef USE_PROJ
1139-
if(p->proj) {
1140-
pj_free(p->proj);
1141-
p->proj = NULL;
1142-
}
1143-
#if PJ_VERSION >= 480
1144-
if(p->proj_ctx) {
1145-
pj_ctx_free(p->proj_ctx);
1146-
p->proj_ctx = NULL;
1147-
}
1148-
#endif
1149-
1150-
msFreeCharArray(p->args, p->numargs);
1151-
p->args = NULL;
1152-
p->numargs = 0;
1153-
#endif
1154-
}
1155-
1156-
/*
1157-
** Handle OGC WMS/WFS AUTO projection in the format:
1158-
** "AUTO:proj_id,units_id,lon0,lat0"
1159-
*/
1160-
#ifdef USE_PROJ
1161-
static int _msProcessAutoProjection(projectionObj *p)
1162-
{
1163-
char **args;
1164-
int numargs, nProjId, nUnitsId, nZone;
1165-
double dLat0, dLon0;
1166-
const char *pszUnits = "m";
1167-
char szProjBuf[512]="";
1168-
1169-
/* WMS/WFS AUTO projection: "AUTO:proj_id,units_id,lon0,lat0" */
1170-
args = msStringSplit(p->args[0], ',', &numargs);
1171-
if (numargs != 4 ||
1172-
(strncasecmp(args[0], "AUTO:", 5) != 0 &&
1173-
strncasecmp(args[0], "AUTO2:", 6) != 0)) {
1174-
msSetError(MS_PROJERR,
1175-
"WMS/WFS AUTO/AUTO2 PROJECTION must be in the format "
1176-
"'AUTO:proj_id,units_id,lon0,lat0' or 'AUTO2:crs_id,factor,lon0,lat0'(got '%s').\n",
1177-
"_msProcessAutoProjection()", p->args[0]);
1178-
return -1;
1179-
}
1180-
1181-
if (strncasecmp(args[0], "AUTO:", 5)==0)
1182-
nProjId = atoi(args[0]+5);
1183-
else
1184-
nProjId = atoi(args[0]+6);
1185-
1186-
nUnitsId = atoi(args[1]);
1187-
dLon0 = atof(args[2]);
1188-
dLat0 = atof(args[3]);
1189-
1190-
1191-
/*There is no unit parameter for AUTO2. The 2nd parameter is
1192-
factor. Set the units to always be meter*/
1193-
if (strncasecmp(args[0], "AUTO2:", 6) == 0)
1194-
nUnitsId = 9001;
1195-
1196-
msFreeCharArray(args, numargs);
1197-
1198-
/* Handle EPSG Units. Only meters for now. */
1199-
switch(nUnitsId) {
1200-
case 9001: /* Meters */
1201-
pszUnits = "m";
1202-
break;
1203-
default:
1204-
msSetError(MS_PROJERR,
1205-
"WMS/WFS AUTO PROJECTION: EPSG Units %d not supported.\n",
1206-
"_msProcessAutoProjection()", nUnitsId);
1207-
return -1;
1208-
}
1209-
1210-
/* Build PROJ4 definition.
1211-
* This is based on the definitions found in annex E of the WMS 1.1.1
1212-
* spec and online at http://www.digitalearth.org/wmt/auto.html
1213-
* The conversion from the original WKT definitions to PROJ4 format was
1214-
* done using the MapScript setWKTProjection() function (based on OGR).
1215-
*/
1216-
switch(nProjId) {
1217-
case 42001: /** WGS 84 / Auto UTM **/
1218-
nZone = (int) floor( (dLon0 + 180.0) / 6.0 ) + 1;
1219-
sprintf( szProjBuf,
1220-
"+proj=tmerc+lat_0=0+lon_0=%.16g+k=0.999600+x_0=500000"
1221-
"+y_0=%.16g+ellps=WGS84+datum=WGS84+units=%s",
1222-
-183.0 + nZone * 6.0,
1223-
(dLat0 >= 0.0) ? 0.0 : 10000000.0,
1224-
pszUnits);
1225-
break;
1226-
case 42002: /** WGS 84 / Auto Tr. Mercator **/
1227-
sprintf( szProjBuf,
1228-
"+proj=tmerc+lat_0=0+lon_0=%.16g+k=0.999600+x_0=500000"
1229-
"+y_0=%.16g+ellps=WGS84+datum=WGS84+units=%s",
1230-
dLon0,
1231-
(dLat0 >= 0.0) ? 0.0 : 10000000.0,
1232-
pszUnits);
1233-
break;
1234-
case 42003: /** WGS 84 / Auto Orthographic **/
1235-
sprintf( szProjBuf,
1236-
"+proj=ortho+lon_0=%.16g+lat_0=%.16g+x_0=0+y_0=0"
1237-
"+ellps=WGS84+datum=WGS84+units=%s",
1238-
dLon0, dLat0, pszUnits );
1239-
break;
1240-
case 42004: /** WGS 84 / Auto Equirectangular **/
1241-
/* Note that we have to pass lon_0 as lon_ts for this one to */
1242-
/* work. Either a PROJ4 bug or a PROJ4 documentation issue. */
1243-
sprintf( szProjBuf,
1244-
"+proj=eqc+lon_ts=%.16g+lat_ts=%.16g+x_0=0+y_0=0"
1245-
"+ellps=WGS84+datum=WGS84+units=%s",
1246-
dLon0, dLat0, pszUnits);
1247-
break;
1248-
case 42005: /** WGS 84 / Auto Mollweide **/
1249-
sprintf( szProjBuf,
1250-
"+proj=moll+lon_0=%.16g+x_0=0+y_0=0+ellps=WGS84"
1251-
"+datum=WGS84+units=%s",
1252-
dLon0, pszUnits);
1253-
break;
1254-
default:
1255-
msSetError(MS_PROJERR,
1256-
"WMS/WFS AUTO PROJECTION %d not supported.\n",
1257-
"_msProcessAutoProjection()", nProjId);
1258-
return -1;
1259-
}
1260-
1261-
/* msDebug("%s = %s\n", p->args[0], szProjBuf); */
1262-
1263-
/* OK, pass the definition to pj_init() */
1264-
args = msStringSplit(szProjBuf, '+', &numargs);
1265-
1266-
msAcquireLock( TLOCK_PROJ );
1267-
if( !(p->proj = pj_init(numargs, args)) ) {
1268-
int *pj_errno_ref = pj_get_errno_ref();
1269-
msReleaseLock( TLOCK_PROJ );
1270-
msSetError(MS_PROJERR, "proj error \"%s\" for \"%s\"",
1271-
"msProcessProjection()", pj_strerrno(*pj_errno_ref), szProjBuf) ;
1272-
return(-1);
1273-
}
1274-
1275-
msReleaseLock( TLOCK_PROJ );
1276-
1277-
msFreeCharArray(args, numargs);
1278-
1279-
return(0);
1280-
}
1281-
#endif /* USE_PROJ */
1282-
1283-
int msProcessProjection(projectionObj *p)
1284-
{
1285-
#ifdef USE_PROJ
1286-
assert( p->proj == NULL );
1287-
1288-
if( strcasecmp(p->args[0],"GEOGRAPHIC") == 0 ) {
1289-
msSetError(MS_PROJERR,
1290-
"PROJECTION 'GEOGRAPHIC' no longer supported.\n"
1291-
"Provide explicit definition.\n"
1292-
"ie. proj=latlong\n"
1293-
" ellps=clrk66\n",
1294-
"msProcessProjection()");
1295-
return(-1);
1296-
}
1297-
1298-
if (strcasecmp(p->args[0], "AUTO") == 0) {
1299-
p->proj = NULL;
1300-
return 0;
1301-
}
1302-
1303-
if (strncasecmp(p->args[0], "AUTO:", 5) == 0 ||
1304-
strncasecmp(p->args[0], "AUTO2:", 6) == 0) {
1305-
/* WMS/WFS AUTO projection: "AUTO:proj_id,units_id,lon0,lat0" */
1306-
/*WMS 1.3.0: AUTO2:auto_crs_id,factor,lon0,lat0*/
1307-
return _msProcessAutoProjection(p);
1308-
}
1309-
msAcquireLock( TLOCK_PROJ );
1310-
#if PJ_VERSION < 480
1311-
if( !(p->proj = pj_init(p->numargs, p->args)) ) {
1312-
#else
1313-
p->proj_ctx = pj_ctx_alloc();
1314-
if( !(p->proj=pj_init_ctx(p->proj_ctx, p->numargs, p->args)) ) {
1315-
#endif
1316-
1317-
int *pj_errno_ref = pj_get_errno_ref();
1318-
msReleaseLock( TLOCK_PROJ );
1319-
if(p->numargs>1) {
1320-
msSetError(MS_PROJERR, "proj error \"%s\" for \"%s:%s\"",
1321-
"msProcessProjection()", pj_strerrno(*pj_errno_ref), p->args[0],p->args[1]) ;
1322-
} else {
1323-
msSetError(MS_PROJERR, "proj error \"%s\" for \"%s\"",
1324-
"msProcessProjection()", pj_strerrno(*pj_errno_ref), p->args[0]) ;
1325-
}
1326-
return(-1);
1327-
}
1328-
1329-
msReleaseLock( TLOCK_PROJ );
1330-
1331-
#ifdef USE_PROJ_FASTPATHS
1332-
if(strcasestr(p->args[0],"epsg:4326")) {
1333-
p->wellknownprojection = wkp_lonlat;
1334-
} else if(strcasestr(p->args[0],"epsg:3857")) {
1335-
p->wellknownprojection = wkp_gmerc;
1336-
} else {
1337-
p->wellknownprojection = wkp_none;
1338-
}
1339-
#endif
1340-
1341-
1342-
return(0);
1343-
#else
1344-
msSetError(MS_PROJERR, "Projection support is not available.",
1345-
"msProcessProjection()");
1346-
return(-1);
1347-
#endif
1348-
}
1349-
13501116
static int loadProjection(projectionObj *p)
13511117
{
13521118
#ifdef USE_PROJ

mapgraticule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
191191
layer->project = msProjectionsDiffer(&(layer->projection), &(layer->map->projection));
192192
if( layer->project &&
193193
strstr(layer->map->projection.args[0], "epsg:3857") &&
194-
pj_is_latlong(layer->projection.proj) )
194+
msProjIsGeographicCRS(&(layer->projection)) )
195195
{
196196
if( rectMapCoordinates.minx < -20037508)
197197
rectMapCoordinates.minx = -20037508;
@@ -1073,8 +1073,8 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule
10731073
msProjectShape( &pLayer->projection, &pLayer->map->projection, pShape );
10741074

10751075
/* Poor man detection of reprojection failure */
1076-
if( pj_is_latlong(pLayer->projection.proj) !=
1077-
pj_is_latlong(pLayer->map->projection.proj) )
1076+
if( msProjIsGeographicCRS(&(pLayer->projection)) !=
1077+
msProjIsGeographicCRS(&(pLayer->map->projection)) )
10781078
{
10791079
if( ptPoint.x == pShape->line->point[0].x &&
10801080
ptPoint.y == pShape->line->point[0].y )
@@ -1128,7 +1128,7 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule
11281128
/* Clamp coordinates into the validity area of the projection, in the */
11291129
/* particular case of EPSG:3857 (WebMercator) to longlat reprojection */
11301130
if( strstr(pLayer->map->projection.args[0], "epsg:3857") &&
1131-
pj_is_latlong(pLayer->projection.proj) )
1131+
msProjIsGeographicCRS(&(pLayer->projection)) )
11321132
{
11331133
if( !pLayer->map->projection.gt.need_geotransform &&
11341134
ePosition == posLeft && pShape->line->point[0].x < -20037508)

mapkmlrenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ int KmlRenderer::checkProjection(mapObj *map)
523523
{
524524
projectionObj *projection= &map->projection;
525525
#ifdef USE_PROJ
526-
if (projection && projection->numargs > 0 && pj_is_latlong(projection->proj)) {
526+
if (projection && projection->numargs > 0 && msProjIsGeographicCRS(projection)) {
527527
return MS_SUCCESS;
528528
} else {
529529
char epsg_string[100];

mapows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ int msOWSPrintEncodeParamList(FILE *stream, const char *name,
20902090
*/
20912091
void msOWSProjectToWGS84(projectionObj *srcproj, rectObj *ext)
20922092
{
2093-
if (srcproj->numargs > 0 && !pj_is_latlong(srcproj->proj)) {
2093+
if (srcproj->proj && !msProjIsGeographicCRS(srcproj)) {
20942094
projectionObj wgs84;
20952095
msInitProjection(&wgs84);
20962096
msLoadProjectionString(&wgs84, "+proj=longlat +ellps=WGS84 +datum=WGS84");

0 commit comments

Comments
 (0)