source: grass/trunk/general/g.proj/output.c

Last change on this file was 74192, checked in by mmetz, 5 years ago

libgis: get srid for proj_create_crs_to_crs()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id
  • Property svn:mime-type set to text/x-csrc
File size: 4.7 KB
Line 
1/*
2 ****************************************************************************
3 *
4 * MODULE: g.proj
5 * AUTHOR(S): Paul Kelly - paul-grass@stjohnspoint.co.uk
6 * PURPOSE: Provides a means of reporting the contents of GRASS
7 * projection information files and creating
8 * new projection information files.
9 * COPYRIGHT: (C) 2003-2007 by the GRASS Development Team
10 *
11 * This program is free software under the GNU General Public
12 * License (>=v2). Read the file COPYING that comes with GRASS
13 * for details.
14 *
15 *****************************************************************************/
16
17#include <stdio.h>
18#include <unistd.h>
19#include <string.h>
20
21#include <grass/gis.h>
22#include <grass/gprojects.h>
23#include <grass/glocale.h>
24#include <grass/config.h>
25
26#include "local_proto.h"
27
28static int check_xy(int shell);
29
30/* print projection information gathered from one of the possible inputs */
31void print_projinfo(int shell)
32{
33 int i;
34
35 if (check_xy(shell))
36 return;
37
38 if (!shell)
39 fprintf(stdout,
40 "-PROJ_INFO-------------------------------------------------\n");
41 for (i = 0; i < projinfo->nitems; i++) {
42 if (strcmp(projinfo->key[i], "init") == 0)
43 continue;
44 if (shell)
45 fprintf(stdout, "%s=%s\n", projinfo->key[i], projinfo->value[i]);
46 else
47 fprintf(stdout, "%-11s: %s\n", projinfo->key[i], projinfo->value[i]);
48 }
49
50 if (projepsg) {
51 const char *epsg_value, *epsg_key;
52
53 epsg_key = projepsg->key[0];
54 epsg_value = projepsg->value[0];
55
56 if (!shell) {
57 fprintf(stdout,
58 "-PROJ_EPSG-------------------------------------------------\n");
59 fprintf(stdout, "%-11s: %s\n", epsg_key, epsg_value);
60 }
61 else
62 fprintf(stdout, "%s=%s\n", epsg_key, epsg_value);
63 }
64
65 if (projunits) {
66 if (!shell)
67 fprintf(stdout,
68 "-PROJ_UNITS------------------------------------------------\n");
69 for (i = 0; i < projunits->nitems; i++) {
70 if (shell)
71 fprintf(stdout, "%s=%s\n",
72 projunits->key[i], projunits->value[i]);
73 else
74 fprintf(stdout, "%-11s: %s\n",
75 projunits->key[i], projunits->value[i]);
76 }
77 }
78
79 return;
80}
81
82void print_datuminfo(void)
83{
84 char *datum, *params;
85 struct gpj_datum dstruct;
86 int validdatum = 0;
87
88 if (check_xy(FALSE))
89 return;
90
91 GPJ__get_datum_params(projinfo, &datum, &params);
92
93 if (datum)
94 validdatum = GPJ_get_datum_by_name(datum, &dstruct);
95
96 if (validdatum > 0)
97 fprintf(stdout, "GRASS datum code: %s\nWKT Name: %s\n",
98 dstruct.name, dstruct.longname);
99 else if (datum)
100 fprintf(stdout, "Invalid datum code: %s\n", datum);
101 else
102 fprintf(stdout, "Datum name not present\n");
103
104 if (params)
105 fprintf(stdout,
106 "Datum transformation parameters (PROJ.4 format):\n"
107 "\t%s\n", params);
108 else if (validdatum > 0) {
109 char *defparams;
110
111 GPJ_get_default_datum_params_by_name(dstruct.name, &defparams);
112 fprintf(stdout,
113 "Datum parameters not present; default for %s is:\n"
114 "\t%s\n", dstruct.name, defparams);
115 G_free(defparams);
116 }
117 else
118 fprintf(stdout, "Datum parameters not present\n");
119
120 if (validdatum > 0)
121 GPJ_free_datum(&dstruct);
122
123 return;
124}
125
126void print_proj4(int dontprettify)
127{
128 struct pj_info pjinfo;
129 char *proj4, *proj4mod, *i;
130 const char *unfact;
131
132 if (check_xy(FALSE))
133 return;
134
135 if (pj_get_kv(&pjinfo, projinfo, projunits) == -1)
136 G_fatal_error(_("Unable to convert projection information to PROJ format"));
137 proj4 = pjinfo.def;
138#ifdef HAVE_PROJ_H
139 proj_destroy(pjinfo.pj);
140#else
141 pj_free(pjinfo.pj);
142#endif
143 /* GRASS-style PROJ.4 strings don't include a unit factor as this is
144 * handled separately in GRASS - must include it here though */
145 unfact = G_find_key_value("meters", projunits);
146 if (unfact != NULL && (strcmp(pjinfo.proj, "ll") != 0))
147 G_asprintf(&proj4mod, "%s +to_meter=%s", proj4, unfact);
148 else
149 proj4mod = G_store(proj4);
150
151 for (i = proj4mod; *i; i++) {
152 /* Don't print the first space */
153 if (i == proj4mod && *i == ' ')
154 continue;
155
156 if (*i == ' ' && *(i+1) == '+' && !(dontprettify))
157 fputc('\n', stdout);
158 else
159 fputc(*i, stdout);
160 }
161 fputc('\n', stdout);
162 G_free(proj4mod);
163
164 return;
165}
166
167#ifdef HAVE_OGR
168void print_wkt(int esristyle, int dontprettify)
169{
170 char *outwkt;
171
172 if (check_xy(FALSE))
173 return;
174
175 outwkt = GPJ_grass_to_wkt2(projinfo, projunits, projepsg, esristyle,
176 !(dontprettify));
177 if (outwkt != NULL) {
178 fprintf(stdout, "%s\n", outwkt);
179 G_free(outwkt);
180 }
181 else
182 G_warning(_("Unable to convert to WKT"));
183
184 return;
185}
186#endif
187
188static int check_xy(int shell)
189{
190 if (cellhd.proj == PROJECTION_XY) {
191 if (shell)
192 fprintf(stdout, "name=xy_location_unprojected\n");
193 else
194 fprintf(stdout, "XY location (unprojected)\n");
195 return 1;
196 }
197 else
198 return 0;
199}
Note: See TracBrowser for help on using the repository browser.