Esempio n. 1
0
void Segment_outfile (char* map_name, char* mapset, int* map_fd,
		         char* seg_name, int* seg_fd, SEGMENT* seg, char* prompt, int fract,
                 RASTER_MAP_TYPE data_type)
{
    int nrows;
    char* mapset_address;

    mapset_address = G_ask_cell_new (prompt, map_name);
    
	if (mapset_address == NULL)
	  G_fatal_error ("Can't continue without filename ");
	
    strcpy (mapset, mapset_address);
    
	if ((*map_fd = G_open_cell_new (map_name)) < 0)
	  G_fatal_error ("Can't create output layer ");

    nrows = G_window_rows ();
    strcpy (seg_name, Create_segment_file (nrows, fract, data_type));
    *seg_fd = open (seg_name, 2);
    
	if (*seg_fd < 0)
	  G_fatal_error ("Can't open segment disk file ");
	
    segment_init (seg, *seg_fd, 4);
}
Esempio n. 2
0
static void set_rgn(double *msc, char *name, char *name1, char *name2)
{
    char reg_name[20];
    int x0, y0, xp, yp, *x, *y, xstart, ystart, btn, d, method, meth;
    static int pts, rgn_cnt = 0;
    double dtmp, etmp;
    FILE *tmp;
    char *tempfile;

    /* get the name of the regions map */

    if (!G_ask_cell_new("    ENTER THE NEW REGION MAP NAME:", reg_name))
	return;

    /* allocate memory for storing the
       points along the boundary of each
       region */

    x = (int *)G_malloc(100 * sizeof(int));
    y = (int *)G_malloc(100 * sizeof(int));

    tempfile = G_tempfile();
    tmp = fopen(tempfile, "w");

  back2:
    G_system("clear");
    fprintf(stderr, "\n\n    CHOOSE AN OPTION:\n\n");
    fprintf(stderr, "       Draw a region                     1\n");
    fprintf(stderr, "       Quit drawing regions and return");
    fprintf(stderr, "\n          to setup options menu          2\n");
    fprintf(stderr, "       Change the color for drawing      3\n\n");

    do {
	fprintf(stderr, "                             Which Number?   ");
	numtrap(1, &etmp);
	if ((meth = fabs(etmp)) > 3 || meth < 1) {
	    fprintf(stderr, "\n    Choice must between 1-3; try again");
	}
    }
    while (meth > 3 || meth < 1);

    if (meth == 2)
	return;
    if (meth == 3) {
	R_open_driver();
	change_draw();
    }
    if (meth == 1) {
	R_open_driver();
	rgn_cnt = 0;
    }

    /* ask the user to outline a region */

  back:
    G_system("clear");
    ppoint(NULL, 0, 0, -1);
    fprintf(stderr, "\n    PLEASE OUTLINE REGION # %d\n", (++rgn_cnt));
    pbutton(0);
    pts = 0;
    x0 = 0;
    y0 = 0;

    /* get the points along the boundary
       of the region as they are drawn */

    do {
	btn = 0;
	R_get_location_with_line(x0, y0, &xp, &yp, &btn);
	if (btn == 1)
	    ppoint(msc, xp, yp, 0);
	else if (btn == 2) {
	    if (!pts) {
		pbutton(1);
		R_move_abs(xp, yp);
		xstart = xp;
		ystart = yp;
	    }
	    x[pts] = xp * msc[0];
	    y[pts] = yp * msc[1];
	    ppoint(msc, xp, yp, (++pts));
	    x0 = xp;
	    y0 = yp;
	    R_cont_abs(x0, y0);
	}
	else if (btn == 3 && pts < 3) {
	    fprintf(stderr,
		    "\n\n    Please digitize more than 2 boundary points\n\n");
	}
    }
    while (btn != 3 || pts < 3);

    R_cont_abs(xstart, ystart);
    R_close_driver();
    R_open_driver();
    x[pts] = x[0];
    y[pts] = y[0];
    pts++;

    /* redisplay the menu and find out what
       to do next */
  back1:
    G_system("clear");
    fprintf(stderr, "\n\n    CHOOSE AN OPTION:\n\n");
    fprintf(stderr,
	    "       Draw another region                          1\n");
    fprintf(stderr,
	    "       Start over drawing regions                   2\n");
    fprintf(stderr,
	    "       Quit drawing and save the region map         3\n");
    fprintf(stderr,
	    "       Quit drawing and don't save the region map   4\n");
    fprintf(stderr,
	    "       Change the color for drawing                 5\n\n");
    do {
	fprintf(stderr,
		"                                        Which Number?  ");
	numtrap(1, &dtmp);
	if ((method = fabs(dtmp)) > 5 || method < 1) {
	    fprintf(stderr, "\n    Choice must between 1-5; try again");
	}
    }
    while (method > 5 || method < 1);


    /* save the region and draw another */

    if (method == 1) {
	save_rgn(reg_name, tempfile, tmp, x, y, pts, rgn_cnt, 1);
	goto back;
    }

    /* start over */

    else if (method == 2) {
	fclose(tmp);
	if (!(tmp = fopen(tempfile, "w")))
	    G_fatal_error
		("Can't open temporary file for storing region info\n");
	rgn_cnt = 0;
	R_close_driver();
	paint_map(name, name1, name2);
	goto back2;
    }

    /* save the region and exit */

    else if (method == 3)
	save_rgn(reg_name, tempfile, tmp, x, y, pts, rgn_cnt, 2);


    /* change the color for drawing */

    else if (method == 5) {
	change_draw();
	goto back1;
    }

    R_close_driver();
    G_free(x);
    G_free(y);
    unlink(tempfile);
    return;

}