Wed, Jul 3 2002
22:57:28
|
|
Request created by guest
|
|
Subject: v.digit break line command should keep information about areas
Platform: GNU/Linux/i386
grass obtained from: Trento Italy site
grass binary for platform: Compiled from Sources
Hi,
When using "break line" it will destroy the attribute/category information
of the areas to the left and to the right of the "broken line". But the act of
breaking a line can also be seen as adding a new node to the line.
I wrote this patch to mapdev/v.digit/break.c:
--%<--
--- break.c.orig 2002-07-03 14:05:50.000000000 -0300
+++ break.c 2002-07-03 16:17:21.000000000 -0300
@@ -105,6 +105,8 @@
int label;
int N1, N2;
int line1, line2;
+ int area1, area2, cat1, cat2;
+ double x1, y1, x2, y2;
if (first_time) /* change 10/90 was buggy in 3.1 */
{
@@ -115,6 +117,18 @@
Line = &(map->Line[line]);
+ /* Save information about areas around line being "broken" */
+ if ((area1 = abs(Line->left)) != 0) {
+ x1 = map->Att[map->Area[area1].att].x;
+ y1 = map->Att[map->Area[area1].att].y;
+ cat1 = map->Att[map->Area[area1].att].cat;
+ }
+ if ((area2 = abs(Line->right)) != 0) {
+ x2 = map->Att[map->Area[area2].att].x;
+ y2 = map->Att[map->Area[area2].att].y;
+ cat2 = map->Att[map->Area[area2].att].cat;
+ }
+
/* hold on to node numbers for new lines */
N1 = Line->N1;
N2 = Line->N2;
@@ -231,5 +245,31 @@
return (-1);
}
display_line (type, &NPoints, line1, map);
+
+ /* Restore attributes of areas around "broken" line */
+ if (area1 || area2) {
+ int att;
+
+ if (area1) {
+ dig_build_area_with_line(map, line1, &Garea);
+ att = dig_new_att(map, x1, y1, AREA, area1, cat1);
+ map->Area[area1].att = att;
+ map->Area[area1].alive = 1;
+ map->Line[line1].left = map->Line[line2].left = area1;
+ if (area2)
+ map->Line[line2].left = area1;
+ Vect__Rewrite_line(map, map->Line[line1].offset, AREA, &Gpoints);
+ }
+
+ if (area2) {
+ dig_build_area_with_line(map, -line1, &Garea);
+ att = dig_new_att(map, x2, y2, AREA, area2, cat2);
+ map->Area[area2].att = att;
+ map->Area[area2].alive = 1;
+ map->Line[line1].right = map->Line[line2].right = area2;
+ Vect__Rewrite_line(map, map->Line[line2].offset, AREA, &Gpoints);
+ }
+ }
+
return (0);
}
--%<--
I am not sure if it is the correct way to do it, but this patch seens to work
for the behaviour the user asked for (subdivide polygons but not miss the category
information of the unmodified polygons that touch the modified ones).
Hope this is useful.
|
|
Wed, Jul 3 2002
23:38:07
|
|
Comments added by guest
|
|
Forgive the patch, it is broken. v.support will not understand some changes,
so this patch will break the file.
|
|
Fri, Jul 5 2002
20:22:51
|
|
Comments added by guest
|
|
Here is a version of the patch that works.
--%<--
--- src/mapdev/v.digit/break.c.orig 2002-07-05 14:34:46.000000000 -0300
+++ src/mapdev/v.digit/break.c 2002-07-05 14:35:01.000000000 -0300
@@ -105,6 +105,8 @@
int label;
int N1, N2;
int line1, line2;
+ int area1, area2, cat1, cat2;
+ double x1, y1, x2, y2;
if (first_time) /* change 10/90 was buggy in 3.1 */
{
@@ -115,6 +117,18 @@
Line = &(map->Line[line]);
+ /* Save information about areas around line being "broken" */
+ if ((area1 = abs(Line->left)) != 0) {
+
x1 = map->Att[map->Area[area1].att].x;
+
y1 = map->Att[map->Area[area1].att].y;
+
cat1 = map->Att[map->Area[area1].att].cat;
+ }
+ if ((area2 = abs(Line->right)) != 0) {
+
x2 = map->Att[map->Area[area2].att].x;
+
y2 = map->Att[map->Area[area2].att].y;
+
cat2 = map->Att[map->Area[area2].att].cat;
+ }
+
/* hold on to node numbers for new lines */
N1 = Line->N1;
N2 = Line->N2;
@@ -231,5 +245,33 @@
return (-1);
}
display_line (type, &NPoints, line1, map);
+
+ /* Restore attributes of areas around "broken" line */
+ if (area1 || area2) {
+
int att;
+
+
if (area1) {
+
if ((att = map->Area[area1].att) == 0) {
+
att = dig_new_att(map, x1, y1, AREA, area1, cat1);
+
map->Area[area1].att = att;
+
}
+
map->Area[area1].alive = 1;
+
map->Line[line1].left = map->Line[line2].left = area1;
+
dig_update_att(map, att);
+
display_area(area1, map);
+
}
+
+
if (area2) {
+
if ((att = map->Area[area2].att) == 0) {
+
att = dig_new_att(map, x2, y2, AREA, area2, cat2);
+
map->Area[area2].att = att;
+
}
+
map->Area[area2].alive = 1;
+
map->Line[line1].right = map->Line[line2].right = area2;
+
dig_update_att(map, att);
+
display_area(area2, map);
+
}
+ }
+
return (0);
}
--%<--
Description of usage where this patch is useful:
o Every area has it's own category number, that is also it's
identifier in a postgres database, so arbitrary data is associated
with the area.
o It is common to subdivide, join, delete or add new areas.
When dividing an area, it is required to add new nodes to two lines,
(then digitize a line and snap nodes), but whithout this patch, when
adding the new nodes, the areas formed by the splitted line were
missing it's atributes. This is the point, "break line" with this patch
can be seen as a "add new area node" command when editing areas.
After the user runs v.digit, a program will update the database state,
remove entries for areas that don't exist in the database and create new
database entries for new areas (and create a suitable category number if
the area is unlabeled).
|
|
Mon, Aug 26 2002
14:59:50
|
|
Mail sent by bernhard
|
|
Radim checked the patch and wrote the following analysis
on the development list:
| Unfortunately it seems to me that it is not quite correct because
| original areas are restored only by
| map->Area[area1].alive = 1;
| which is not sufficient because old line must be deleted from area
| and new lines added.
|
| It doesn't crash because of
| if (!LINE_ALIVE (&(map->Line[line])))
| continue;
| in _area_display().
|
|
Mon, Aug 26 2002
22:02:52
|
|
Comments added by guest
|
|
Thanks for reviewing the patch.
The patch was more to show what the user needed. Actually, what is
being done is basically this:
o run v.digit and edit the file (with that patch)
o run a program that updates an database based on what was changed
in the vector file.
This program basically does:
+ run "v.support <vector> option=build"
+ open the vector for editing
+ for every attribute as returned by V2_area_att (or V2_line_att),
checks database entries with this same number as it's unique
identifier. If an area/line was deleted, there will be an database
entry associated with the old identifier, it must be handled (and
deleted/backuped).
+ For every new area/line it adds a new database entry, and a new
unique attribute to the area/line with the database value.
+ It also updates the cats file.
+ Closes the vector file.
+ run v.support again.
I agree that this patch is not completely correct, but it's faults is
that I don't have enough knowledge of the grass libraries (the program
that syncs the vector and the postgres datbase shouldn't need to run
v.support twice for example).
I hope this comment makes it clear what the patch does. When dividing
an vector, only the area that was divided will be removed, the areas
around will be kept; probably the user will stay with grass5.0.0pre5,
where it works, indefinitely.
|
|
Thu, Mar 9 2006
13:55:30
|
|
Area changed to grass5.0 by msieczka
|
|
Tue, Jun 19 2007
08:57:57
|
|
Status changed to resolved by hbowman
|
|
Tue, Jun 19 2007
08:57:57
|
|
Comments added by hbowman
|
|
GRASS 5's v.digit is no longer maintained, closing bug as "won't fix".
:-/
Hamish
|
|