Difference between revisions of "Trace vector contours from a scanned map"

From GRASS-Wiki
Jump to: navigation, search
(init)
 
Line 1: Line 1:
# import scanned map image. to save processing later you might want to mask out
+
* Import a scanned map image. To save processing later you might want to mask out obvious text and other noise in a paint program first.
obvious text etc. in a paint program first.
 
 
  r.in.gdal
 
  r.in.gdal
  
# georectify map using GUI georectifier or i.points + i.rectify
+
* georectify map using GUI georectifier or i.points + i.rectify
 +
* switch to in target location
 +
* we now have a registered raster map containing a 300 dpi scan of our A0 sized map
  
# switch to in target location
+
* check how many categories
 
 
# we now have a registered raster map containing a 300 dpi scan of our A0 sized map
 
 
 
# check how many categories
 
 
  r.info chart
 
  r.info chart
# 8 colors (categories)
+
* 8 colors (categories)
  
# zoom to the map's bounds
+
* zoom to the map's bounds
 
  g.region rast=chart
 
  g.region rast=chart
  
# display map
+
* display map
 
  d.mon x0
 
  d.mon x0
 
  d.rast chart
 
  d.rast chart
  
# query map values
+
* query map values
 
  d.what.rast
 
  d.what.rast
# black is category 1
+
* black is category 1
  
# make a reclass map, with just the black lines
+
* make a reclass map, with just the black lines
 
  r.reclass in=chart out=chart_black << EOF
 
  r.reclass in=chart out=chart_black << EOF
 
  1 = 1 black
 
  1 = 1 black
 
  EOF
 
  EOF
  
# thin the lines to be 1 pixel wide
+
* thin the lines to be 1 pixel wide
 
  r.thin in=chart_black out=chart_black.thinned
 
  r.thin in=chart_black out=chart_black.thinned
  
# convert raster lines to vector lines
+
* convert raster lines to vector lines
 
  r.to.vect -s in=chart_black.thinned out=chart_lines
 
  r.to.vect -s in=chart_black.thinned out=chart_lines
  
# remove any dangles smaller than 1km
+
* remove any dangles smaller than 1km
 
  v.clean in=chart_lines out=chart_lines_cleaned tool=rmdangle thresh=1000
 
  v.clean in=chart_lines out=chart_lines_cleaned tool=rmdangle thresh=1000
  
# connect broken lines
+
* connect broken lines
 
  v.build.polylines -q in=chart_lines_cleaned out=chart_polyline
 
  v.build.polylines -q in=chart_lines_cleaned out=chart_polyline
  
# add category numbers to lines
+
* add category numbers to lines
 
  v.category in=chart_polyline out=chart_polyline_cat type=line
 
  v.category in=chart_polyline out=chart_polyline_cat type=line
  
# create a DB table to hold line length values
+
* create a DB table to hold line length values
 
  v.db.addtable chart_polyline_cat columns="length_km DOUBLE PRECISION"
 
  v.db.addtable chart_polyline_cat columns="length_km DOUBLE PRECISION"
  
# upload line lengths to DB table
+
* upload line lengths to DB table
 
  v.to.db chart_polyline_cat type=line option=length units=k column=length_km
 
  v.to.db chart_polyline_cat type=line option=length units=k column=length_km
  
# extract line features longer than 5km (cleans out the noise)
+
* extract line features longer than 5km (cleans out the noise)
 
  v.extract in=chart_polyline_cat out=chart_lines_5km type=line where="length_km > 5"
 
  v.extract in=chart_polyline_cat out=chart_lines_5km type=line where="length_km > 5"
  
# display result over raster chart
+
* display result over raster chart
 
  d.vect chart_lines_5km color=red width=2
 
  d.vect chart_lines_5km color=red width=2
  
# export as a shapefile
+
* export as a shapefile
 
  v.out.ogr in=chart_lines_5km dsn=chart_lines_gt5km
 
  v.out.ogr in=chart_lines_5km dsn=chart_lines_gt5km
  
# view shape file in [http://qgis.org QuantumGIS]
+
* view shape file in [http://qgis.org QuantumGIS]
 
  qgis chart_lines_gt5km/chart_lines_5km_crop.shp
 
  qgis chart_lines_gt5km/chart_lines_5km_crop.shp

Revision as of 00:37, 12 December 2006

  • Import a scanned map image. To save processing later you might want to mask out obvious text and other noise in a paint program first.
r.in.gdal
  • georectify map using GUI georectifier or i.points + i.rectify
  • switch to in target location
  • we now have a registered raster map containing a 300 dpi scan of our A0 sized map
  • check how many categories
r.info chart
  • 8 colors (categories)
  • zoom to the map's bounds
g.region rast=chart
  • display map
d.mon x0
d.rast chart
  • query map values
d.what.rast
  • black is category 1
  • make a reclass map, with just the black lines
r.reclass in=chart out=chart_black << EOF
1 = 1 black
EOF
  • thin the lines to be 1 pixel wide
r.thin in=chart_black out=chart_black.thinned
  • convert raster lines to vector lines
r.to.vect -s in=chart_black.thinned out=chart_lines
  • remove any dangles smaller than 1km
v.clean in=chart_lines out=chart_lines_cleaned tool=rmdangle thresh=1000
  • connect broken lines
v.build.polylines -q in=chart_lines_cleaned out=chart_polyline
  • add category numbers to lines
v.category in=chart_polyline out=chart_polyline_cat type=line
  • create a DB table to hold line length values
v.db.addtable chart_polyline_cat columns="length_km DOUBLE PRECISION"
  • upload line lengths to DB table
v.to.db chart_polyline_cat type=line option=length units=k column=length_km
  • extract line features longer than 5km (cleans out the noise)
v.extract in=chart_polyline_cat out=chart_lines_5km type=line where="length_km > 5"
  • display result over raster chart
d.vect chart_lines_5km color=red width=2
  • export as a shapefile
v.out.ogr in=chart_lines_5km dsn=chart_lines_gt5km
qgis chart_lines_gt5km/chart_lines_5km_crop.shp