GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
do_proj.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <string.h>
19 #include <ctype.h>
20 
21 #include <grass/gis.h>
22 #include <grass/gprojects.h>
23 #include <grass/glocale.h>
24 
25 /* a couple defines to simplify reading the function */
26 #define MULTIPLY_LOOP(x,y,c,m) \
27 do {\
28  int i; \
29  for (i = 0; i < c; ++i) {\
30  x[i] *= m; \
31  y[i] *= m; \
32  }\
33 } while (0)
34 
35 #define DIVIDE_LOOP(x,y,c,m) \
36 do {\
37  int i; \
38  for (i = 0; i < c; ++i) {\
39  x[i] /= m; \
40  y[i] /= m; \
41  }\
42 } while (0)
43 
44 static double METERS_in = 1.0, METERS_out = 1.0;
45 
63 int pj_do_proj(double *x, double *y,
64  struct pj_info *info_in, struct pj_info *info_out)
65 {
66  int ok;
67  double u, v;
68  double h = 0.0;
69 
70  METERS_in = info_in->meters;
71  METERS_out = info_out->meters;
72 
73  if (strncmp(info_in->proj, "ll", 2) == 0) {
74  if (strncmp(info_out->proj, "ll", 2) == 0) {
75  u = (*x) / RAD_TO_DEG;
76  v = (*y) / RAD_TO_DEG;
77  ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
78  *x = u * RAD_TO_DEG;
79  *y = v * RAD_TO_DEG;
80  }
81  else {
82  u = (*x) / RAD_TO_DEG;
83  v = (*y) / RAD_TO_DEG;
84  ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
85  *x = u / METERS_out;
86  *y = v / METERS_out;
87  }
88  }
89  else {
90  if (strncmp(info_out->proj, "ll", 2) == 0) {
91  u = *x * METERS_in;
92  v = *y * METERS_in;
93  ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
94  *x = u * RAD_TO_DEG;
95  *y = v * RAD_TO_DEG;
96  }
97  else {
98  u = *x * METERS_in;
99  v = *y * METERS_in;
100  ok = pj_transform(info_in->pj, info_out->pj, 1, 0, &u, &v, &h);
101  *x = u / METERS_out;
102  *y = v / METERS_out;
103  }
104  }
105  if (ok < 0) {
106  G_warning(_("pj_transform() failed: %s"), pj_strerrno(ok));
107  }
108  return ok;
109 }
110 
134 int pj_do_transform(int count, double *x, double *y, double *h,
135  struct pj_info *info_in, struct pj_info *info_out)
136 {
137  int ok;
138  int has_h = 1;
139 
140  METERS_in = info_in->meters;
141  METERS_out = info_out->meters;
142 
143  if (h == NULL) {
144  int i;
145 
146  h = G_malloc(sizeof *h * count);
147  /* they say memset is only guaranteed for chars ;-( */
148  for (i = 0; i < count; ++i)
149  h[i] = 0.0;
150  has_h = 0;
151  }
152  if (strncmp(info_in->proj, "ll", 2) == 0) {
153  if (strncmp(info_out->proj, "ll", 2) == 0) {
154  DIVIDE_LOOP(x, y, count, RAD_TO_DEG);
155  ok = pj_transform(info_in->pj, info_out->pj, count, 1, x, y, h);
156  MULTIPLY_LOOP(x, y, count, RAD_TO_DEG);
157  }
158  else {
159  DIVIDE_LOOP(x, y, count, RAD_TO_DEG);
160  ok = pj_transform(info_in->pj, info_out->pj, count, 1, x, y, h);
161  DIVIDE_LOOP(x, y, count, METERS_out);
162  }
163  }
164  else {
165  if (strncmp(info_out->proj, "ll", 2) == 0) {
166  MULTIPLY_LOOP(x, y, count, METERS_in);
167  ok = pj_transform(info_in->pj, info_out->pj, count, 1, x, y, h);
168  MULTIPLY_LOOP(x, y, count, RAD_TO_DEG);
169  }
170  else {
171  MULTIPLY_LOOP(x, y, count, METERS_in);
172  ok = pj_transform(info_in->pj, info_out->pj, count, 1, x, y, h);
173  DIVIDE_LOOP(x, y, count, METERS_out);
174  }
175  }
176  if (!has_h)
177  G_free(h);
178 
179  if (ok < 0) {
180  G_warning(_("pj_transform() failed: %s"), pj_strerrno(ok));
181  }
182  return ok;
183 }
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
int pj_do_proj(double *x, double *y, struct pj_info *info_in, struct pj_info *info_out)
Re-project a point between two co-ordinate systems.
Definition: do_proj.c:63
int count
#define DIVIDE_LOOP(x, y, c, m)
Definition: do_proj.c:35
int y
Definition: plot.c:34
int pj_do_transform(int count, double *x, double *y, double *h, struct pj_info *info_in, struct pj_info *info_out)
Re-project an array of points between two co-ordinate systems with optional ellipsoidal height conver...
Definition: do_proj.c:134
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
#define MULTIPLY_LOOP(x, y, c, m)
Definition: do_proj.c:26
tuple h
panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _(&quot;Use default size&quot;)) panel...