| 18270 | } |
| 18271 | |
| 18272 | GMT_LOCAL int gmtinit_parse_proj4(struct GMT_CTRL *GMT, char *item, char *dest) { |
| 18273 | /* Deal with proj.4 or EPSGs passed in -J option */ |
| 18274 | char *item_t1 = NULL, *item_t2 = NULL, epsg2proj[GMT_LEN256] = {""}, wktext[32] = {""}, *pch; |
| 18275 | bool do_free = false; |
| 18276 | int error = 0, scale_pos; |
| 18277 | size_t k, len; |
| 18278 | double sc; |
| 18279 | |
| 18280 | if (item[0] == '+') { |
| 18281 | bool found = false; |
| 18282 | len = strlen(item); |
| 18283 | for (k = 1; k < len; k++) { /* Search for glued tokens */ |
| 18284 | if (item[k] == '+' && item[k-1] != ' ') { |
| 18285 | found = true; |
| 18286 | break; |
| 18287 | } |
| 18288 | } |
| 18289 | if (found) { /* OK, need to break up things like +x=0+y=0 into "+x=0 +y=0" */ |
| 18290 | item_t1 = gmt_strrep(item, "+", " +"); |
| 18291 | do_free = true; /* Signal that we must free item_t1 */ |
| 18292 | } |
| 18293 | else |
| 18294 | item_t1 = item; |
| 18295 | |
| 18296 | snprintf(GMT->common.J.proj4string, GMT_LEN256, "%s", item_t1); /* Copy the proj.4 string */ |
| 18297 | } |
| 18298 | else if (!strncmp(item, "EPSG:", 5) || !strncmp(item, "epsg:", 5)) |
| 18299 | item_t1 = &item[5]; /* Drop the EPSG: part because gmt_impotproj4 is not expecting it */ |
| 18300 | else |
| 18301 | item_t1 = item; |
| 18302 | |
| 18303 | item_t2 = gmt_importproj4(GMT, item_t1, &scale_pos, epsg2proj); /* This is the GMT -J proj string */ |
| 18304 | if (item_t2 && !GMT->current.ps.active && !strcmp(item_t2, "/1:1")) { |
| 18305 | /* Even though it failed to do the mapping we can still use it in mapproject */ |
| 18306 | GMT->current.proj.projection_GMT = GMT_NO_PROJ; |
| 18307 | GMT->current.proj.is_proj4 = true; |
| 18308 | GMT->current.proj.pars[14] = 1; |
| 18309 | } |
| 18310 | else if (item_t2) { |
| 18311 | char *pch2; |
| 18312 | len = strlen(item_t2); |
| 18313 | if (item_t2[len-1] == 'W') { /* See if scale is in fact a width */ |
| 18314 | item_t2[0] = (char)toupper(item_t2[0]); /* and let the GMT machinery detect this fact */ |
| 18315 | item_t2[len-1] = '\0'; |
| 18316 | } |
| 18317 | if (scale_pos != 0) { /* Because if == 0 than it means we have a scale only string (i.e. no GMT mapped proj) */ |
| 18318 | error += (gmt_M_check_condition(GMT, GMT->common.J.active, "Option -J given more than once\n") || |
| 18319 | gmtinit_parse_J_option (GMT, item_t2)); |
| 18320 | } |
| 18321 | else /* Not particularly useful yet because mapproject will fail anyway when scale != 1:1 */ |
| 18322 | GMT->current.proj.projection_GMT = GMT_NO_PROJ; |
| 18323 | |
| 18324 | /* If input was a EPSG code, save the epsg -> proj conversion string. Save also if input was a +proj string */ |
| 18325 | if (epsg2proj[0] != '\0') snprintf(GMT->common.J.proj4string, GMT_LEN256-1, "%s", epsg2proj); |
| 18326 | else if (item_t1[0] == '+') snprintf(GMT->common.J.proj4string, GMT_LEN256-1, "%s", item_t1); |
| 18327 | |
| 18328 | /* Check if the scale is 1 or 1:1, and don't get fooled with, for example, 1:10 */ |
| 18329 | pch = &item_t2[scale_pos]; |
no test coverage detected