コード例 #1
0
ファイル: windowio.c プロジェクト: rashadkm/grass_cmake
int Rast3d_read_window(RASTER3D_Region * window, const char *windowName)
{
    struct Cell_head win;
    struct Key_Value *windowKeys;
    char path[GPATH_MAX];


    if (windowName == NULL) {
	G_get_window(&win);

	window->proj = win.proj;
	window->zone = win.zone;
	window->north = win.north;
	window->south = win.south;
	window->east = win.east;
	window->west = win.west;
	window->top = win.top;
	window->bottom = win.bottom;
	window->rows = win.rows3;
	window->cols = win.cols3;
	window->depths = win.depths;
	window->ns_res = win.ns_res3;
	window->ew_res = win.ew_res3;
	window->tb_res = win.tb_res;
    }
    else {
	Rast3d_getFullWindowPath(path, windowName);

	if (access(path, R_OK) != 0) {
	    G_warning("Rast3d_read_window: unable to find [%s].", path);
	    return 0;
	}

	windowKeys = G_read_key_value_file(path);

	if (!Rast3d_readWriteWindow(windowKeys, 1,
				 &(window->proj), &(window->zone),
				 &(window->north), &(window->south),
				 &(window->east), &(window->west),
				 &(window->top), &(window->bottom),
				 &(window->rows), &(window->cols),
				 &(window->depths), &(window->ew_res),
				 &(window->ns_res), &(window->tb_res))) {
	    Rast3d_error
		("Rast3d_read_window: error extracting window key(s) of file %s",
		 path);
	    return 0;
	}

	G_free_key_value(windowKeys);
    }

    return 1;
}
コード例 #2
0
ファイル: output.c プロジェクト: caomw/grass
void print_projinfo(int shell)
{
    int i;
    char path[GPATH_MAX];

    if (check_xy(shell))
	return;

    if (!shell)
	fprintf(stdout,
		"-PROJ_INFO-------------------------------------------------\n");
    for (i = 0; i < projinfo->nitems; i++) {
	if (shell)
	    fprintf(stdout, "%s=%s\n", projinfo->key[i], projinfo->value[i]);
	else
	    fprintf(stdout, "%-11s: %s\n", projinfo->key[i], projinfo->value[i]);
    }

    /* EPSG code is preserved for historical metadata interest only:
	the contents of this file are not used by pj_*() routines at all */
    G_file_name(path, "", "PROJ_EPSG", "PERMANENT");
    if (access(path, F_OK) == 0) {
	struct Key_Value *in_epsg_key;
	in_epsg_key = G_read_key_value_file(path);
	if (!shell) {
	    fprintf(stdout,
		"-PROJ_EPSG-------------------------------------------------\n");
	    fprintf(stdout, "%-11s: %s\n", in_epsg_key->key[0],
		    in_epsg_key->value[0]);
	}
	else
	    fprintf(stdout, "%s=%s\n", in_epsg_key->key[0],
		    in_epsg_key->value[0]);

	if (in_epsg_key != NULL)
	    G_free_key_value(in_epsg_key);
    }
 
    if (!shell)
	fprintf(stdout,
		"-PROJ_UNITS------------------------------------------------\n");
    for (i = 0; i < projunits->nitems; i++) {
	if (shell)
	    fprintf(stdout, "%s=%s\n",
		    projunits->key[i], projunits->value[i]);
	else
	    fprintf(stdout, "%-11s: %s\n",
		    projunits->key[i], projunits->value[i]);
    }
    
    return;
}
コード例 #3
0
ファイル: color_rules.c プロジェクト: rashadkm/grass_cmake
/*!
  \brief Get color rules description for Option->descriptions

  \return allocated buffer with descriptions
*/
char *G_color_rules_descriptions(void)
{
    char path[GPATH_MAX];
    struct Key_Value *kv;
    int result_len, result_max;
    char *result, **rules;
    const char *name, *desc;
    int i, len, nrules;

    result_len = 0;
    result_max = 2000;
    result = G_malloc(result_max);
    
    G_snprintf(path, GPATH_MAX, "%s/etc/colors.desc", G_gisbase());
    kv = G_read_key_value_file(path);
    if (!kv)
        return NULL;

    rules = scan_rules(&nrules);
    
    for (i = 0; i < nrules; i++) {
        name = rules[i];
        desc = G_find_key_value(name, kv);
        
        if (!desc)
	    desc = _("no description");
	
        /* desc = _(desc); */
	
        len = strlen(name) + strlen(desc) + 2;
        if (result_len + len >= result_max) {
            result_max = result_len + len + 1000;
            result = G_realloc(result, result_max);
        }

        sprintf(result + result_len, "%s;%s;", name, desc);
        result_len += len;
    }

    G_free_key_value(kv);
    G_free(rules);
    
    return result;
}
コード例 #4
0
ファイル: main.c プロジェクト: imincik/pkg-grass
static char *rules_descriptions(void)
{
    char path[GPATH_MAX];
    struct Key_Value *kv;
    int result_len = 0;
    int result_max = 2000;
    char *result = G_malloc(result_max);
    int stat;
    int i;

    sprintf(path, "%s/etc/colors.desc", G_gisbase());
    kv = G_read_key_value_file(path, &stat);
    if (!kv || stat < 0)
	return NULL;

    for (i = 0; i < nrules; i++) {
	const char *name = rules[i];
	const char *desc = G_find_key_value(name, kv);
	int len;

	if (!desc)
	    desc = "no description";

	desc = _(desc);

	len = strlen(name) + strlen(desc) + 2;
	if (result_len + len >= result_max) {
	    result_max = result_len + len + 1000;
	    result = G_realloc(result, result_max);
	}

	sprintf(result + result_len, "%s;%s;", name, desc);
	result_len += len;
    }

    G_free_key_value(kv);

    return result;
}
コード例 #5
0
ファイル: get_ellipse.c プロジェクト: caomw/grass
/*!
 * \brief get ellipsoid parameters
 *
 * This routine returns the semi-major axis <b>a</b> (in meters) and
 * the eccentricity squared <b>e2</b> for the ellipsoid associated
 * with the database. If there is no ellipsoid explicitly associated
 * with the database, it returns the values for the WGS 84 ellipsoid.
 *
 * \param[out] a semi-major axis
 * \param[out] e2 eccentricity squared
 *
 * \return 1 success
 * \return 0 default values used
 */
int G_get_ellipsoid_parameters(double *a, double *e2)
{
    int stat;
    char ipath[GPATH_MAX];
    struct Key_Value *proj_keys;

    proj_keys = NULL;

    G_file_name(ipath, "", PROJECTION_FILE, PERMANENT);

    if (access(ipath, 0) != 0) {
	*a = 6378137.0;
	*e2 = .006694385;
	return 0;
    }

    proj_keys = G_read_key_value_file(ipath);

    stat = get_ellipsoid_parameters(proj_keys, a, e2);

    G_free_key_value(proj_keys);

    return stat;
}