rasteraccess.py 809 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python
  2. # run within GRASS Spearfish session
  3. import os, sys
  4. import swig.grass as grasslib
  5. import swig.raster as grassrast
  6. if not os.environ.has_key("GISBASE"):
  7. print "You must be in GRASS GIS to run this program."
  8. sys.exit(1)
  9. if len(sys.argv)==2:
  10. input = sys.argv[1]
  11. else:
  12. input = raw_input("Raster Map Name? ")
  13. mapset = 'PERMANENT'
  14. # initialize
  15. grasslib.G_gisinit('')
  16. # determine the inputmap type (CELL/FCELL/DCELL) */
  17. data_type = grasslib.G_raster_map_type(input, mapset)
  18. infd = grasslib.G_open_cell_old(input, mapset)
  19. inrast = grasslib.G_allocate_raster_buf(data_type)
  20. rown=0
  21. while 1:
  22. myrow = grasslib.G_get_raster_row(infd, inrast, rown, data_type)
  23. print rown,myrow[0:10]
  24. rown = rown+1
  25. if rown==476:break
  26. grasslib.G_close_cell(inrast)
  27. grasslib.G_free(cell)