1

I am try to smooth data obtained by vectorization of a raster image by applying a series of filters in GRASS GIS. Once of steps involves using the Douglas-Peucker filter. However, I need to apply it only to selected objects in a vector layer, specifically "big" ones. The notion of size if not defined fully yet, it may be number of nodes, areas covered by the way, length of the way.

I cannot figure out how to specify this in GRASS, neither in command-line or GUI. Reading the manual page for v.generalize gives me an impression that where <sql_syntax> is my best option for adding such a condition. However, I cannot find a good example for it.

I use SQLite as a backend, if that is important.

  • I believe that you cannot apply smoothing to a subset of a line vector, since it will often create topography errors. The where="<sql>" works only on area vectors. – Micha Apr 19 at 11:36
  • @Micha That's fine for me — I actually have areas in mind for this goal. So far I found that I should be able to run v.db.addcolumn, then v.to.db option=perimeter columns=wayperimeter to add a column with e.g. perimeter data. I wonder if I then can use v.generalize where='wayperimeter > 100' or similar to achieve what I want. – Grigory Rechistov Apr 19 at 11:57
1

Here's an example, using the North Carolina basic mapset. First I extract a subset from the builtin geology polygon vector. This way, I have some small and some large areas, that are not contiguous. So the smoothing will be obvious. Then I add and populate (as you did) an area attribute. Now, I can do v.generalize with the where= condition.

But note: you must specify the layer for this to work. The default is to use all layers, and in that case, where= is ignored. This was pointed out 1n the grass-users maillist message.

micha@TP480:~$ v.extract geology output=my_geology --o where="GEO_NAME='Qp'"
Extracting features...
 100%
Building topology for vector map <my_geology@user1>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%
Writing attributes...
micha@TP480:~$ 
micha@TP480:~$ v.db.addcolumn my_geology column="area_sqkm DOUBLE"
micha@TP480:~$ v.to.db my_geology option=area unit=kilometer column=area_sqkm
WARNING: Values in column <area_sqkm> will be overwritten
Reading areas...
 100%
Updating database...
 100%
326 categories read from vector map (layer 1)
326 records selected from table (layer 1)
326 categories read from vector map exist in selection from table
326 records updated/inserted (layer 1)
# Only a few polygons have area > 20 sq.km.:
micha@TP480:~$ v.db.select my_geology column=area_sqkm where="area_sqkm>20"
area_sqkm
141.526059
45.783948
27.856732
2688.963279
5030.98666
47.616086
93.061948
942.740866
25.049455
1027.366856
25.867045
33.64133
23.780279
29.099771
56.994219
22.329903

# Now run v.generalize, with a where clause. And be sure to specify the layer
micha@TP480:~$ v.generalize my_geology output=my_geology_smooth layer=1 type=area method=douglas thresh=100 where="area_sqkm>10" --o
Copying features...
 100%
Building topology for vector map <my_geology_smooth@user1>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%
-----------------------------------------------------
Generalization (douglas)...
Using threshold: 100 meters
 100%
-----------------------------------------------------
Building topology for vector map <my_geology_smooth@user1>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%
-----------------------------------------------------
v.generalize complete. Number of vertices for selected features reduced
from 31709 to 5125 (16% remaining)

Here's a zoom in view of the results. The red lines are the generalized boundaries. The blue areas are the original. You can see that the large area has been generalized, but the small "islands" have not.

enter image description here

  • One additional comment: This post on the GRASS users mail list should clear up the issue. – Micha Apr 22 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.