From 9f09469aefc538a2196a7d54c03d581824e8df01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hern=C3=A1n=20De=20Angelis?=
<51515911+dhdeangelis@users.noreply.github.com>
Date: Fri, 22 Nov 2024 14:10:59 +0100
Subject: [PATCH 1/8] docs: v.net.salesman.html fix manual typos (#4737)
---
vector/v.net.salesman/v.net.salesman.html | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/vector/v.net.salesman/v.net.salesman.html b/vector/v.net.salesman/v.net.salesman.html
index 0f29c69e857..00153281daf 100644
--- a/vector/v.net.salesman/v.net.salesman.html
+++ b/vector/v.net.salesman/v.net.salesman.html
@@ -3,7 +3,7 @@
DESCRIPTION
v.net.salesman calculates the optimal route to visit nodes on a
vector network.
-Costs may be either line lengths, or attributes saved in a database
+
Costs may be either line lengths or attributes saved in a database
table. These attribute values are taken as costs of whole segments, not
as costs to traverse a length unit (e.g. meter) of the segment.
For example, if the speed limit is 100 km / h, the cost to traverse a
@@ -14,16 +14,16 @@
DESCRIPTION
Supported are cost assignments for arcs,
and also different costs for both directions of a vector line.
For areas, costs will be calculated along boundary lines.
+
The input vector needs to be prepared with v.net operation=connect
in order to connect points representing center nodes to the network.
Points specified by category must be exactly on network nodes, and the
input vector map needs to be prepared with v.net operation=connect.
-
Application of flag -t enables a turntable support.
-This flag requires additional parameters turn_layer and turn_cat_layer
-that are otherwise ignored.
- The turntable allows
+
The flag -t enables turntable support.
+This flag requires additional parameters, turn_layer and turn_cat_layer,
+that are otherwise ignored. The turntable allows
to model e.g. traffic code, where some turns may be prohibited.
This means that the input layer is expanded by
turntable with costs of every possible turn on any possible node
@@ -161,7 +161,7 @@
AUTHORS
TURNS SUPPORT
-The turns support was implemnented as part of GRASS GIS turns cost project
+The turns support was implemented as part of GRASS GIS turns cost project
at Czech Technical University in Prague, Czech Republic.
Eliska Kyzlikova, Stepan Turek, Lukas Bocan and Viera Bejdova participated
in the project.
From c2fb1181383f7452b01e6cd3e315ce4c75113386 Mon Sep 17 00:00:00 2001
From: Markus Metz <33666869+metzm@users.noreply.github.com>
Date: Fri, 22 Nov 2024 21:35:47 +0100
Subject: [PATCH 2/8] r.to.vect: new flag to re-center centroids (#4690)
* r.to.vect: new flag to re-center centroids
---
raster/r.to.vect/areas_io.c | 19 +++++++++++++++++++
raster/r.to.vect/global.h | 3 ++-
raster/r.to.vect/main.c | 15 +++++++++++++--
raster/r.to.vect/r.to.vect.html | 5 +++++
4 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/raster/r.to.vect/areas_io.c b/raster/r.to.vect/areas_io.c
index 6d9cfd10e84..eae104e3339 100644
--- a/raster/r.to.vect/areas_io.c
+++ b/raster/r.to.vect/areas_io.c
@@ -290,6 +290,10 @@ int write_area(
catNum = 1;
+ if (centroid_flag) {
+ Vect_build_partial(&Map, GV_BUILD_ATTACH_ISLES);
+ }
+
G_important_message(_("Writing areas..."));
for (i = 0, p = a_list; i < n_areas; i++, p++) {
G_percent(i, n_areas, 3);
@@ -327,6 +331,21 @@ int write_area(
break;
}
+ if (centroid_flag) {
+ int area, ret;
+
+ area = Vect_find_area(&Map, x, y);
+ if (area == 0) {
+ G_warning(_("No area for centroid %d"), i);
+ }
+ else {
+ ret = Vect_get_point_in_area(&Map, area, &x, &y);
+ if (ret < 0) {
+ G_warning(_("Unable to calculate area centroid"));
+ }
+ }
+ }
+
Vect_reset_line(points);
Vect_append_point(points, x, y, 0.0);
diff --git a/raster/r.to.vect/global.h b/raster/r.to.vect/global.h
index 7b0084153bb..81f748e67e5 100644
--- a/raster/r.to.vect/global.h
+++ b/raster/r.to.vect/global.h
@@ -48,7 +48,8 @@ extern int n_alloced_ptrs;
extern int
smooth_flag; /* this is 0 for no smoothing, 1 for smoothing of lines */
-extern int value_flag; /* use raster values as categories */
+extern int value_flag; /* use raster values as categories */
+extern int centroid_flag; /* re-center centroids */
extern struct Categories RastCats;
extern int has_cats; /* Category labels available */
diff --git a/raster/r.to.vect/main.c b/raster/r.to.vect/main.c
index b8fea5678a3..da89c9a0c08 100644
--- a/raster/r.to.vect/main.c
+++ b/raster/r.to.vect/main.c
@@ -48,8 +48,10 @@ int row_length, row_count, n_rows;
int total_areas;
int n_alloced_ptrs;
-int smooth_flag; /* this is 0 for no smoothing, 1 for smoothing of lines */
-int value_flag; /* use raster values as categories */
+int smooth_flag; /* this is 0 for no smoothing, 1 for smoothing of lines */
+int value_flag; /* use raster values as categories */
+int centroid_flag; /* re-center centroids */
+
struct Categories RastCats;
int has_cats; /* Category labels available */
struct field_info *Fi;
@@ -66,6 +68,7 @@ int main(int argc, char *argv[])
struct GModule *module;
struct Option *in_opt, *out_opt, *feature_opt, *column_name;
struct Flag *smooth_flg, *value_flg, *z_flg, *no_topol, *notab_flg;
+ struct Flag *centroid_flg;
int feature, notab_flag;
G_gisinit(argv[0]);
@@ -115,6 +118,13 @@ int main(int argc, char *argv[])
no_topol->label = _("Do not build vector topology");
no_topol->description = _("Recommended for massive point conversion");
+ centroid_flg = G_define_flag();
+ centroid_flg->key = 'c';
+ centroid_flg->label =
+ _("Move centroids to more central locations within areas");
+ centroid_flg->description = _("Default: centroids are located anywhere in "
+ "areas, often close to boundaries");
+
notab_flg = G_define_standard_flag(G_FLG_V_TABLE);
if (G_parser(argc, argv))
@@ -123,6 +133,7 @@ int main(int argc, char *argv[])
feature = Vect_option_to_types(feature_opt);
smooth_flag = (smooth_flg->answer) ? SMOOTH : NO_SMOOTH;
value_flag = value_flg->answer;
+ centroid_flag = centroid_flg->answer;
notab_flag = notab_flg->answer;
if (z_flg->answer && (feature != GV_POINT))
diff --git a/raster/r.to.vect/r.to.vect.html b/raster/r.to.vect/r.to.vect.html
index 0bf0b21dfe2..363b1444182 100644
--- a/raster/r.to.vect/r.to.vect.html
+++ b/raster/r.to.vect/r.to.vect.html
@@ -57,6 +57,11 @@ Area conversion
input file. If the raster map contains other data (i.e., line edges,
or point data) the output may be wrong.
+
+By default, area centroids are often located close to boundaries and not
+in the middle of an area. Centroids can be more centrally located with
+the -c flag.
+
EXAMPLES
The examples are based on the North Carolina sample dataset:
From a58e17817a44d09f5bb1a0bf462bf8a2ab6ed115 Mon Sep 17 00:00:00 2001
From: Markus Neteler
Date: Sat, 23 Nov 2024 01:51:16 +0100
Subject: [PATCH 3/8] man: fix KeyError: 'MDDIR' in man/build_md.py (#4739)
At time the GRASS GIS main compilation with addons with `cron_grass_preview_build_binaries.sh` is broken:
https://grass.osgeo.org/grass85/binary/linux/snapshot/build.log.txt
```
...
Parsing ... SUCCESS
Parsing ... FAILED
Parsing ... FAILED
Parsing ... FAILED
Parsing ... FAILED
+ cp /home/neteler/.grass8/addons/modules.xml /var/www/code_and_data/addons/grass8/modules.xml
+ export ARCH
+ export ARCH_DISTDIR=/home/neteler/src//main/dist.x86_64-pc-linux-gnu
+ export GISBASE=/home/neteler/src//main/dist.x86_64-pc-linux-gnu
+ export VERSION_NUMBER=8.5
+ python3 /home/neteler/src//main/man/build_keywords.py /var/www/code_and_data/grass85/manuals/ /var/www/code_and_data/grass85/manuals/addons/
Traceback (most recent call last):
File "/home/neteler/src//main/man/build_keywords.py", line 202, in
build_keywords("md")
File "/home/neteler/src//main/man/build_keywords.py", line 68, in build_keywords
from build_md import (
File "/home/neteler/src/main/man/build_md.py", line 264, in
man_dir = os.path.join(os.environ["MDDIR"], "source")
File "/usr/lib/python3.9/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'MDDIR'
```
This PR attemps to fix this bug (inspired by `man/build_html.py`). Tested on grass.osgeo.org (without log file).
Co-authored-by: Martin Landa
---
man/build_md.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/man/build_md.py b/man/build_md.py
index 4976c8f6364..0aae069edef 100644
--- a/man/build_md.py
+++ b/man/build_md.py
@@ -261,6 +261,6 @@ def get_desc(cmd):
############################################################################
-man_dir = os.path.join(os.environ["MDDIR"], "source")
+man_dir = os.path.join(os.environ["ARCH_DISTDIR"], "docs", "mkdocs", "source")
############################################################################
From 29bb77b6a407d562e40b7b1c0934146147988c61 Mon Sep 17 00:00:00 2001
From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com>
Date: Fri, 22 Nov 2024 20:48:44 -0500
Subject: [PATCH 4/8] r.watershed: Fix Resource Leak issue (#4687)
* Fix Resource Leak issue
* G_free()
---
raster/r.watershed/ram/do_cum.c | 3 +++
raster/r.watershed/seg/do_cum.c | 2 ++
2 files changed, 5 insertions(+)
diff --git a/raster/r.watershed/ram/do_cum.c b/raster/r.watershed/ram/do_cum.c
index c882b82bb46..0bebc9dee46 100644
--- a/raster/r.watershed/ram/do_cum.c
+++ b/raster/r.watershed/ram/do_cum.c
@@ -218,6 +218,8 @@ int do_cum(void)
}
}
G_free(astar_pts);
+ G_free(contour);
+ G_free(dist_to_nbr);
return 0;
}
@@ -632,6 +634,7 @@ int do_cum_mfd(void)
G_free(dist_to_nbr);
G_free(weight);
+ G_free(contour);
return 0;
}
diff --git a/raster/r.watershed/seg/do_cum.c b/raster/r.watershed/seg/do_cum.c
index bd5bbebbed9..f7918ecdb5c 100644
--- a/raster/r.watershed/seg/do_cum.c
+++ b/raster/r.watershed/seg/do_cum.c
@@ -232,6 +232,8 @@ int do_cum(void)
G_percent(do_points, do_points, 1); /* finish it */
seg_close(&astar_pts);
+ G_free(dist_to_nbr);
+ G_free(contour);
return 0;
}
From 6acffcb86e76b354ea8a3118d506fc45182ce67a Mon Sep 17 00:00:00 2001
From: Mohan Yelugoti
Date: Fri, 22 Nov 2024 20:55:31 -0500
Subject: [PATCH 5/8] lib/vector/Vlib: Fix out-of-scope memory access (#4667)
A local array was used to store column name and column
type for each column, and a pointer to this local array
was stored and accessed outside its scope, which can cause
undefined behavior.
To avoid this, use memory from heap to store this information
so that it's accessible outside where its defined and free
this memory at the end to avoid memory leaks.
This was found using cppcheck tool.
Signed-off-by: Mohan Yelugoti
---
lib/vector/Vlib/dbcolumns.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/lib/vector/Vlib/dbcolumns.c b/lib/vector/Vlib/dbcolumns.c
index e3cf915a9ec..f0c6f5bc514 100644
--- a/lib/vector/Vlib/dbcolumns.c
+++ b/lib/vector/Vlib/dbcolumns.c
@@ -154,7 +154,7 @@ const char *Vect_get_column_names_types(struct Map_info *Map, int field)
dbHandle handle;
dbString table_name;
dbTable *table;
- const char **col_type_names;
+ char **col_type_names;
char *list;
num_dblinks = Vect_get_num_dblinks(Map);
@@ -180,16 +180,21 @@ const char *Vect_get_column_names_types(struct Map_info *Map, int field)
ncols = db_get_table_number_of_columns(table);
col_type_names = G_malloc(ncols * sizeof(char *));
for (col = 0; col < ncols; col++) {
- char buf[256];
+ col_type_names[col] = (char *)G_calloc(256, sizeof(char));
- sprintf(buf, "%s(%s)",
+ sprintf(col_type_names[col], "%s(%s)",
db_get_column_name(db_get_table_column(table, col)),
db_sqltype_name(
db_get_column_sqltype(db_get_table_column(table, col))));
- col_type_names[col] = buf;
}
- if ((list = G_str_concat(col_type_names, ncols, ",", BUFF_MAX)) == NULL)
+
+ if ((list = G_str_concat((const char **)col_type_names, ncols, ",",
+ BUFF_MAX)) == NULL)
list = G_store("");
+
+ for (col = 0; col < ncols; col++) {
+ G_free(col_type_names[col]);
+ }
G_free(col_type_names);
G_debug(3, "%s", list);
From b2c7fcef322f44c48b84da44c1a4f48b6e567b99 Mon Sep 17 00:00:00 2001
From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com>
Date: Fri, 22 Nov 2024 20:57:17 -0500
Subject: [PATCH 6/8] v.in.ascii: Fix Resource Leak issue in points.c (#4729)
---
vector/v.in.ascii/points.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/vector/v.in.ascii/points.c b/vector/v.in.ascii/points.c
index 0fd1899c2e2..ab1720f78d7 100644
--- a/vector/v.in.ascii/points.c
+++ b/vector/v.in.ascii/points.c
@@ -494,6 +494,9 @@ int points_to_bin(FILE *ascii, int rowlen, struct Map_info *Map,
G_free_tokens(tokens);
}
G_percent(nrows, nrows, 2);
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+ G_free(buf);
return 0;
}
From 08ce5bf4de4260cfe7c31304de4704fa563754fe Mon Sep 17 00:00:00 2001
From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com>
Date: Fri, 22 Nov 2024 22:36:07 -0500
Subject: [PATCH 7/8] v.univar: Fix Resource Leak issue in main.c (#4730)
---
vector/v.univar/main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/vector/v.univar/main.c b/vector/v.univar/main.c
index 85217498035..5bfa2b672f8 100644
--- a/vector/v.univar/main.c
+++ b/vector/v.univar/main.c
@@ -358,6 +358,8 @@ void select_from_geometry(void)
G_debug(3, "i=%d j=%d sum = %f val=%f", i, j, sum, val);
}
}
+ Vect_destroy_line_struct(jPoints);
+ Vect_destroy_line_struct(iPoints);
}
void select_from_database(void)
From b4e4cb0fe949881199758548a3e912a7b63a966f Mon Sep 17 00:00:00 2001
From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com>
Date: Fri, 22 Nov 2024 22:36:41 -0500
Subject: [PATCH 8/8] v.net: Fix Resource Leak issue in arcs.c (#4735)
---
vector/v.net/arcs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/vector/v.net/arcs.c b/vector/v.net/arcs.c
index 6d18f760bfd..20554fc19f9 100644
--- a/vector/v.net/arcs.c
+++ b/vector/v.net/arcs.c
@@ -68,6 +68,7 @@ int create_arcs(FILE *file, struct Map_info *Pnts, struct Map_info *Out,
Vect_destroy_line_struct(points);
Vect_destroy_cats_struct(cats);
+ Vect_destroy_line_struct(points2);
return narcs;
}