GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Macros
Pages
make_mapset.c
Go to the documentation of this file.
1
2
/******************************************************************************
3
*
4
* Project: libgrass
5
* Purpose: Function to create a new mapset within an existing location
6
* Author(s): Joel Pitt, joel.pitt@gmail.com
7
*
8
******************************************************************************
9
* Copyright (c) 2006, Joel Pitt
10
*
11
* This library is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Library General Public
13
* License as published by the Free Software Foundation; either
14
* version 2 of the License, or (at your option) any later version.
15
*
16
* This library is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* Library General Public License for more details.
20
*
21
* You should have received a copy of the GNU Library General Public
22
* License along with this library; if not, write to the
23
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
******************************************************************************
25
*
26
*/
27
28
#include <grass/gis.h>
29
30
#include <stdlib.h>
31
#include <string.h>
32
#include <unistd.h>
33
#include <sys/stat.h>
34
35
/*
36
* Returns 0 on success.
37
* Returns -1 to indicate a system error (check errno).
38
*/
39
40
41
int
G__make_mapset
(
const
char
*gisdbase_name,
const
char
*location_name,
42
const
char
*mapset_name)
43
{
44
char
path[GPATH_MAX];
45
struct
Cell_head default_window;
46
47
/* Get location */
48
if
(location_name ==
NULL
)
49
location_name =
G_location
();
50
51
/* Get GISDBASE */
52
if
(gisdbase_name ==
NULL
)
53
gisdbase_name =
G_gisdbase
();
54
55
/* TODO: Should probably check that user specified location and gisdbase are valid */
56
57
/* Make the mapset. */
58
sprintf(path,
"%s/%s/%s"
, gisdbase_name, location_name, mapset_name);
59
if
(
G_mkdir
(path) != 0)
60
return
-1;
61
62
G__create_alt_env
();
63
64
/* Get PERMANENT default window */
65
G__setenv
(
"GISDBASE"
, gisdbase_name);
66
G__setenv
(
"LOCATION"
, location_name);
67
G__setenv
(
"MAPSET"
,
"PERMANENT"
);
68
G_get_default_window
(&default_window);
69
70
/* Change to the new mapset */
71
G__setenv
(
"MAPSET"
, mapset_name);
72
73
/* Copy default window/regions to new mapset */
74
G__put_window
(&default_window,
""
,
"WIND"
);
75
76
/* And switch back to original environment */
77
G__switch_env
();
78
79
return
0;
80
}
81
82
105
int
G_make_mapset
(
const
char
*gisdbase_name,
const
char
*location_name,
106
const
char
*mapset_name)
107
{
108
int
err
;
109
110
err =
G__make_mapset
(gisdbase_name, location_name, mapset_name);
111
112
if
(err == 0)
113
return
0;
114
115
if
(err == -1) {
116
perror(
"G_make_mapset"
);
117
}
118
119
G_fatal_error
(
"G_make_mapset failed."
);
120
121
return
1;
122
}
lib
gis
make_mapset.c
Generated on Thu Sep 26 2013 09:48:04 for GRASS Programmer's Manual by
1.8.4