vectoraccess.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/python
  2. # run within GRASS Spearfish session
  3. import os, sys
  4. import swig.grass as grasslib
  5. import swig.vector as grassvect
  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("Vector Map Name? ")
  13. mapset = 'PERMANENT'
  14. # initialize
  15. grasslib.G_gisinit('')
  16. # define map structure
  17. map = grassvect.Map_info()
  18. # define open level (level 2: topology)
  19. grassvect.Vect_set_open_level (2)
  20. # open existing map
  21. grassvect.Vect_open_old(map, input, mapset)
  22. # query
  23. print 'Vect map: ', input
  24. print 'Vect is 3D: ', grassvect.Vect_is_3d (map)
  25. print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)
  26. print 'Map Scale: 1:', grassvect.Vect_get_scale(map)
  27. # misleading:
  28. # print 'Number of lines:', grassvect.Vect_get_num_lines(map)
  29. # how to access GV_POINT?
  30. # print 'Number of points: ', grassvect.Vect_get_num_primitives(map,GV_POINT)
  31. # confusing:
  32. #print 'Number of lines: ', Vect_get_num_primitives(map,GV_LINE)
  33. #print 'Number of areas:', Vect_get_num_primitives(map,GV_AREA)
  34. print 'Number of areas:', grassvect.Vect_get_num_areas(map)
  35. # close map
  36. grassvect.Vect_close(map)
  37. ## end of the python script