[GRASS-user] Tracing dotted lines from raster (and convert to vector)

Dear list,

I am curious to find out if it is possible to successfully convert the
"boundaries" of a raster map (contains some administrative boundaries)
in
a vector map.

The problem with this raster map is that the boundaries
are represented by non-continuous lines (dots).
---
Here is the link to the bad-looking gif files which contain
administrative boundaries (prefectures in Greece):
http://www.ypes.gr/kapodistrias/greek/kapo/nomoi.htm
---

Is there a way to get the biggest portion out of it as vector
lines/boundaries and correct manually as less as possible?

Thank you,
Nikos

P.S. My "quick" attempts so far

(a)

I 've tried using r.zc (edge detection) with no satisfactory results.

(b)

1. Save gif from http://www.ypes.gr/kapodistrias/images/i_trik.gif

2. grass -text # and create an xy location

3. r.in.gdal input="/grass_db/kapodistrias/data/i_trik.gif"
output="trikala"

4. d.rast trikala cat=3 # cat=3 is the blue color, that is the
boundaries of interest.

5. r.mapcalc trikala_3="if(trikala == 3, 3, null())"

6. r.thin input="trikala_3" output="trikala_3.thinned" iterations=200

7. r.to.vect input="trikala_3.thinned" output="trikala_3_thinned"
feature="line"

8. v.clean input="trikala_3_thinned" output="trikala_3_thinned_clean"
type="line" tool="snap,rmdangle,rmbridge,rmdupl" thresh=16

Probably only snap help here but anyway I tested several options. snap
threshold above 20 and below 14 gives few/bad lines.

If there is a way to connect the "blue dots" in the raster map then I
suppose it would be more or less easy to grab lines from the raster
map.

On Friday 23 May 2008, Nikos Alexandris wrote:

Dear list,

I am curious to find out if it is possible to successfully convert the
"boundaries" of a raster map (contains some administrative boundaries)
in
a vector map.

The problem with this raster map is that the boundaries
are represented by non-continuous lines (dots).
---
Here is the link to the bad-looking gif files which contain
administrative boundaries (prefectures in Greece):
http://www.ypes.gr/kapodistrias/greek/kapo/nomoi.htm
---

Is there a way to get the biggest portion out of it as vector
lines/boundaries and correct manually as less as possible?

Thank you,
Nikos

P.S. My "quick" attempts so far

(a)

I 've tried using r.zc (edge detection) with no satisfactory results.

(b)

1. Save gif from http://www.ypes.gr/kapodistrias/images/i_trik.gif

2. grass -text # and create an xy location

3. r.in.gdal input="/grass_db/kapodistrias/data/i_trik.gif"
output="trikala"

4. d.rast trikala cat=3 # cat=3 is the blue color, that is the
boundaries of interest.

5. r.mapcalc trikala_3="if(trikala == 3, 3, null())"

6. r.thin input="trikala_3" output="trikala_3.thinned" iterations=200

7. r.to.vect input="trikala_3.thinned" output="trikala_3_thinned"
feature="line"

8. v.clean input="trikala_3_thinned" output="trikala_3_thinned_clean"
type="line" tool="snap,rmdangle,rmbridge,rmdupl" thresh=16

Probably only snap help here but anyway I tested several options. snap
threshold above 20 and below 14 gives few/bad lines.

If there is a way to connect the "blue dots" in the raster map then I
suppose it would be more or less easy to grab lines from the raster
map.

I have found that when you are working with discontinuous line segments that
don't have gaps too large -- it is possible to "re-connect" the lines with
the following procedure:

1. extract only the color of interest
2. use r.grow to "fatten" the segments until they touch
3. use r.thin to return the segments to linear feature
4. vectorize with r.to.vect

I have used this approach with area features as well. See this link for some
ideas:
http://casoilresource.lawr.ucdavis.edu/drupal/node/244

Cheers,

Dylan

--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

On Fri, 2008-05-23 at 17:46 +0200, Nikos Alexandris wrote:

Dear list,

I am curious to find out if it is possible to successfully convert the
"boundaries" of a raster map (contains some administrative boundaries)
in
a vector map.

The problem with this raster map is that the boundaries
are represented by non-continuous lines (dots).
---
Here is the link to the bad-looking gif files which contain
administrative boundaries (prefectures in Greece):
http://www.ypes.gr/kapodistrias/greek/kapo/nomoi.htm
---

Is there a way to get the biggest portion out of it as vector
lines/boundaries and correct manually as less as possible?

Thank you,
Nikos

P.S. My "quick" attempts so far

(a)

I 've tried using r.zc (edge detection) with no satisfactory results.

(b)

1. Save gif from http://www.ypes.gr/kapodistrias/images/i_trik.gif

2. grass -text # and create an xy location

3. r.in.gdal input="/grass_db/kapodistrias/data/i_trik.gif"
output="trikala"

4. d.rast trikala cat=3 # cat=3 is the blue color, that is the
boundaries of interest.

5. r.mapcalc trikala_3="if(trikala == 3, 3, null())"

6. r.thin input="trikala_3" output="trikala_3.thinned" iterations=200

7. r.to.vect input="trikala_3.thinned" output="trikala_3_thinned"
feature="line"

8. v.clean input="trikala_3_thinned" output="trikala_3_thinned_clean"
type="line" tool="snap,rmdangle,rmbridge,rmdupl" thresh=16

Probably only snap help here but anyway I tested several options. snap
threshold above 20 and below 14 gives few/bad lines.

If there is a way to connect the "blue dots" in the raster map then I
suppose it would be more or less easy to grab lines from the raster
map.

O.K.,

I feel I am closer to the target.

I used r.grow and then r.thin.

Now it looks much better but I have lots of small-length lines left and
right from the borders.

v.clean tool=rmdangle does halfway the job.

How do I tell GRASS (v.clean?) to remove lines of small lentghs?

Hi,

2008/5/23 Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:
[...]

v.clean tool=rmdangle does halfway the job.

How do I tell GRASS (v.clean?) to remove lines of small lentghs?

try v.edit, e.g.

v.edit map tool=delete query=length thresh=-1,0,-50 type=line

which removes from vector map all lines with length shorter than 50 map units

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

I have found that when you are working with discontinuous line segments that
don't have gaps too large -- it is possible to "re-connect" the lines with
the following procedure:

1. extract only the color of interest
2. use r.grow to "fatten" the segments until they touch
3. use r.thin to return the segments to linear feature
4. vectorize with r.to.vect

I have used this approach with area features as well. See this link for some
ideas:
http://casoilresource.lawr.ucdavis.edu/drupal/node/244

Cheers,

Dylan

Yep,

it works great. Also here
http://grass.osgeo.org/wiki/Trace_vector_contours_from_a_scanned_map

which might be yours :wink:

Thanks.

It feels good that I also "found" the same way more or less in the end.
I noticed the "trick" of keeping the color of the lines of interest
afterwards.

On Fri, 2008-05-23 at 18:20 +0200, Martin Landa wrote:

v.edit map tool=delete query=length thresh=-1,0,-50 type=line

Martin,

it removes more than what I would like it to remove.

Even with a small thresh like:
v.edit trikala_3_grown_thinned tool=delete query=length thresh=-1,0,-5
type=line

Anyhow,

the v.clean tool=rmdangle works fine with the proper thresh value.

Thank you,

Nikos

Hi,

2008/5/23 Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:

it removes more than what I would like it to remove.

Even with a small thresh like:
v.edit trikala_3_grown_thinned tool=delete query=length thresh=-1,0,-5
type=line

tool=length -> tool=dangle

does the same job as v.clean.

Anyhow,

the v.clean tool=rmdangle works fine with the proper thresh value.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *