2
/******************************************************************************
5
* Purpose: Function to create a new location automatically given a
6
* "Cell_head", PROJ_INFO and PROJ_UNITS information.
7
* Author: Frank Warmerdam, warmerda@pobox.com
9
******************************************************************************
10
* Copyright (c) 2000, Frank Warmerdam
12
* This library is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU Library General Public
14
* License as published by the Free Software Foundation; either
15
* version 2 of the License, or (at your option) any later version.
17
* This library is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
* Library General Public License for more details.
22
* You should have received a copy of the GNU Library General Public
23
* License along with this library; if not, write to the
24
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
******************************************************************************
2
* \file lib/gis/make_loc.c
4
* \brief GIS Library - Functions to create a new location
6
* Creates a new location automatically given a "Cell_head", PROJ_INFO
7
* and PROJ_UNITS information.
9
* (C) 2000-2013 by the GRASS Development Team
11
* This program is free software under the GNU General Public License
12
* (>=v2). Read the file COPYING that comes with GRASS for details.
14
* \author Frank Warmerdam
29
17
#include <grass/gis.h>
34
22
#include <sys/stat.h>
38
* Returns 0 on success.
39
* Returns -1 to indicate a system error (check errno).
26
* \brief Create a new location
28
* This function creates a new location in the current database,
29
* initializes the projection, default window and current window.
31
* \param location_name Name of the new location. Should not include
32
* the full path, the location will be created within
33
* the current database.
34
* \param wind default window setting for the new location.
35
* All fields should be set in this
36
* structure, and care should be taken to ensure that
37
* the proj/zone fields match the definition in the
38
* proj_info parameter(see G_set_cellhd_from_projinfo()).
40
* \param proj_info projection definition suitable to write to the
41
* PROJ_INFO file, or NULL for PROJECTION_XY.
43
* \param proj_units projection units suitable to write to the PROJ_UNITS
46
* \return 0 on success
47
* \return -1 to indicate a system error (check errno).
48
* \return -2 failed to create projection file (currently not used)
49
* \return -3 illegal name
43
int G__make_location(const char *location_name,
44
struct Cell_head *wind,
45
struct Key_Value *proj_info,
46
struct Key_Value *proj_units, FILE * report_file)
51
int G_make_location(const char *location_name,
52
struct Cell_head *wind,
53
const struct Key_Value *proj_info,
54
const struct Key_Value *proj_units)
48
56
char path[GPATH_MAX];
58
/* check if location name is legal */
59
if (G_legal_filename(location_name) != 1)
51
62
/* Try to create the location directory, under the gisdbase. */
52
63
sprintf(path, "%s/%s", G_gisdbase(), location_name);
56
67
/* Make the PERMANENT mapset. */
57
68
sprintf(path, "%s/%s/%s", G_gisdbase(), location_name, "PERMANENT");
58
if (G_mkdir(path) != 0)
69
if (G_mkdir(path) != 0) {
61
73
/* make these the new current location and mapset */
62
G__setenv("LOCATION_NAME", location_name);
63
G__setenv("MAPSET", "PERMANENT");
74
G_setenv_nogisrc("LOCATION_NAME", location_name);
75
G_setenv_nogisrc("MAPSET", "PERMANENT");
65
77
/* Create the default, and current window files */
66
G__put_window(wind, "", "DEFAULT_WIND");
67
G__put_window(wind, "", "WIND");
78
G_put_element_window(wind, "", "DEFAULT_WIND");
79
G_put_element_window(wind, "", "WIND");
69
81
/* Write out the PROJ_INFO, and PROJ_UNITS if available. */
70
82
if (proj_info != NULL) {
71
G__file_name(path, "", "PROJ_INFO", "PERMANENT");
72
G_write_key_value_file(path, proj_info, &out_stat);
83
G_file_name(path, "", "PROJ_INFO", "PERMANENT");
84
G_write_key_value_file(path, proj_info);
77
87
if (proj_units != NULL) {
78
G__file_name(path, "", "PROJ_UNITS", "PERMANENT");
79
G_write_key_value_file(path, proj_units, &out_stat);
88
G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
89
G_write_key_value_file(path, proj_units);
89
* \brief create a new location
91
* This function creates a new location in the current database,
92
* initializes the projection, default window and current window.
94
* \param location_name
95
* The name of the new location. Should not include
96
* the full path, the location will be created within
97
* the current database.
99
* Contains the default window setting for the
100
* new location. All fields should be set in this
101
* structure, and care should be taken to ensure that
102
* the proj/zone fields match the definition in the
103
* proj_info parameter (see G_set_cellhd_from_projinfo()).
106
* Projection definition suitable to write to the
107
* PROJ_INFO file, or NULL for PROJECTION_XY.
110
* Projection units suitable to write to the PROJ_UNITS
114
* File to which creation information should be written
115
* (can be stdout). Currently not used.
117
* \return Returns 0 on success, or generates a fatal error on failure.
118
* The G__make_location() function operates the same, but returns a
119
* non-zero error code on failure, instead of terminating.
122
int G_make_location(const char *location_name,
123
struct Cell_head *wind,
124
struct Key_Value *proj_info,
125
struct Key_Value *proj_units, FILE * report_file)
129
err = G__make_location(location_name, wind, proj_info, proj_units,
136
perror("G_make_location");
139
G_fatal_error("G_make_location failed.");
145
/************************************************************************/
146
/* G_compare_projections() */
148
/************************************************************************/
151
* \brief compare projections
157
* \return -1 if not the same projection, -2 if linear unit translation to
158
* meters fails, -4 if not the same ellipsoid,
159
* -5 if UTM zone differs, -6 if UTM hemisphere differs,
160
* -7 if false easting differs, -8 if false northing differs,
161
* else TRUE if projections match.
166
G_compare_projections(const struct Key_Value *proj_info1,
167
const struct Key_Value *proj_units1,
168
const struct Key_Value *proj_info2,
169
const struct Key_Value *proj_units2)
96
* \brief Compare projections including units
98
* \param proj_info1 projection info to compare
99
* \param proj_units1 projection units to compare
100
* \param proj_info2 projection info to compare
101
* \param proj_units2 projection units to compare
103
* \return -1 if not the same projection
104
* \return -2 if linear unit translation to meters fails
105
* \return -4 if not the same ellipsoid,
106
* \return -5 if UTM zone differs
107
* \return -6 if UTM hemisphere differs,
108
* \return -7 if false easting differs
109
* \return -8 if false northing differs,
110
* \return 1 if projections match.
112
int G_compare_projections(const struct Key_Value *proj_info1,
113
const struct Key_Value *proj_units1,
114
const struct Key_Value *proj_info2,
115
const struct Key_Value *proj_units2)
171
117
const char *proj1, *proj2;