[GRASS-SVN] r39821 - grass/trunk/vector/v.delaunay
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 27 07:48:17 EST 2009
Author: martinl
Date: 2009-11-27 07:48:16 -0500 (Fri, 27 Nov 2009)
New Revision: 39821
Modified:
grass/trunk/vector/v.delaunay/in_out.c
grass/trunk/vector/v.delaunay/in_out.h
grass/trunk/vector/v.delaunay/main.c
Log:
v.delaunay: OGR support (read access)
cosmetics in message output
Modified: grass/trunk/vector/v.delaunay/in_out.c
===================================================================
--- grass/trunk/vector/v.delaunay/in_out.c 2009-11-26 22:32:43 UTC (rev 39820)
+++ grass/trunk/vector/v.delaunay/in_out.c 2009-11-27 12:48:16 UTC (rev 39821)
@@ -26,7 +26,9 @@
}
double x1, y1, z1, x2, y2, z2;
+ G_message(_("Creating edges..."));
for (i = 0; i < n; i++) {
+ G_percent(i, n, 2);
u = sites_sorted[i];
e_start = e = u->entry_pt;
do {
@@ -54,6 +56,7 @@
e = NEXT(e, u);
} while (!SAME_EDGE(e, e_start));
}
+ G_percent(1, 1, 1);
}
/* Print the ring of triangles about each vertex. */
@@ -160,24 +163,33 @@
}
/* returns number of sites read */
-int read_sites(int mode3d, int complete_map, struct Map_info map_in,
- struct bound_box Box)
+int read_sites(int mode3d, int complete_map, struct Map_info* map_in,
+ struct bound_box Box, int field)
{
int nlines, line, allocated, nsites;
struct line_pnts *Points;
+ struct line_cats *Cats;
+
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
- Points = Vect_new_line_struct();
- nlines = Vect_get_num_lines(&map_in);
+ nlines = Vect_get_num_lines(map_in);
alloc_sites(nlines);
allocated = nlines;
nsites = 0;
+ G_message(_("Reading point features..."));
for (line = 1; line <= nlines; line++) {
int type;
- type = Vect_read_line(&map_in, Points, NULL, line);
+ G_percent(line, nlines, 2);
+ type = Vect_read_line(map_in, Points, Cats, line);
if (!(type & GV_POINTS))
continue;
+
+ if (Vect_cat_get(Cats, field, NULL) == 0)
+ continue;
+
if (!complete_map) {
if (!Vect_point_in_box(Points->x[0], Points->y[0], 0.0, &Box))
continue;
@@ -204,5 +216,8 @@
realloc_sites(nsites);
alloc_edges(nsites);
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+
return nsites;
}
Modified: grass/trunk/vector/v.delaunay/in_out.h
===================================================================
--- grass/trunk/vector/v.delaunay/in_out.h 2009-11-26 22:32:43 UTC (rev 39820)
+++ grass/trunk/vector/v.delaunay/in_out.h 2009-11-27 12:48:16 UTC (rev 39821)
@@ -1,8 +1,8 @@
#ifndef IN_OUT_H
#define IN_OUT_H
-int read_sites(int mode3d, int complete_map, struct Map_info map_in,
- struct bound_box Box);
+int read_sites(int mode3d, int complete_map, struct Map_info* map_in,
+ struct bound_box Box, int);
void output_edges(struct vertex *sites_sorted[], unsigned int n, int mode3d,
int Type, struct Map_info map_out);
void output_triangles(struct vertex *sites_sorted[], unsigned int n,
Modified: grass/trunk/vector/v.delaunay/main.c
===================================================================
--- grass/trunk/vector/v.delaunay/main.c 2009-11-26 22:32:43 UTC (rev 39820)
+++ grass/trunk/vector/v.delaunay/main.c 2009-11-27 12:48:16 UTC (rev 39821)
@@ -2,25 +2,26 @@
*
* MODULE: v.delaunay
*
- * AUTHOR(S): Martin Pavlovsky (Paul Kelly mentor)
+ * AUTHOR(S): Martin Pavlovsky (Google SoC 2008, Paul Kelly mentor)
*
- * PURPOSE: creates a Delaunay triangulation vector map
+ * PURPOSE: Creates a Delaunay triangulation vector map
*
- * COPYRIGHT: (C) 2008 by the GRASS Development Team
+ * COPYRIGHT: (C) 2008-2009 by the GRASS Development Team
*
- * This program is free software under the
- * GNU General Public License (>=v2).
- * Read the file COPYING that comes with GRASS
- * for details.
+ * This program is free software under the GNU General
+ * Public License (>=v2). Read the file COPYING that
+ * comes with GRASS for details.
*
**************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+
#include <grass/gis.h>
#include <grass/vector.h>
#include <grass/glocale.h>
+
#include "data_types.h"
#include "memory.h"
#include "geometry.h"
@@ -33,13 +34,12 @@
{
/* GRASS related variables */
- const char *mapset;
struct Map_info map_in, map_out;
struct Cell_head Window;
struct bound_box Box;
struct GModule *module;
struct Flag *reg_flag, *line_flag;
- struct Option *in_opt, *out_opt;
+ struct Option *in_opt, *out_opt, *field_opt;
struct line_pnts *Points;
struct line_cats *Cats;
@@ -48,9 +48,7 @@
int Type;
int complete_map;
int mode3d;
-
- /* ---------------------- */
-
+
unsigned int i;
unsigned int n;
struct edge *l_cw, *r_ccw;
@@ -60,10 +58,13 @@
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("vector"));
+ G_add_keyword(_("geometry"));
+ G_add_keyword(_("triangulation"));
module->description = _("Creates a Delaunay triangulation from an input "
"vector map containing points or centroids.");
in_opt = G_define_standard_option(G_OPT_V_INPUT);
+ field_opt = G_define_standard_option(G_OPT_V_FIELD);
out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
reg_flag = G_define_flag();
@@ -87,13 +88,9 @@
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
-
- /* open files */
- if ((mapset = G_find_vector2(in_opt->answer, "")) == NULL)
- G_fatal_error(_("Vector map <%s> not found"), in_opt->answer);
-
+
Vect_set_open_level(2);
- Vect_open_old(&map_in, in_opt->answer, mapset);
+ Vect_open_old2(&map_in, in_opt->answer, "", field_opt->answer);
/* check if we have a 3D input points map */
mode3d = Vect_is_3d(&map_in);
@@ -111,20 +108,21 @@
/* initialize working region */
G_get_window(&Window);
- G_percent(0, 100, 1);
Vect_region_box(&Window, &Box);
- n = read_sites(mode3d, complete_map, map_in, Box);
+ n = read_sites(mode3d, complete_map, &map_in, Box,
+ Vect_get_field_number(&map_in, field_opt->answer));
/* Sort. */
sites_sorted =
(struct vertex **)G_malloc((unsigned)n * sizeof(struct vertex *));
if (sites_sorted == MY_NULL)
- G_fatal_error(_("Not enough memory."));
+ G_fatal_error(_("Not enough memory"));
for (i = 0; i < n; i++)
sites_sorted[i] = sites + i;
qsort(sites_sorted, n, sizeof(struct vertex *), (void *)compare);
+ G_verbose_message(_("Removing duplicates..."));
remove_duplicates(sites_sorted, &n);
/* Triangulate. */
@@ -132,16 +130,23 @@
output_edges(sites_sorted, n, mode3d, Type, map_out);
- free((char *)sites_sorted);
+ G_free((char *)sites_sorted);
free_memory();
Vect_close(&map_in);
if (Type == GV_BOUNDARY) {
+ int verbose = G_verbose();
+ if (verbose < G_verbose_max()) {
+ G_message(_("Building topology..."));
+ G_set_verbose(0);
+ }
Vect_build_partial(&map_out, GV_BUILD_AREAS);
+ G_set_verbose(verbose);
nareas = Vect_get_num_areas(&map_out);
G_debug(3, "nareas = %d", nareas);
/* Assign centroid to each area */
+ G_message(_("Writing areas..."));
for (area = 1; area <= nareas; area++) {
double x, y, z, angle, slope;
int ret;
More information about the grass-commit
mailing list