7
7
#include "local_proto.h"
9
void create_location(char *location)
9
void create_location(const char *location, const char *epsg)
13
ret = G__make_location(location, &cellhd, projinfo, projunits, NULL);
13
ret = G_make_location(location, &cellhd, projinfo, projunits);
15
15
G_message(_("Location <%s> created"), location);
16
16
else if (ret == -1)
17
17
G_fatal_error(_("Unable to create location <%s>: %s"),
18
location, strerror(errno));
18
location, strerror(errno));
19
19
else if (ret == -2)
20
G_fatal_error(_("Unable to create projection files: %s"),
20
G_fatal_error(_("Unable to create projection files: %s"),
23
23
/* Shouldn't happen */
24
G_fatal_error(_("Unspecified error while creating new location"));
24
G_fatal_error(_("Unable to create location <%s>"), location);
26
/* create also PROJ_EPSG */
28
create_epsg(location, epsg);
26
30
G_message(_("You can switch to the new location by\n`%s=%s`"),
27
31
"g.mapset mapset=PERMANENT location", location);
35
39
if (strcmp(mapset, "PERMANENT") != 0)
36
40
G_fatal_error(_("You must select the PERMANENT mapset before updating the "
37
"current location's projection (current mapset is <%s>)."),
41
"current location's projection (current mapset is <%s>)"),
40
44
/* Read projection information from current location first */
41
45
G_get_default_window(&old_cellhd);
43
47
char path[GPATH_MAX];
46
49
/* Write out the PROJ_INFO, and PROJ_UNITS if available. */
47
50
if (projinfo != NULL) {
48
G__file_name(path, "", "PROJ_INFO", "PERMANENT");
49
G_write_key_value_file(path, projinfo, &stat);
51
G_file_name(path, "", "PROJ_INFO", "PERMANENT");
52
G_write_key_value_file(path, projinfo);
52
55
if (projunits != NULL) {
53
G__file_name(path, "", "PROJ_UNITS", "PERMANENT");
54
G_write_key_value_file(path, projunits, &stat);
56
G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
57
G_write_key_value_file(path, projunits);
57
60
if ((old_cellhd.zone != cellhd.zone) ||
58
61
(old_cellhd.proj != cellhd.proj)) {
59
62
/* Recreate the default, and current window files if projection
60
63
* number or zone have changed */
61
G__put_window(&cellhd, "", "DEFAULT_WIND");
62
G__put_window(&cellhd, "", "WIND");
64
G_put_element_window(&cellhd, "", "DEFAULT_WIND");
65
G_put_element_window(&cellhd, "", "WIND");
63
66
G_message(_("Default region was updated to the new projection, but if you have "
64
67
"multiple mapsets `g.region -d` should be run in each to update the "
65
68
"region from the default"));
67
70
G_important_message(_("Projection information updated"));
73
void create_epsg(const char *location, const char *epsg)
78
/* if inputs were not clean it should of failed by now */
80
snprintf(path, sizeof(path), "%s%c%s%c%s%c%s", G_gisdbase(), HOST_DIRSEP,
81
location, HOST_DIRSEP,
82
"PERMANENT", HOST_DIRSEP, "PROJ_EPSG");
83
path[sizeof(path)-1] = '\0';
86
G_file_name(path, "", "PROJ_EPSG", "PERMANENT");
89
fp = fopen(path, "w");
91
G_fatal_error(_("Unable to create PROJ_EPSG file: %s"), strerror (errno));
94
fprintf(fp, "epsg: %s\n", epsg);