#  This macro is a demonstration of how a typical soil layer might be 
#  processed using LTPlus.  The data is a part of an actual soil layer
#  scanned by the SCS.    JPD  5/3/90
#
#  ***** NOTE ***** you must have the rdef2 file  demo_p.rdef2 in the
#  default import directory for it to run correctly.


pause 8 First a map is created or acquired.
acquire poly_demo

pause 8 Next, some header data is set.
menuset_get poly_menu
header  maptype = polygon
header  menu_set = poly_menu
header  map_wd = 13

pause 8 Then the scanned data is imported.
scan_input
import  rdef2  demo_p.rdef2  1

pause 8 After the scanned (raster) data is imported, it is registered.
register 0 i1=27.0 10.0 i2=29.0 566.0 i3=624.0 566.0 i4=624.0 10.0
register 1 i1=45.000 120.000 i2=45.125 120.000 i3=45.125 119.783 i4=45.000 119.783

edit1
pause 8 Now the raster is checked for lines which touch & aren't supposed to.
pause 6 We look at the raw scan beginning at the top left corner.
view zoom 0 576
view full 0 576
pause 8 In this editing pass, we look for lines merging together.
view last 83 404
pause 8 Here is an example of scanned lines touching where they shouldn't.
separate
start 82 405
goto coord 85 400
pause 8 The input mode has been changed to 'separate' & two endpoints located.
continue 85 400
pause 8 After the second endpoint is input, a 'separation' is done on the scan.
view last 85 401
view last 159 247
pause 8 Here is the next separation.
start 154 251
goto coord 160 245
pause 1
goto coord 160 245
pause 1
continue 160 245
pause 1
start 160 244
pause 1
view last 160 245
view last 266 370
pause 1
start 266 380
goto coord 263 359
pause 1
continue 263 359
pause 1
view last 263 360
view last 518 269
pause 1
start 518 268
goto coord 521 270
pause 1
continue 521 270
pause 1
view last 521 270
view last 623 560
pause 1
start 623 556
goto coord 623 554
pause 1
continue 623 554
pause 1
view last 623 554
view last 218 82
pause 1
start 218 80
goto coord 220 83
pause 1
continue 220 83
pause 1
view last 220 83
clear_mode
view map 0 0
pause 8 Now that manual clean-up is done, we do the first batch clean-up.
#poly_clean1
  fill_holes
  del_spurs 2
  del_points
  thin_lines 0 0
  del_spurs 2
  redisp_map
# macro executed.
pause 8 This clean-up routine filled holes, deleted spurs, thinned lines etc.
view full 0 0
pause 10 Here is how the raster looks now.
view map 0 0
pause 5 Next, the margin area is cleared & a frame drawn to close polygons.
#clean_frame
  erase_margin
  frame_map d r
# macro executed.



edit2
pause 8 Next, we go to the edit2 menu & finish all the manual editing
pause 8 First, all the spurs are located automatically & their locations stored.
#log_poly1
  log clear
  log spurs
  log holes
  log points
  view zoom 0 0
# macro executed.
pause 8 Next, we visit each error location & correct the error if necessary.
goto log +
pause 8 Here, we see a gap where a polygon doesn't close.
bridge_gap
start 138 12
pause 8 The bridge_gaps input mode allows it to be fixed easily.
pause 5 We will visit the other gaps more quickly.
goto log +
pause 1
start 29 67
pause 1
goto log +
pause 1
start 416 170
pause 1
goto log +
pause 1
goto log +
pause 1
start 385 211
pause 1
goto log +
pause 1
goto log +
pause 1
start 622 237
pause 1
goto log +
pause 1
start 622 338
pause 1
goto log +
pause 1
start 384 516
pause 1
goto log +
pause 1
view last 382 519

pause 8 Now it is time to remove all remaining spurs:
clear_mode
fill_holes
del_spurs 9999999
del_points
thin_lines 0 0
del_spurs 9999999
pause 2

pause 8 The raster data is then vectorized and polygons formed:
assemble_map
assemble
view zoom 500 567
graphics +n0 
#wait An example of the vector/raster data combination is shown above.



pause 8 The data on the edges will now be snapped to a straight line frame:
crit_clear
crit_type  16
crit_exec  22  map border polygon
crit_type  1
crit_subel  22
crit_exec  21  segments which are part of the map border polygon
level_snap  21  33  33  2.500000  0  3
#wait The data after being snapped is shown above.


graphics 
view map
manual_atrbt
pause 8 Now the data is ready to be given labels or 'attributes'.
pause 8 First the data is displayed in vector form, with un-attributed data highlighted.
graphics -r +c +n0 +h26 

pause 8 now, attributes are assigned by digitizing a point within each polygon.
atrbt_dig  2  1  1
goto coord 63 320
pause 2
start 63 320
pause 2

atrbt_dig  2  1  $++
goto coord 37 301
pause 1
start 37 301
goto coord 149 269
pause 1
start 149 269
goto coord 213 328
pause 1
start 213 328
goto coord 104 434 
pause 1
start 104 434
goto coord 136 482
pause 1
start 136 482
goto coord 37 493
pause 1
start 37 493
goto coord 303 501
pause 1
start 303 501
goto coord 376 373
pause 1
start 376 373
goto coord 418 284
pause 1
start 418 284
goto coord 509 492
pause 1
start 509 492
goto coord 396 522
pause 1
start 396 522
goto coord 268 349
pause 1
start 268 349
goto coord 229 503
pause 1
start 229 503
goto coord 215 375
pause 1
start 215 375
goto coord 261 274
pause 1
start 261 274
goto coord 284 247
pause 1
start 284 247
goto coord 319 26
pause 1
start 319 26
goto coord 290 15
pause 1
start 290 15
goto coord 226 39
pause 1
start 226 39
goto coord 229 109
pause 1
start 229 109
goto coord 152 93
pause 1
start 152 93
goto coord 72 90
pause 1
start 72 90
goto coord 71 20
pause 1
start 71 20
goto coord 124 39
pause 1
start 124 39
goto coord 117 84
pause 1
start 117 84
goto coord 151 248
pause 1
start 151 248
goto coord 256 164
pause 1
start 256 164
goto coord 420 128
pause 1
start 420 128
goto coord 388 308
pause 1
start 388 308
goto coord 348 231
pause 1
start 348 231
goto coord 277 71
pause 1
start 277 71
goto coord 201 11
pause 1
start 201 11
goto coord 287 308
pause 1
start 287 308
goto coord 173 172
pause 1
start 173 172
goto coord 90 460
pause 1
start 90 460
goto coord 541 447
pause 1
start 541 447
goto coord 476 293
pause 1
start 476 293
goto coord 538 196
pause 1
start 538 196
goto coord 530 69
pause 1
start 530 69
goto coord 570 61
pause 1
start 570 61
goto coord 584 61
pause 1
start 584 61
goto coord 616 156
pause 1
start 616 156
goto coord 613 197
pause 1
start 613 197
goto coord 620 210
pause 1
start 620 210
goto coord 621 234
pause 1
start 621 234
goto coord 573 248
pause 1
start 573 248
goto coord 557 61
pause 1
start 557 61
goto coord 584 92
pause 1
start 584 92
goto coord 600 24
pause 1
start 600 24
goto coord 567 12
pause 1
start 567 12
goto coord 500 26
pause 1
start 500 26
goto coord 514 12
pause 1
start 514 12
goto coord 518 12
pause 1
start 517 12
goto coord 386 15
pause 1
start 389 15
goto coord 373 50
pause 1
start 373 50
goto coord 426 178
pause 1
start 426 178
goto coord 621 186
pause 1
start 621 186
goto coord 589 509
pause 1
start 589 509
goto coord 620 477
pause 1
start 620 477
goto coord 615 413
pause 1
start 615 413
goto coord 612 368
pause 1
start 612 368
goto coord 616 536
pause 1
start 616 536
goto coord 228 551
pause 1
start 228 551
goto coord 36 264
pause 1
start 36 264
goto coord 95 18
pause 1
start 95 18


goto coord 203 12
pause 1
start 203 12
goto coord 623 60
pause 1
start 623 60
goto coord 621 185
pause 1
start 621 185
goto coord 623 559
pause 1
start 623 559
goto coord 580 564
pause 1
start 580 564
goto coord 439 565 
pause 1
start 439 565
goto coord 494 565
pause 1
start 494 565
goto coord 621 256
pause 1
start 621 256
pause 8 In practice the polygons would be labelled twice & compared for accuracy.

graphics 

output_data
pause 8 Now a GIS importable file can be written.  In this example it is a DLG3 file:

export  dlg3  poly_demo.dlg  3  2  2  0

pause 8 This is what the file looks like:
more export poly_demo.dlg
pause 6 This macro is completed.
