report.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /****************************************************************************
  2. *
  3. * MODULE: r.distance
  4. *
  5. * AUTHOR(S): Michael Shapiro - CERL
  6. *
  7. * PURPOSE: Locates the closest points between objects in two
  8. * raster maps.
  9. *
  10. * COPYRIGHT: (C) 2003 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. ***************************************************************************/
  17. #include <grass/glocale.h>
  18. #include "defs.h"
  19. void report(struct Parms *parms)
  20. {
  21. int i1, i2;
  22. struct Map *map1, *map2;
  23. char *fs;
  24. double distance, north1, east1, north2, east2;
  25. struct Cell_head region;
  26. struct CatEdgeList *list1, *list2;
  27. char temp[100];
  28. extern void find_minimum_distance();
  29. extern char *get_label();
  30. G_get_set_window(&region);
  31. G_begin_distance_calculations();
  32. map1 = &parms->map1;
  33. map2 = &parms->map2;
  34. fs = parms->fs;
  35. G_message(_("Processing..."));
  36. for (i1 = 0; i1 < map1->edges.ncats; i1++) {
  37. list1 = &map1->edges.catlist[i1];
  38. for (i2 = 0; i2 < map2->edges.ncats; i2++) {
  39. list2 = &map2->edges.catlist[i2];
  40. find_minimum_distance(list1, list2,
  41. &east1, &north1, &east2, &north2, &distance,
  42. &region, parms->overlap, map1->name,
  43. map2->name);
  44. /* print cat numbers */
  45. fprintf(stdout, "%ld%s%ld", (long)list1->cat, fs,
  46. (long)list2->cat);
  47. /* print distance */
  48. sprintf(temp, "%.10f", distance);
  49. G_trim_decimal(temp);
  50. fprintf(stdout, "%s%s", fs, temp);
  51. /* print coordinates of the closest pair */
  52. G_format_easting(east1, temp,
  53. G_projection() == PROJECTION_LL ? -1 : 0);
  54. fprintf(stdout, "%s%s", fs, temp);
  55. G_format_northing(north1, temp,
  56. G_projection() == PROJECTION_LL ? -1 : 0);
  57. fprintf(stdout, "%s%s", fs, temp);
  58. G_format_easting(east2, temp,
  59. G_projection() == PROJECTION_LL ? -1 : 0);
  60. fprintf(stdout, "%s%s", fs, temp);
  61. G_format_northing(north2, temp,
  62. G_projection() == PROJECTION_LL ? -1 : 0);
  63. fprintf(stdout, "%s%s", fs, temp);
  64. /* print category labels */
  65. if (parms->labels) {
  66. fprintf(stdout, "%s%s", fs, get_label(map1, list1->cat));
  67. fprintf(stdout, "%s%s", fs, get_label(map2, list2->cat));
  68. }
  69. fprintf(stdout, "\n");
  70. }
  71. }
  72. }