Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. """
  2. Interpolate a dem from a line shapefile
  3. The shapefile name is passed on the command line
  4. It must have a column named "level" with elevation values
  5. """
  6.  
  7. import os, sys
  8. import grass.script as grass
  9.  
  10. if "GISBASE" not in os.environ:
  11. print "You must be in GRASS GIS to run this program."
  12. sys.exit(1)
  13.  
  14. if len(sys.argv) < 2:
  15. print 'No shapefile specified'
  16. sys.exit(1)
  17.  
  18. # Get shapefile name on command line
  19. shp_path = sys.argv[1]
  20. shp = os.path.basename(shp_path)
  21. ctour_orig = os.path.splitext(shp)[0].lower()
  22. ctour = ctour_orig.replace(' ','_')
  23. ctour_rast = ctour + '_rast'
  24. dem_tile = ctour + '_dem'
  25.  
  26. print "Processing shapefile: %s" % ctour
  27.  
  28. grass.run_command('v.in.ogr', dsn=shp_path, output=ctour, type='line', overwrite=True)
  29. grass.run_command('g.region', flags='p', vect=ctour, overwrite=True)
  30. grass.run_command('v.to.rast', input=ctour, output=ctour, type='line', use='attr', attrcol='level', overwrite=True)
  31. grass.run_command('r.surf.contour', input=ctour, output=dem_tile, overwrite=True)
  32.  
  33. print "Completed creating raster tile: %s" % dem_tile
  34.  
  35. for s in *.shp; do python shp_to_dem.py $s; done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement