[GRASS5] Re: [5.7] remove islands and U-dangles?
Hamish
hamish_nospam at yahoo.com
Tue May 11 04:59:25 EDT 2004
On Thu, 12 Feb 2004 10:06:09 +0100
Radim Blazek <blazek at itc.it> wrote:
> On Thursday 12 February 2004 06:42, you wrote:
> > > > any chance I could try the buggy version of extract.c? I think
> > > > '-d' will do exactly what I need, and I don't care about
> > > > centroids.
> > >
> > > Go to v.extract/main.c and enable d_flag (commented),
> > > then in v.extract/extract.c in block starting at the row 69 add
> > > something which checks if area on both sides are exracted.
> >
> > I'll try, but I'm not too sure how to do "check if area on both
> > sides are exracted" yet..
>
> You have to check if both catr and catl are in num_array[] (number of
> items num_index) so you need a loop as num_array is not sorted. It is
> awful v.extract should be rewritten a bit I think, maybe
> Vect_str_to_cat_list(), Vect_array_to_cat_list(),
> Vect_cat_in_cat_list().
see also http://article.gmane.org/gmane.comp.gis.grass.user/3870
The following patch makes the -d (dissolve) function of v.extract work.
(this is against today's CVS)
It works, but probably needs some cleanup before putting in CVS..
(i.e. I've taken it as far as I can, someone else please do it)
It's faster than I thought it would be.. (for 15,000 cats)
Usage: v.extract -d in=vect1 out=vect2 type=area,boundary list=1-50000
Also, 'v.extract type=area list=1,2,3' keeps areas with missing
centroids; how do you automatically add missing centroids so you can
then get rid of the zombie areas with another 'v.extract list=1,2,3'?
These are islands within a bigger area, in the following I want to get
rid of "A2". The outer boundary is made up of multiple lines. A1 has a
centroid.
+------------+
| |
| +--+ |
| |A2| |
| +--+ + |
| A1 |
+------------+
Hamish
-------------- next part --------------
Index: main.c
===================================================================
RCS file: /home/grass/grassrepository/grass51/vector/v.extract/main.c,v
retrieving revision 1.15
diff -u -r1.15 main.c
--- main.c 15 Apr 2004 17:01:22 -0000 1.15
+++ main.c 11 May 2004 08:23:47 -0000
@@ -56,7 +56,7 @@
struct Option *inopt, *outopt, *fileopt, *newopt, *typopt, *listopt, *fieldopt;
struct Option *whereopt;
struct Flag *t_flag;
-/* struct Flag *d_flag;*/
+ struct Flag *d_flag;
struct Map_info In;
struct Map_info Out;
struct field_info *Fi;
@@ -74,11 +74,9 @@
"Selects vector objects from an existing vector map and "
"creates a new map containing only the selected objects.";
- /*
d_flag = G_define_flag();
d_flag->key = 'd';
d_flag->description = "Dissolve common boundaries (default is no) ";
- */
t_flag = G_define_flag();
t_flag->key = 't';
@@ -138,7 +136,7 @@
/* set output vector file name */
output = outopt->answer;
- /* if ( d_flag->answer ) dissolve = 1; */
+ if ( d_flag->answer ) dissolve = 1;
field = atoi ( fieldopt->answer );
Index: extract.c
===================================================================
RCS file: /home/grass/grassrepository/grass51/vector/v.extract/extract.c,v
retrieving revision 1.10
diff -u -r1.10 extract.c
--- extract.c 10 May 2004 17:08:04 -0000 1.10
+++ extract.c 11 May 2004 08:23:48 -0000
@@ -19,7 +19,7 @@
{
int cat, areal, arear, catl, catr, centroid, line;
int type;
- int i;
+ int i, j;
struct line_pnts *Points, *CPoints;
struct line_cats *Cats, *CCats;
@@ -45,9 +45,9 @@
if ( !(select_type & GV_BOUNDARY) && !(select_type & GV_AREA) ) continue;
if ( select_type & GV_AREA ) { /* get left right category */
Vect_get_line_areas ( In, line, &areal, &arear );
+
if ( areal < 0 )
areal = Vect_get_isle_area ( In, abs(areal) );
-
if ( areal > 0 ) {
centroid = Vect_get_area_centroid ( In, areal );
if ( centroid > 0 ) {
@@ -74,7 +74,15 @@
for ( i = 0 ; i < num_index ; i++) {
if ( cat == num_array[i] || catr == num_array[i] || catl == num_array[i] ) {
if ( type == GV_BOUNDARY && dissolve ) {
- /* TODO */
+ int is_left=0, is_right=0;
+
+ for (j=0; j < num_index; j++) {
+ if(catl == num_array[j])
+ is_left=1;
+ if(catr == num_array[j])
+ is_right=1;
+ }
+ if(is_left && is_right) continue;
}
/* write line */
if ( cat_new > 0 && cat >= 0 ) { /* assign the new category value */
More information about the grass-dev
mailing list