[GRASS-SVN] r32632 - in grass/trunk/display: . d.where

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 7 20:48:59 EDT 2008


Author: glynn
Date: 2008-08-07 20:48:58 -0400 (Thu, 07 Aug 2008)
New Revision: 32632

Removed:
   grass/trunk/display/d.where/b_w_line.c
Modified:
   grass/trunk/display/Makefile
   grass/trunk/display/d.where/local_proto.h
   grass/trunk/display/d.where/main.c
   grass/trunk/display/d.where/where.c
Log:
Cannibalize d.where


Modified: grass/trunk/display/Makefile
===================================================================
--- grass/trunk/display/Makefile	2008-08-07 23:04:57 UTC (rev 32631)
+++ grass/trunk/display/Makefile	2008-08-08 00:48:58 UTC (rev 32632)
@@ -29,14 +29,15 @@
 	d.vect \
 	d.vect.chart \
 	d.thematic.area \
+	d.where \
 
+
 #	d.colors \
 #	d.extract \
 #	d.measure \
 #	d.profile \
 #	d.what.rast \
 #	d.what.vect \
-#	d.where \
 #	d.zoom \
 #	drivers
 

Deleted: grass/trunk/display/d.where/b_w_line.c
===================================================================
--- grass/trunk/display/d.where/b_w_line.c	2008-08-07 23:04:57 UTC (rev 32631)
+++ grass/trunk/display/d.where/b_w_line.c	2008-08-08 00:48:58 UTC (rev 32632)
@@ -1,41 +0,0 @@
-#include <stdlib.h>
-#include <grass/raster.h>
-
-int
-black_and_white_line(int c1, int c2, int screen_x, int screen_y,
-		     int cur_screen_x, int cur_screen_y)
-{
-    if (abs(screen_y - cur_screen_y) <= abs(screen_x - cur_screen_x)) {
-	if (screen_x > cur_screen_x)
-	    R_standard_color(c1);
-	else
-	    R_standard_color(c2);
-	R_move_abs(cur_screen_x, cur_screen_y);
-	R_cont_abs(screen_x, screen_y);
-
-	if (screen_x > cur_screen_x)
-	    R_standard_color(c2);
-	else
-	    R_standard_color(c1);
-	R_move_abs(cur_screen_x, cur_screen_y - 1);
-	R_cont_abs(screen_x, screen_y - 1);
-    }
-    else {
-	if (screen_y > cur_screen_y)
-	    R_standard_color(c1);
-	else
-	    R_standard_color(c2);
-	R_move_abs(cur_screen_x, cur_screen_y);
-	R_cont_abs(screen_x, screen_y);
-	if (screen_y > cur_screen_y)
-	    R_standard_color(c2);
-	else
-	    R_standard_color(c1);
-	R_move_abs(cur_screen_x + 1, cur_screen_y);
-	R_cont_abs(screen_x + 1, screen_y);
-    }
-
-    R_flush();
-
-    return 0;
-}

Modified: grass/trunk/display/d.where/local_proto.h
===================================================================
--- grass/trunk/display/d.where/local_proto.h	2008-08-07 23:04:57 UTC (rev 32631)
+++ grass/trunk/display/d.where/local_proto.h	2008-08-08 00:48:58 UTC (rev 32632)
@@ -1,5 +1,2 @@
-/* b_w_line.c */
-int black_and_white_line(int, int, int, int, int, int);
-
 /* where.c */
-int where_am_i(int, int, int, int, int);
+int where_am_i(char **, FILE *, int, int, int);

Modified: grass/trunk/display/d.where/main.c
===================================================================
--- grass/trunk/display/d.where/main.c	2008-08-07 23:04:57 UTC (rev 32631)
+++ grass/trunk/display/d.where/main.c	2008-08-08 00:48:58 UTC (rev 32632)
@@ -32,8 +32,10 @@
 int main(int argc, char **argv)
 {
     struct GModule *module;
-    struct Flag *once, *decimal, *latlong, *wgs84, *dcoord;
+    struct Option *coords, *file;
+    struct Flag *decimal, *latlong, *wgs84, *dcoord;
     int have_spheroid = 0;
+    FILE *fp;
 
     /* Initialize the GIS calls */
     G_gisinit(argv[0]);
@@ -42,12 +44,22 @@
     module->keywords = _("display");
     module->description =
 	_("Identifies the geographic coordinates associated with "
-	  "point locations in the active frame on the graphics monitor.");
+	  "point locations given in display coordinates.");
 
-    once = G_define_flag();
-    once->key = '1';
-    once->description = _("One mouse click only");
+    coords = G_define_option();
+    coords->key = "coordinates";
+    coords->key_desc = "x,y";
+    coords->type = TYPE_DOUBLE;
+    coords->required = NO;
+    coords->multiple = YES;
+    coords->description =
+	_("Display coordinates to convert");
 
+    file = G_define_standard_option(G_OPT_F_INPUT);
+    file->required = NO;
+    file->description =
+	_("File from which to read coordinates (\"-\" to read from stdin)");
+
     decimal = G_define_flag();
     decimal->key = 'd';
     decimal->description = _("Output lat/long in decimal degree");
@@ -140,11 +152,22 @@
 
     }
 
+    if (file->answer) {
+	if (strcmp(file->answer, "-") == 0)
+	    fp = stdin;
+	else {
+	    fp = fopen(file->answer, "r");
+	    if (!fp)
+		G_fatal_error(_("Unable to open input file <%s>"), file->answer);
+	}
+    }
+    else
+	fp = NULL;
+
     if (R_open_driver() != 0)
 	G_fatal_error(_("No graphics device selected"));
     D_setup(0);
-    where_am_i(once->answer, have_spheroid, decimal->answer, wgs84->answer,
-	       dcoord->answer);
+    where_am_i(coords->answers, fp, have_spheroid, decimal->answer, dcoord->answer);
     R_close_driver();
 
     exit(EXIT_SUCCESS);

Modified: grass/trunk/display/d.where/where.c
===================================================================
--- grass/trunk/display/d.where/where.c	2008-08-07 23:04:57 UTC (rev 32631)
+++ grass/trunk/display/d.where/where.c	2008-08-08 00:48:58 UTC (rev 32632)
@@ -1,63 +1,40 @@
-#include <unistd.h>
-#include <string.h>
+#include <stdio.h>
 #include <grass/gis.h>
+#include <grass/glocale.h>
 #include <grass/gprojects.h>
 #include <grass/display.h>
-#include <grass/raster.h>
 #include "local_proto.h"
 
-static int nlines = 4;
-static int header(int, int, int);
-static int show(char *, int, int, int);
+extern struct pj_info iproj, oproj;
 
-int where_am_i(int once, int have_spheroid, int decimal, int wgs84,
-	       int dcoord)
+int where_am_i(char **coords, FILE *fp, int have_spheroid, int decimal, int dcoord)
 {
-    char buffer[200];
     char buf1[50], buf2[50];
-    char temp[100];
-    double lat, lon;
     int screen_x, screen_y;
-    int cur_screen_x = 0, cur_screen_y = 0;
     double east, north;
-    int button;
-    int white, black;
     int projection;
-    int draw_on;
-    extern struct pj_info iproj, oproj;
 
     projection = G_projection();
-    white = D_translate_color("white");
-    black = D_translate_color("black");
 
-    screen_x = ((int)D_get_d_west() + (int)D_get_d_east()) / 2;
-    screen_y = ((int)D_get_d_north() + (int)D_get_d_south()) / 2;
-    draw_on = 0;
-
-    if (!dcoord)
-	header(once, have_spheroid, wgs84);
-
     for (;;) {
-	R_get_location_with_pointer(&screen_x, &screen_y, &button);
-	if (button == 3 && !once)
-	    return (0);
+	if (coords) {
+	    const char *x, *y;
+	    x = *coords++;
+	    if (!x)
+		return 0;
+	    y = *coords++;
+	    if (!y)
+		return 0;
+	    if (sscanf(x, "%d", &screen_x) != 1 || sscanf(y, "%d", &screen_y) != 1)
+		G_fatal_error(_("Invalid coordinates <%s,%s>"), x, y);
+	}
+	else
+	    if (fscanf(fp, "%d %d", &screen_x, &screen_y) != 2)
+		return 0;
 
 	east = D_d_to_u_col((double)screen_x);
 	north = D_d_to_u_row((double)screen_y);
 
-	if (dcoord) {
-	    fprintf(stdout, "%.1f,%.1f\n",
-		    100 * (east - D_get_u_west()) / (D_get_u_east() -
-						     D_get_u_west()),
-		    100 * (north - D_get_u_south()) / (D_get_u_north() -
-						       D_get_u_south()));
-
-	    if (once)
-		break;
-	    else
-		continue;
-	}
-
 	if (decimal) {
 	    G_format_easting(east, buf1, 0);
 	    G_format_northing(north, buf2, 0);
@@ -66,10 +43,19 @@
 	    G_format_easting(east, buf1, projection);
 	    G_format_northing(north, buf2, projection);
 	}
-	sprintf(buffer, "%18s %18s", buf1, buf2);
+	fprintf(stdout, " %s %s", buf1, buf2);
+
+	if (dcoord) {
+	    fprintf(stdout, " %.1f %.1f",
+		    100 * (east - D_get_u_west()) / (D_get_u_east() -
+						     D_get_u_west()),
+		    100 * (north - D_get_u_south()) / (D_get_u_north() -
+						       D_get_u_south()));
+	}
+
 	if (have_spheroid) {
-	    lat = north;
-	    lon = east;
+	    double lat = north;
+	    double lon = east;
 
 	    if (pj_do_proj(&lon, &lat, &iproj, &oproj) < 0)
 		G_fatal_error("Error in pj_do_proj()");
@@ -82,74 +68,11 @@
 		G_lon_format(lon, buf1);
 		G_lat_format(lat, buf2);
 	    }
-	    sprintf(temp, " %18s %18s", buf1, buf2);
-	    strcat(buffer, temp);
+	    fprintf(stdout, " %s %s", buf1, buf2);
 	}
-	if (once) {
-	    sprintf(temp, " %d", button);
-	    strcat(buffer, temp);
-	}
-	show(buffer, once, have_spheroid, wgs84);
-	if (button != 2)
-	    draw_on = 0;
 
-	if (draw_on) {
-	    black_and_white_line(black, white, screen_x, screen_y,
-				 cur_screen_x, cur_screen_y);
-	    cur_screen_x = screen_x;
-	    cur_screen_y = screen_y;
-	    R_move_abs(cur_screen_x, cur_screen_y);
-	}
-	else if (button == 2) {
-	    R_move_abs(screen_x, screen_y);
-	    cur_screen_x = screen_x;
-	    cur_screen_y = screen_y;
-	    draw_on = 1;
-	}
-	nlines++;
-	if (once)
-	    return 0;
+	fprintf(stdout, "\n");
     }
 
     return 0;
 }
-
-static int show(char *buf, int once, int have_spheroid, int wgs84)
-{
-    fprintf(stdout, "%s\n", buf);
-    if (!isatty(1))
-	fprintf(stderr, "%s\n", buf);
-
-    if (nlines >= 21) {
-	header(once, have_spheroid, wgs84);
-	nlines = 4;
-    }
-
-    return 0;
-}
-
-static int header(int once, int have_spheroid, int wgs84)
-{
-    int projection = G_projection();
-
-    if (!once) {
-	fprintf(stderr, "\nButtons:\n");
-	fprintf(stderr, "Left:   where am i\n");
-	fprintf(stderr, "Middle: draw to/from here\n");
-	fprintf(stderr, "Right:  quit this\n\n");
-    }
-    else
-	fprintf(stderr, "\nClick mouse button on desired location\n\n");
-
-    if (wgs84)
-	fprintf(stderr, "%69s\n", "WGS84 Co-ordinates");
-    if (projection == PROJECTION_LL)
-	fprintf(stderr, "%18s %18s", "LON:", "LAT:");
-    else
-	fprintf(stderr, "%18s %18s", "EAST:", "NORTH:");
-    if (have_spheroid)
-	fprintf(stderr, " %18s %18s", "LON:", "LAT:");
-    fprintf(stderr, "\n");
-
-    return 0;
-}



More information about the grass-commit mailing list