/
| 1210 | |
| 1211 | /*****************************************************************************/ |
| 1212 | std::vector<PJCoordOperation> pj_create_prepared_operations(PJ_CONTEXT *ctx, |
| 1213 | const PJ *source_crs, |
| 1214 | const PJ *target_crs, |
| 1215 | PJ_OBJ_LIST* op_list) |
| 1216 | /*****************************************************************************/ |
| 1217 | { |
| 1218 | auto pjGeogToSrc = create_operation_to_geog_crs(ctx, source_crs); |
| 1219 | if( !pjGeogToSrc ) |
| 1220 | { |
| 1221 | proj_context_log_debug(ctx, |
| 1222 | "Cannot create transformation from geographic CRS of source CRS to source CRS"); |
| 1223 | return {}; |
| 1224 | } |
| 1225 | |
| 1226 | auto pjGeogToDst = create_operation_to_geog_crs(ctx, target_crs); |
| 1227 | if( !pjGeogToDst ) |
| 1228 | { |
| 1229 | proj_context_log_debug(ctx, |
| 1230 | "Cannot create transformation from geographic CRS of target CRS to target CRS"); |
| 1231 | proj_destroy(pjGeogToSrc); |
| 1232 | return {}; |
| 1233 | } |
| 1234 | |
| 1235 | try |
| 1236 | { |
| 1237 | std::vector<PJCoordOperation> preparedOpList; |
| 1238 | |
| 1239 | // Iterate over source->target candidate transformations and reproject |
| 1240 | // their long-lat bounding box into the source CRS. |
| 1241 | const auto op_count = proj_list_get_count(op_list); |
| 1242 | for( int i = 0; i < op_count; i++ ) |
| 1243 | { |
| 1244 | auto op = proj_list_get(ctx, op_list, i); |
| 1245 | assert(op); |
| 1246 | double west_lon = 0.0; |
| 1247 | double south_lat = 0.0; |
| 1248 | double east_lon = 0.0; |
| 1249 | double north_lat = 0.0; |
| 1250 | |
| 1251 | const char* areaName = nullptr; |
| 1252 | if( proj_get_area_of_use(ctx, op, |
| 1253 | &west_lon, &south_lat, &east_lon, &north_lat, &areaName) ) |
| 1254 | { |
| 1255 | const bool isOffshore = |
| 1256 | areaName && strstr(areaName, "- offshore"); |
| 1257 | if( west_lon <= east_lon ) |
| 1258 | { |
| 1259 | op = add_coord_op_to_list(i, op, |
| 1260 | west_lon, south_lat, east_lon, north_lat, |
| 1261 | pjGeogToSrc, pjGeogToDst, isOffshore, |
| 1262 | preparedOpList); |
| 1263 | } |
| 1264 | else |
| 1265 | { |
| 1266 | auto op_clone = proj_clone(ctx, op); |
| 1267 | |
| 1268 | op = add_coord_op_to_list(i, op, |
| 1269 | west_lon, south_lat, 180, north_lat, |
no test coverage detected