[GRASS-user] v.extract -d vs. v.dissolve

Hi all!

What could be the reason for v.dissolve failing to dissolve when
v.extract -d works just fine with the exact same vector maps? Bug?

Regards, Nikos

Nikos Alexandris

What could be the reason for v.dissolve failing to dissolve when
v.extract -d works just fine with the exact same vector maps? Bug?

is there a table attached?

without specific details of command, map, and result it is rather hard to
guess.....

Hamish

On Sun, 2008-11-09 at 15:34 -0800, Hamish wrote:

Nikos Alexandris
> What could be the reason for v.dissolve failing to dissolve when
> v.extract -d works just fine with the exact same vector maps? Bug?

is there a table attached?

without specific details of command, map, and result it is rather hard to
guess.....

Hamish

Hamish,
apologies!

Here you go (working with grass-6.4.svn):

#info of vector map
v.info fgaps_shadows_singleid_patched_nik -c

Displaying column types/names for database connection of layer 1:
INTEGER|cat
INTEGER|value
CHARACTER|label
## column "value" contains just 1's, 2's, 3's, 4's and 5's

# dissolving
v.dissolve fgaps_shadows_singleid_patched_nik
out=fgaps_shadows_singleid_patched_nik_dissolved_test column=value

100%
Building topology for vector map
<fgaps_shadows_singleid_patched_nik_dissolved_test_14997>...
54377 primitives registered
629349 vertices registered
Building areas: 100%
38049 areas built
24046 isles built
Attaching islands: 100%
Attaching centroids: 100%
Topology was built
Number of nodes : 40374
Number of primitives: 54377
Number of points : 0
Number of lines : 0
Number of boundaries: 47093
Number of centroids : 7284
Number of areas : 38049
Number of isles : 24046
Number of areas without centroid : 30765
7284 features reclassed
Building topology for vector map
<fgaps_shadows_singleid_patched_nik_dissolved_test>...
54377 primitives registered
629349 vertices registered
Building areas: 100%
38049 areas built
24046 isles built
Attaching islands: 100%
Attaching centroids: 100%
Topology was built
Number of nodes : 40374
Number of primitives: 54377
Number of points : 0
Number of lines : 0
Number of boundaries: 47093
Number of centroids : 7284
Number of areas : 38049
Number of isles : 24046
Number of areas without centroid : 30765
Removing duplicate centroids...
Building topology for vector map
<fgaps_shadows_singleid_patched_nik_dissolved_test>...
54377 primitives registered
629349 vertices registered
Building areas: 100%
38049 areas built
24046 isles built
Attaching islands: 100%
Attaching centroids: 100%
Topology was built
Number of nodes : 40374
Number of primitives: 54377
Number of points : 0
Number of lines : 0
Number of boundaries: 47093
Number of centroids : 7284
Number of areas : 38049
Number of isles : 24046
Number of areas without centroid : 30765

# add table to database
v.db.addtable fgaps_shadows_singleid_patched_nik_dissolved_test

Using vector map name as table name:
fgaps_shadows_singleid_patched_nik_dissolved_test
Creating new DB connection based on default mapset settings...
Creating table with columns (cat integer)
The table <fgaps_shadows_singleid_patched_nik_dissolved_test> is now
part
of vector map <fgaps_shadows_singleid_patched_nik_dissolved_test> and
may
be deleted or overwritten by GRASS modules
Select privileges were granted on the table
Updating database...
100%
5 categories read from map
4 categories read from map don't exist in selection from table
4 records updated/inserted
Current attribute table links:
Vector map <fgaps_shadows_singleid_patched_nik_dissolved_test@nik> is
connected by:
layer <1> table <fgaps_shadows_singleid_patched_nik_dissolved_test> in
database </home/nik/grassdb/rlp_fgaps/gk2_option6/sqlite.db> through
driver <sqlite> with key <cat>
## only 4 records updated!? ##

# checking columns
v.info fgaps_shadows_singleid_patched_nik_dissolved_test -c

Displaying column types/names for database connection of layer 1:
INTEGER|cat
## why is the rest lost?

# using v.extract ## but this is probably not what I want. I need to
"dissolve" based on "value" column!
v.extract -d fgaps_shadows_singleid_patched_nik
out=fgaps_shadows_singleid_patched_nik_dissolved_test2

Building topology for vector map
<fgaps_shadows_singleid_patched_nik_dissolved_test2>...
54377 primitives registered
629349 vertices registered
Building areas: 100%
38049 areas built
24046 isles built
Attaching islands: 100%
Attaching centroids: 100%
Topology was built
Number of nodes : 40374
Number of primitives: 54377
Number of points : 0
Number of lines : 0
Number of boundaries: 47093
Number of centroids : 7284
Number of areas : 38049
Number of isles : 24046
Number of areas without centroid : 30765
v.extract complete.
Removing duplicate centroids...
Building topology for vector map
<fgaps_shadows_singleid_patched_nik_dissolved_test2>...
54377 primitives registered
629349 vertices registered
Building areas: 100%
38049 areas built
24046 isles built
Attaching islands: 100%
Attaching centroids: 100%
Topology was built
Number of nodes : 40374
Number of primitives: 54377
Number of points : 0
Number of lines : 0
Number of boundaries: 47093
Number of centroids : 7284
Number of areas : 38049
Number of isles : 24046
Number of areas without centroid : 30765

# checking columns
v.info fgaps_shadows_singleid_patched_nik_dissolved_test2 -c

Displaying column types/names for database connection of layer 1:
INTEGER|cat
INTEGER|value
CHARACTER|label

On Mon, 2008-11-10 at 00:48 +0100, Nikos Alexandris wrote:

On Sun, 2008-11-09 at 15:34 -0800, Hamish wrote:
> Nikos Alexandris
> > What could be the reason for v.dissolve failing to dissolve when
> > v.extract -d works just fine with the exact same vector maps? Bug?
>
> is there a table attached?
>

Yes.

db.tables -p

[...]
fgaps_no_shadows_singleid_patched_nik
[...]

Nikos:

What could be the reason for v.dissolve failing to dissolve when
v.extract -d works just fine with the exact same vector maps? Bug?

[map sent]

what do you mean by "failing"? topology results seem the same before and
after, ie there were no borders which needed to dissolve. (v.info -t)

GRASS> v.report fgaps_shadows_singleid_patched_nik option=area | wc -l
Displaying column types/names for database connection of layer 1:
7285

(so 7285 unique cat numbers in input map)

# dissolving
v.dissolve fgaps_shadows_singleid_patched_nik \
    out=fgaps_shadows_singleid_patched_nik_dissolved_test column=value

GRASS> v.report fgaps_shadows_singleid_patched_nik_dissolved_test op=area
cat|area
1|45302.399999782
2|257889.279999155
3|355739.519996849
4|111633.280001068

## only 4 records updated!? ##

"value" from input map has become "cat" in output map.

v.dissolve "v.reclass"es it to make the "value" integer column the key
column instead of "cat".

do you need to retain the original cat numbers?

d.erase
g.region vect=fgaps_shadows_singleid_patched_nik
d.vect fgaps_shadows_singleid_patched_nik where='value = 1' color=red type=area fcol=red
d.vect fgaps_shadows_singleid_patched_nik where='value = 2' color=yellow type=area fcol=yellow
d.vect fgaps_shadows_singleid_patched_nik where='value = 3' color=cyan type=area fcol=cyan
d.vect fgaps_shadows_singleid_patched_nik where='value = 4' color=blue type=area fcol=blue

# random colors all over the place
d.vect -c fgaps_shadows_singleid_patched_nik type=area

# random colors by value ID
d.vect -c fgaps_shadows_singleid_patched_nik_dissolved_test type=area

Hamish

On Sun, 2008-11-09 at 23:57 -0800, Hamish wrote:

Nikos:
> What could be the reason for v.dissolve failing to dissolve when
> v.extract -d works just fine with the exact same vector maps? Bug?

[map sent]

what do you mean by "failing"? topology results seem the same before and
after, ie there were no borders which needed to dissolve. (v.info -t)

GRASS> v.report fgaps_shadows_singleid_patched_nik option=area | wc -l
Displaying column types/names for database connection of layer 1:
7285

(so 7285 unique cat numbers in input map)

The reason I expect another result than just 4 big areas is that

(a) I need single unique (=separate) "fagp" polygons (but not when they
are adjacent),

(b) I have done the exact same processing (v.dissolve based on "value"
column) on another vector map (actually the same "fgap" map with some
polygons removed manually and it just works fine. I'll check the
"numbers" on the other map.

(Sorry that I didn't mention the "other example" before.)

> # dissolving
> v.dissolve fgaps_shadows_singleid_patched_nik \
> out=fgaps_shadows_singleid_patched_nik_dissolved_test column=value

GRASS> v.report fgaps_shadows_singleid_patched_nik_dissolved_test op=area
cat|area
1|45302.399999782
2|257889.279999155
3|355739.519996849
4|111633.280001068

> ## only 4 records updated!? ##

"value" from input map has become "cat" in output map.

That's fine but I need lots of cat(s) around (to catch the mices) !! :slight_smile:

v.dissolve "v.reclass"es it to make the "value" integer column the key
column instead of "cat".

do you need to retain the original cat numbers?

yep!

d.erase
g.region vect=fgaps_shadows_singleid_patched_nik
d.vect fgaps_shadows_singleid_patched_nik where='value = 1' color=red type=area fcol=red
d.vect fgaps_shadows_singleid_patched_nik where='value = 2' color=yellow type=area fcol=yellow
d.vect fgaps_shadows_singleid_patched_nik where='value = 3' color=cyan type=area fcol=cyan
d.vect fgaps_shadows_singleid_patched_nik where='value = 4' color=blue type=area fcol=blue

# random colors all over the place
d.vect -c fgaps_shadows_singleid_patched_nik type=area

# random colors by value ID
d.vect -c fgaps_shadows_singleid_patched_nik_dissolved_test type=area

Hamish

Kind regards, Nikos

On Mon, 2008-11-10 at 12:09 +0100, Nikos Alexandris wrote:

On Sun, 2008-11-09 at 23:57 -0800, Hamish wrote:
> Nikos:
> > What could be the reason for v.dissolve failing to dissolve when
> > v.extract -d works just fine with the exact same vector maps? Bug?
>
> [map sent]
>
> what do you mean by "failing"? topology results seem the same before and
> after, ie there were no borders which needed to dissolve. (v.info -t)

Hamish,

I think I misunderstood the function of v.dissolve here :frowning:

1. My map seems to be already "dissolved", that is: there are no
adjacent polygons carrying the same "value"

2. When I dissolve the already "dissolved" map based on the "values"
column, the module reclassifies and brings the "unique" "values" in a
cat column (right?)

3. With db.select I see only 4 different categories. That's right. I
though that I now have only 4 BIG areas (something like the multipart
shapefile concept). This is where I got confused - My bad... !

I guess it's ok to use my already dissolved map or just add a column and
populate unique id's for each of the polygons.

Sorry for the un-necessary time-crunching.

Regards, Nikos

Nikos:

I think I misunderstood the function of v.dissolve here :frowning:

1. My map seems to be already "dissolved", that is: there are no
adjacent polygons carrying the same "value"

ok, so v.dissolve is not needed

2. When I dissolve the already "dissolved" map based on the "values"
column, the module reclassifies and brings the "unique" "values" in a
cat column (right?)

Yes, essentially "v.reclass column=" is all that is run then.
I just updated the v.reclass help page to try and make it a bit clearer
about what happens then, see NOTES and EXAMPLE 2:
  https://trac.osgeo.org/grass/changeset/34237

I guess it's ok to use my already dissolved map or just add a column and
populate unique id's for each of the polygons.

ok, but if things were dissolved you wouldn't be able to do that and keep
it in sync with the original cat numbers.

say you have two touching polygons cat 1001 and 1002. Both are owned by
"Farmer John" and you dissolve by owner string column. The new polygon
covering both farms can not keep cat 1001 or 1002, it needs a new unique
cat value. And the attribute attached to that cat value will be all farms
owned by John.

Hamish

On Tue, 2008-11-11 at 00:37 -0800, Hamish wrote:

Nikos:
> I think I misunderstood the function of v.dissolve here :frowning:
>
> 1. My map seems to be already "dissolved", that is: there are no
> adjacent polygons carrying the same "value"

ok, so v.dissolve is not needed

> 2. When I dissolve the already "dissolved" map based on the "values"
> column, the module reclassifies and brings the "unique" "values" in a
> cat column (right?)

Yes, essentially "v.reclass column=" is all that is run then.
I just updated the v.reclass help page to try and make it a bit clearer
about what happens then, see NOTES and EXAMPLE 2:
  https://trac.osgeo.org/grass/changeset/34237

> I guess it's ok to use my already dissolved map or just add a column and
> populate unique id's for each of the polygons.

ok, but if things were dissolved you wouldn't be able to do that and keep
it in sync with the original cat numbers.

say you have two touching polygons cat 1001 and 1002. Both are owned by
"Farmer John" and you dissolve by owner string column. The new polygon
covering both farms can not keep cat 1001 or 1002, it needs a new unique
cat value. And the attribute attached to that cat value will be all farms
owned by John.

Hamish

Thanks for the extra explanations.

Regards, Nikos