File: write_grid.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (135 lines) | stat: -rw-r--r-- 2,939 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include "gis.h"
#include "Vect.h"
#include "grid_structs.h"
#include "local_proto.h"

int write_grid (struct grid_description *grid_info,
  struct Map_info *Map, int quiet)
{

  int i, k;
  int rows, cols, x_cols;
  int num_v_rows, num_v_cols;
  double x, y, x_len;
  double sx, sy;
  double width, length;
  double next_x, next_y;
  double snext_x, snext_y;
  double angle, dum;

  struct line_pnts *Points;

  Points = Vect_new_line_struct ();

  num_v_rows = grid_info->num_vect_rows;
  num_v_cols = grid_info->num_vect_cols;
  rows = grid_info->num_rows;
  cols = grid_info->num_cols;
  width = grid_info->width;
  length = grid_info->length;
  angle = grid_info->angle;

/*
* For latlon, must draw in shorter sections
* to make sure that each section of the grid
* line is less than half way around the globe
*/
  x_len = length/3.;
  x_cols = cols*3.;

  /* write out all the vector lengths (x vectors) of the entire grid  */
  if (!quiet)
    fprintf (stderr,"Writing out vector rows ...\n");

  y = grid_info->origin_y;
  for (i = 0; i < num_v_rows; ++i)
  {
    x = grid_info->origin_x;
    for (k = 0; k < x_cols; ++k)
    {
      next_x = x + x_len;

      sx = x;
      sy = y;
      snext_x = next_x;
      dum = y;

      rotate (&x, &y, grid_info->origin_x, grid_info->origin_y, angle);
      rotate (&next_x, &dum, grid_info->origin_x, grid_info->origin_y, angle);
      write_vect (x, y, next_x, dum, Map, Points);

      y = sy;
      x = next_x = snext_x;
    }
    y += width;
  }

  /* write out all the vector widths (y vectors) of the entire grid  */
  if (!quiet)
    fprintf (stdout,"Writing out vector columns ...\n");
  x = grid_info->origin_x;
  for (k = 0; k < num_v_cols; ++k)
  {
    y = grid_info->origin_y;
    for (i = 0; i < rows; ++i)
    {
      next_y = y + width;

      sx = x;
      sy = y;
      snext_y = next_y;
      dum = x;
      rotate (&x, &y, grid_info->origin_x, grid_info->origin_y, angle);
      rotate (&dum, &next_y, grid_info->origin_x, grid_info->origin_y, angle);

      write_vect (x, y, dum, next_y, Map, Points);

      x = sx;
      y = next_y = snext_y;
    }
    /* To get exactly the same coordinates as above, x+=length is wrong */
    x += x_len;
    x += x_len;
    x += x_len;
  }

  /* new with Vlib */
  Vect_destroy_line_struct (Points);

  return (0);
}

static double xarray[10];
static double yarray[10];

#define  NUM_POINTS  2

int 
write_vect (
    double x1,
    double y1,
    double x2,
    double y2,
    struct Map_info *Map,
    struct line_pnts *Points	/* new with Vlib */
)
{
  static struct line_cats *Cats = NULL;

  if ( !Cats ) {
      Cats = Vect_new_cats_struct ();
  }

  xarray[0] = x1;
  xarray[1] = x2;
  yarray[0] = y1;
  yarray[1] = y2;

  if (0 > Vect_copy_xyz_to_pnts (Points, xarray, yarray, NULL, NUM_POINTS))
    G_fatal_error ("Out of memory");
  
  Vect_write_line (Map, GV_BOUNDARY, Points, Cats);

  return 0;
}