[GRASS-SVN] r29715 -
grass/branches/releasebranch_6_2/raster/r.le/r.le.setup
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 15 21:12:47 EST 2008
Author: hamish
Date: 2008-01-15 21:12:47 -0500 (Tue, 15 Jan 2008)
New Revision: 29715
Modified:
grass/branches/releasebranch_6_2/raster/r.le/r.le.setup/sample.c
Log:
work for sample radius > 100, update site->vector points, "shape" to aspect ratio
(merge from HEAD)
Modified: grass/branches/releasebranch_6_2/raster/r.le/r.le.setup/sample.c
===================================================================
--- grass/branches/releasebranch_6_2/raster/r.le/r.le.setup/sample.c 2008-01-16 01:00:53 UTC (rev 29714)
+++ grass/branches/releasebranch_6_2/raster/r.le/r.le.setup/sample.c 2008-01-16 02:12:47 UTC (rev 29715)
@@ -22,10 +22,12 @@
#include <stdlib.h>
#include <grass/gis.h>
-#include "setup.h"
+#include <grass/Vect.h>
#include <grass/config.h>
#include <grass/raster.h>
#include <grass/display.h>
+#include <grass/glocale.h>
+#include "setup.h"
static int calc_unit_loc (double radius, int top, int bot, int left, int right,
@@ -310,11 +312,11 @@
if (!G_yes("\n radius (> 100 pixels)? ",1))
goto getradius;
}
- else {
- ratio = 1.0;
- u_w = (int)(2 * radius);
- u_l = (int)(2 * radius);
- }
+
+ ratio = 1.0;
+ u_w = (int)(2 * radius);
+ u_l = (int)(2 * radius);
+
if (fmask > 0) {
count = 0;
row_buf = G_allocate_raster_buf(CELL_TYPE);
@@ -347,7 +349,7 @@
/* get the width/length ratio */
getratio:
- fprintf(stderr, "\n Sampling unit SHAPE (#cols/#rows) expressed as real");
+ fprintf(stderr, "\n Sampling unit SHAPE (aspect ratio, #cols/#rows) expressed as real");
fprintf(stderr, " number\n (e.g., 10 cols/5 rows = 2.0) for sampling units");
fprintf(stderr, " of scale %d? ", i+1);
@@ -727,13 +729,16 @@
int *sites, double startx, int starty, int fmask,
double nx, double x, double y)
{
- char *sites_mapset, sites_file_name[GNAME_MAX], *desc, *cmd;
- FILE *sites_fp;
+ char *sites_mapset, sites_file_name[GNAME_MAX], *cmd;
+ struct Map_info Map;
struct Cell_head region;
- double east_coord, north_coord, D_u_to_a_col(), D_u_to_a_row();
+ double D_u_to_a_col(), D_u_to_a_row();
int i, j, k, cnt=0, w_w = right - left, w_l = bot - top, exp1, exp2,
dx = w_w, dy = w_l, l, t, left1 = left, top1 = top, n, tmp,
ulrow, ulcol, *row_buf, lap=0;
+ static struct line_pnts *Points;
+ struct line_cats *Cats;
+ int ltype;
/* VARIABLES:
UNITS FOR ALL DIMENSION VARIABLES IN THIS ROUTINE ARE IN PIXELS
@@ -912,26 +917,34 @@
/* for centered over sites */
else if (method==5){
- sites_mapset=G_ask_sites_old(" Enter name of site map", sites_file_name) ;
+ sites_mapset = G_ask_vector_old(" Enter name of vector points map", sites_file_name);
if (sites_mapset == NULL) {
G_system("d.frame -e");
exit(0);
}
- if ((sites_fp = G_fopen_sites_old(sites_file_name,sites_mapset)) == NULL) {
- fprintf(stderr, "\n Can't open sites file %s\n",sites_file_name);
+ Vect_open_old(&Map, sites_file_name, sites_mapset);
+/* fprintf(stderr, "\n Can't open vector points file %s\n", sites_file_name); */
- }
*sites = 0;
i = 0;
n = 0;
- while( G_get_site(sites_fp,&east_coord,&north_coord,&desc) > 0) {
- ulcol = ((int)(D_u_to_a_col(east_coord))) + 1 - u_w/2;
- ulrow = ((int)(D_u_to_a_row(north_coord))) + 1 - u_l/2;
+ Points = Vect_new_line_struct(); /* init line_pnts struct */
+ Cats = Vect_new_cats_struct();
+
+ while (1) {
+ ltype = Vect_read_next_line (&Map, Points, Cats);
+ if ( ltype == -1 ) G_fatal_error(_("Cannot read vector"));
+ if ( ltype == -2 ) break; /* EOF */
+ /* point features only. (GV_POINTS is pts AND centroids, GV_POINT is just pts) */
+ if (!(ltype & GV_POINT)) continue;
+
+ ulcol = ((int)(D_u_to_a_col(Points->x[0]))) + 1 - u_w/2;
+ ulrow = ((int)(D_u_to_a_row(Points->y[0]))) + 1 - u_l/2;
if (ulcol <= left || ulrow <= top || ulcol+u_w-1 > right || ulrow+u_l-1 > bot) {
fprintf(stderr, " No sampling unit over site %d at east=%8.1f north=%8.1f\n",
- n+1,east_coord,north_coord);
+ n+1, Points->x[0], Points->y[0]);
fprintf(stderr, " as it would extend outside the map\n");
}
@@ -952,6 +965,10 @@
G_system(cmd);
G_free (cmd);
+ Vect_close(&Map);
+ G_free(Points);
+ G_free(Cats);
+
}
return 1;
More information about the grass-commit
mailing list