@@ -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-
13501116static int loadProjection (projectionObj * p )
13511117{
13521118#ifdef USE_PROJ
0 commit comments