[GRASS-SVN] r70425 - grass/branches/releasebranch_7_2/vector/v.what.rast
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 24 07:37:10 PST 2017
Author: martinl
Date: 2017-01-24 07:37:10 -0800 (Tue, 24 Jan 2017)
New Revision: 70425
Modified:
grass/branches/releasebranch_7_2/vector/v.what.rast/main.c
Log:
v.what.rast: segfault with map without topology (fix #3249)
(merge r70331, r70332, r70366, r70381 from trunk)
Modified: grass/branches/releasebranch_7_2/vector/v.what.rast/main.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.what.rast/main.c 2017-01-24 15:14:07 UTC (rev 70424)
+++ grass/branches/releasebranch_7_2/vector/v.what.rast/main.c 2017-01-24 15:37:10 UTC (rev 70425)
@@ -28,7 +28,7 @@
int main(int argc, char *argv[])
{
- int i, j, nlines, type, field, cat, vtype;
+ int i, j, type, field, cat, vtype, open_level;
int fd;
/* struct Categories RCats; */ /* TODO */
@@ -124,10 +124,10 @@
Vect_region_box(&window, &box); /* T and B set to +/- PORT_DOUBLE_MAX */
/* Open vector */
- Vect_set_open_level(2);
- if (Vect_open_old2(&Map, opt.vect->answer,
- print_flag->answer ? "" : G_mapset(),
- opt.field->answer) < 0)
+ open_level = Vect_open_old2(&Map, opt.vect->answer,
+ print_flag->answer ? "" : G_mapset(),
+ opt.field->answer);
+ if (open_level < 0)
G_fatal_error(_("Unable to open vector map <%s>"), opt.vect->answer);
field = Vect_get_field_number(&Map, opt.field->answer);
@@ -192,28 +192,33 @@
vtype = Vect_option_to_types(opt.type);
/* Read vector points to cache */
- Cache_size = Vect_get_num_primitives(&Map, vtype);
- /* Note: Some space may be wasted (outside region or no category) */
-
+ if (open_level > 1) {
+ Cache_size = Vect_get_num_primitives(&Map, vtype);
+ /* Note: Some space may be wasted (outside region or no category) */
+ }
+ else {
+ Cache_size = 1000;
+ }
cache = (struct order *)G_calloc(Cache_size, sizeof(struct order));
point_cnt = outside_cnt = nocat_cnt = 0;
- nlines = Vect_get_num_lines(&Map);
-
- G_debug(1, "Reading %d vector features fom map", nlines);
-
G_important_message(_("Reading features from vector map..."));
- for (i = 1; i <= nlines; i++) {
- type = Vect_read_line(&Map, Points, Cats, i);
- G_debug(4, "line = %d type = %d", i, type);
+ Vect_set_constraint_type(&Map, vtype);
+ i = 0;
+ while (TRUE) {
+ /* register line */
+ type = Vect_read_next_line(&Map, Points, Cats);
+ if (type == -1) {
+ G_fatal_error(_("Unable to read vector map"));
+ }
+ else if (type == -2) {
+ break;
+ }
- G_percent(i, nlines, 2);
+ G_progress(++i, 1e4);
- /* check type */
- if (!(type & vtype))
- continue; /* Points or centroids only */
- G_debug(1, "line = %d type = %d", i, type);
+ G_debug(4, "line = %d type = %d", i, type);
/* check region */
if (!Vect_point_in_box(Points->x[0], Points->y[0], 0.0, &box)) {
@@ -229,6 +234,14 @@
G_debug(4, " cat = %d", cat);
+ /* Resize cache on level 1 if needed */
+ if (open_level < 2) {
+ if (point_cnt >= Cache_size) {
+ Cache_size += 1000;
+ cache = (struct order *)G_realloc(cache, Cache_size * sizeof(struct order));
+ }
+ }
+
/* Add point to cache */
row = Rast_northing_to_row(Points->y[0], &window);
col = Rast_easting_to_col(Points->x[0], &window);
@@ -245,7 +258,8 @@
cache[point_cnt].count = 1;
point_cnt++;
}
-
+ G_progress(1, 1);
+
if (!print_flag->answer) {
Vect_set_db_updated(&Map);
Vect_hist_command(&Map);
More information about the grass-commit
mailing list