~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to general/g.proj/create.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
#include "local_proto.h"
8
8
 
9
 
void create_location(char *location)
 
9
void create_location(const char *location, const char *epsg)
10
10
{
11
11
    int ret;
12
12
 
13
 
    ret = G__make_location(location, &cellhd, projinfo, projunits, NULL);
 
13
    ret = G_make_location(location, &cellhd, projinfo, projunits);
14
14
    if (ret == 0)
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"),
21
21
                    strerror(errno));
22
22
    else
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);
25
25
 
 
26
    /* create also PROJ_EPSG */
 
27
    if (epsg)
 
28
        create_epsg(location, epsg);
 
29
        
26
30
    G_message(_("You can switch to the new location by\n`%s=%s`"),
27
31
              "g.mapset mapset=PERMANENT location", location);
28
32
}
34
38
    
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>)"),
38
42
                      mapset);
39
43
    
40
44
    /* Read projection information from current location first */
41
45
    G_get_default_window(&old_cellhd);
42
46
    
43
47
    char path[GPATH_MAX];
44
 
    int stat;
45
48
        
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);
50
53
    }
51
54
    
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);
55
58
    }
56
59
    
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"));
66
69
    }
67
70
    G_important_message(_("Projection information updated"));
68
71
}
 
72
 
 
73
void create_epsg(const char *location, const char *epsg)
 
74
{
 
75
    FILE *fp;
 
76
    char path[GPATH_MAX];
 
77
    
 
78
    /* if inputs were not clean it should of failed by now */
 
79
    if (location) {
 
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';
 
84
    }
 
85
    else {
 
86
        G_file_name(path, "", "PROJ_EPSG", "PERMANENT");
 
87
    }
 
88
    
 
89
    fp = fopen(path, "w");
 
90
    if (!fp)
 
91
        G_fatal_error(_("Unable to create PROJ_EPSG file: %s"), strerror (errno));
 
92
    
 
93
#ifdef HAVE_OGR
 
94
    fprintf(fp, "epsg: %s\n", epsg);
 
95
#endif
 
96
    fclose(fp);
 
97
}