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

Dylan Beaudette dylan.beaudette at gmail.com
Fri May 23 12:05:28 EDT 2008


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


More information about the grass-user mailing list