[GRASS-dev] [GRASS GIS] #3030: v. generalize fails to generalize polygons in a random manner

#3030: v. generalize fails to generalize polygons in a random manner
-------------------------+-------------------------
Reporter: dido | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Keywords: | CPU: Unspecified
Platform: Unspecified |
-------------------------+-------------------------
Trying to generalize Greece shoreline + landmass, polygons fishnet'ed with
cell size of 5000 m. Random polygons are not being generalized while they
should be. If fishnet is made bigger (e.g 50 km cell size), then more non-
generalized polygons are visible.

Input is topologically error-free (no overlaps or gaps in input data).
v.generalize output is as follows:

v.generalize --overwrite input=c100_sea_dis_fish@Greece_UTM
output=c100_sea_G120 method=douglas threshold=120
WARNING: Vector map <c100_sea_G120> already exists and will be overwritten
Copying features...
Building topology for vector map <c100_sea_G120@Greece_UTM>...
Registering primitives...
105726 primitives registered
832947 vertices registered
Building areas...
36099 areas built
2921 isles built
Attaching islands...
Attaching centroids...
Number of nodes: 36449
Number of primitives: 105726
Number of points: 0
Number of lines: 0
Number of boundaries: 69627
Number of centroids: 36099
Number of areas: 36099
Number of isles: 2921
-----------------------------------------------------
Generalization (douglas)...
Using threshold: 120 meters
WARNING: 1953 boundaries were not modified because modification would
damage topology
WARNING: 1951 lines/boundaries were not modified due to over-
simplification
-----------------------------------------------------
Building topology for vector map <c100_sea_G120@Greece_UTM>...
Registering primitives...
105726 primitives registered
323843 vertices registered
Building areas...
36099 areas built
2921 isles built
Attaching islands...
Attaching centroids...
Number of nodes: 36449
Number of primitives: 105726
Number of points: 0
Number of lines: 0
Number of boundaries: 69627
Number of centroids: 36099
Number of areas: 36099
Number of isles: 2921
-----------------------------------------------------
v.generalize complete. Number of vertices for selected features reduced
from 796848 to 287744 (36% remaining)
(Mon May 09 22:54:11 2016) Command finished (1 min 42 sec)

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
--------------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: Unspecified | Platform: MSWindows 7
--------------------------+--------------------------------------
Changes (by dido):

* keywords: => v.generalize fails 7.0.4
* platform: Unspecified => MSWindows 7

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
--------------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: Unspecified | Platform: MSWindows 7
--------------------------+--------------------------------------
Changes (by dido):

* Attachment "Clipboard01.jpg" added.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
--------------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: Unspecified | Platform: MSWindows 7
--------------------------+--------------------------------------
Changes (by dido):

* Attachment "Clipboard02.jpg" added.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
--------------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: Unspecified | Platform: MSWindows 7
--------------------------+--------------------------------------
Changes (by dido):

* Attachment "Clipboard03.jpg" added.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
--------------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: Unspecified | Platform: MSWindows 7
--------------------------+--------------------------------------

Comment (by dido):

Added attachments with generalized data over the original data, where the
non-generalized polygons are well-visible.

Dataset can be provided upon request. GRASS version is 7.0.4 (missing in
the list). How can I modify the description -- looks ugly after I pasted
the GRASS output :slight_smile:

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
--------------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Default | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: Unspecified | Platform: MSWindows 7
--------------------------+--------------------------------------
Changes (by dido):

* cc: dido (added)

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.3
Resolution: | Keywords: v.generalize fails 7.0.4
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------------------
Changes (by dido):

* component: Default => Vector
* cpu: Unspecified => x86-64

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.3
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------
Changes (by neteler):

* keywords: v.generalize fails 7.0.4 => v.generalize

Old description:

Trying to generalize Greece shoreline + landmass, polygons fishnet'ed
with cell size of 5000 m. Random polygons are not being generalized while
they should be. If fishnet is made bigger (e.g 50 km cell size), then
more non-generalized polygons are visible.

Input is topologically error-free (no overlaps or gaps in input data).
v.generalize output is as follows:

v.generalize --overwrite input=c100_sea_dis_fish@Greece_UTM
output=c100_sea_G120 method=douglas threshold=120
WARNING: Vector map <c100_sea_G120> already exists and will be
overwritten
Copying features...
Building topology for vector map <c100_sea_G120@Greece_UTM>...
Registering primitives...
105726 primitives registered
832947 vertices registered
Building areas...
36099 areas built
2921 isles built
Attaching islands...
Attaching centroids...
Number of nodes: 36449
Number of primitives: 105726
Number of points: 0
Number of lines: 0
Number of boundaries: 69627
Number of centroids: 36099
Number of areas: 36099
Number of isles: 2921
-----------------------------------------------------
Generalization (douglas)...
Using threshold: 120 meters
WARNING: 1953 boundaries were not modified because modification would
damage topology
WARNING: 1951 lines/boundaries were not modified due to over-
simplification
-----------------------------------------------------
Building topology for vector map <c100_sea_G120@Greece_UTM>...
Registering primitives...
105726 primitives registered
323843 vertices registered
Building areas...
36099 areas built
2921 isles built
Attaching islands...
Attaching centroids...
Number of nodes: 36449
Number of primitives: 105726
Number of points: 0
Number of lines: 0
Number of boundaries: 69627
Number of centroids: 36099
Number of areas: 36099
Number of isles: 2921
-----------------------------------------------------
v.generalize complete. Number of vertices for selected features reduced
from 796848 to 287744 (36% remaining)
(Mon May 09 22:54:11 2016) Command finished (1 min 42 sec)

New description:

Trying to generalize Greece shoreline + landmass, polygons fishnet'ed with
cell size of 5000 m. Random polygons are not being generalized while they
should be. If fishnet is made bigger (e.g 50 km cell size), then more non-
generalized polygons are visible.

Input is topologically error-free (no overlaps or gaps in input data).
v.generalize output is as follows:

{{{
v.generalize --overwrite input=c100_sea_dis_fish@Greece_UTM
output=c100_sea_G120 method=douglas threshold=120
WARNING: Vector map <c100_sea_G120> already exists and will be overwritten
Copying features...
Building topology for vector map <c100_sea_G120@Greece_UTM>...
Registering primitives...
105726 primitives registered
832947 vertices registered
Building areas...
36099 areas built
2921 isles built
Attaching islands...
Attaching centroids...
Number of nodes: 36449
Number of primitives: 105726
Number of points: 0
Number of lines: 0
Number of boundaries: 69627
Number of centroids: 36099
Number of areas: 36099
Number of isles: 2921
-----------------------------------------------------
Generalization (douglas)...
Using threshold: 120 meters
WARNING: 1953 boundaries were not modified because modification would
damage topology
WARNING: 1951 lines/boundaries were not modified due to over-
simplification
-----------------------------------------------------
Building topology for vector map <c100_sea_G120@Greece_UTM>...
Registering primitives...
105726 primitives registered
323843 vertices registered
Building areas...
36099 areas built
2921 isles built
Attaching islands...
Attaching centroids...
Number of nodes: 36449
Number of primitives: 105726
Number of points: 0
Number of lines: 0
Number of boundaries: 69627
Number of centroids: 36099
Number of areas: 36099
Number of isles: 2921
-----------------------------------------------------
v.generalize complete. Number of vertices for selected features reduced
from 796848 to 287744 (36% remaining)
(Mon May 09 22:54:11 2016) Command finished (1 min 42 sec)
}}}

--

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------
Changes (by neteler):

* version: 7.0.3 => 7.0.4

Comment:

Replying to [comment:2 dido]:
> Added attachments with generalized data over the original data, where
the non-generalized polygons are well-visible.
>
> Dataset can be provided upon request. GRASS version is 7.0.4 (missing in
the list).

Thanks for the hint, added to the list.

> How can I modify the description -- looks ugly after I pasted the GRASS
output :slight_smile:

You need to encapsulate code in triple "{" ... "}" chars as per
WikiFormatting. Updated as well.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------

Comment (by mmetz):

Replying to [comment:2 dido]:
> Added attachments with generalized data over the original data, where
the non-generalized polygons are well-visible.

Area boundaries are not generalized if the modification would damage
topology or if the boundaries would be over-generalized (zero-length
boundaries). In your output, you see

{{{
Generalization (douglas)...
Using threshold: 120 meters
WARNING: 1953 boundaries were not modified because modification would
damage topology
WARNING: 1951 lines/boundaries were not modified due to over-
simplification
}}}

That means the not generalized boundaries are not random, instead their
generalization would cause errors, they should not be generalized and they
are copied unmodified to the output. Try a smaller threshold or stepwise
increase the threshold using the output of the previous simplification as
input for the next simplification.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------

Comment (by dido):

Hi,

the reason why non-generalized polygons appear in the output is certainly
clear. My point is that none of these polygons will be damaged due to
generalization over-simplification, so I suspect a v.generalize algorithm
problem here.

As an example find attached 4 pairs of shapefiles that produce non-
simplified polygons.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------
Changes (by dido):

* Attachment "v_generalize_test_polygons.zip" added.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------

Comment (by mmetz):

Replying to [comment:8 dido]:
> Hi,
>
> the reason why non-generalized polygons appear in the output is
certainly clear. My point is that none of these polygons will be damaged
due to generalization over-simplification, so I suspect a v.generalize
algorithm problem here.
>
> As an example find attached 4 pairs of shapefiles that produce non-
simplified polygons.

I modified v.generalize a bit in my local copy to write out those modified
boundaries that would damage topology. In each of your test cases.
v.generalize is correct in not generalizing these boundaries. They would
collapse to a point, intersect with themselves, intersect with another
boundary, or produce a zero-size area. See screenshots in attached
topo_errors.zip.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------
Changes (by mmetz):

* Attachment "topo_errors.zip" added.

topological errors for v_generalize_test_polygons.zip

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------

Comment (by dido):

OK, I get what's breaking up generalization.

Talking about test1.png - it's a piece of polygon boundary that's several
hundred meters in length, unfortunately causing a self-intersection. Why
v.generalize discards the whole polygon side that's several kilometers
long but not the problematic sector only?

Actually in my first tryout the whole area was not fishnet'ed to 5000x5000
m cells so small problematic sectors resulted to tens and hundreds of
kilometers of shoreline being not generalized at all, making the tool
completely unpredictable in the output.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:10&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------

Comment (by mmetz):

Replying to [comment:10 dido]:
> OK, I get what's breaking up generalization.
>
> Talking about test1.png - it's a piece of polygon boundary that's
several hundred meters in length, unfortunately causing a self-
intersection. Why v.generalize discards the whole polygon side that's
several kilometers long but not the problematic sector only?

Because implementing such a feature would slow down v.generalize
considerably, it is already rather slow for complex vectors. Splicing in
an original part of the boundary into the modified version could also
cause quite a few other problems (no common vertex to start with), and
topological correctness is not guaranteed. Note that boundaries and
polygons are not the same.
>
> Actually in my first tryout the whole area was not fishnet'ed to
5000x5000 m cells so small problematic sectors resulted to tens and
hundreds of kilometers of shoreline being not generalized at all, making
the tool completely unpredictable in the output.

As I suggested previously, try stepwise generalization, starting with a
small threshold, then increasing the threshold and using the output of the
previous run as input for the next run. In your case, a threshold of 120
seems rather large considering the vertex density of the boundaries.

I suggest to close the ticket as invalid because v.generalize correctly
discards boundary modifications that would result in errors.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/3030#comment:11&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
---------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
---------------------+--------------------------

Comment (by dido):

OK, I will close the issue due to the fact that an algo rework of
v.generalize not to leave too long non-generalized boundaries behind will
be too costly to be implemented.

Still this particular use-case needs a good explanation in the
v.generalize manual. I could not find any clue that the generalize
algorithm will simply stop and retain the boundary untouched IF any
topology damage occurs during processing. The good workarounds must also
find a way to the manual -- to slice-down the input adequately, then to
apply v.generalize and v.dissolve, or to apply multiple v.generalize steps
with increasing distance.

Regards,
Dido

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
----------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: wontfix | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
----------------------+--------------------------
Changes (by dido):

* status: new => closed
* resolution: => wontfix

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3030#comment:13&gt;
GRASS GIS <https://grass.osgeo.org>

#3030: v. generalize fails to generalize polygons in a random manner
----------------------+--------------------------
  Reporter: dido | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.0.5
Component: Vector | Version: 7.0.4
Resolution: wontfix | Keywords: v.generalize
       CPU: x86-64 | Platform: MSWindows 7
----------------------+--------------------------

Comment (by neteler):

Replying to [comment:12 dido]:
> Still this particular use-case needs a good explanation in the
v.generalize manual. I could not find any clue that the generalize
algorithm will simply stop and retain the boundary untouched IF any
topology damage occurs during processing. The good workarounds must also
find a way to the manual -- to slice-down the input adequately, then to
apply v.generalize and v.dissolve, or to apply multiple v.generalize steps
with increasing distance.

Please consider to write a few sentences for the manual page (post here,
I'll merge it in).

Thanks!

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/3030#comment:14&gt;
GRASS GIS <https://grass.osgeo.org>