vectoraccess.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/python
  2. # run within GRASS Spearfish session
  3. # run this before starting python to append module search path:
  4. # export PYTHONPATH=/usr/src/grass70/swig/python
  5. # check with "import sys; sys.path"
  6. # or:
  7. # sys.path.append("/usr/src/grass70/swig/python")
  8. # FIXME: install the grass bindings in $GISBASE/lib/ ?
  9. import os, sys
  10. import grass
  11. if not os.environ.has_key("GISBASE"):
  12. print "You must be in GRASS GIS to run this program."
  13. sys.exit(1)
  14. if len(sys.argv)==2:
  15. input = sys.argv[1]
  16. else:
  17. input = raw_input("Vector Map Name? ")
  18. # initialize
  19. grass.G_gisinit('')
  20. # find map in search path
  21. mapset = grass.G_find_vector2(input,'')
  22. # define map structure
  23. map = grass.Map_info()
  24. # define open level (level 2: topology)
  25. grass.Vect_set_open_level (2)
  26. # open existing map
  27. grass.Vect_open_old(map, input, mapset)
  28. # query
  29. print 'Vect map: ', input
  30. print 'Vect is 3D: ', grass.Vect_is_3d (map)
  31. print 'Vect DB links: ', grass.Vect_get_num_dblinks(map)
  32. print 'Map Scale: 1:', grass.Vect_get_scale(map)
  33. # misleading:
  34. # print 'Number of lines:', grass.Vect_get_num_lines(map)
  35. # how to access GV_POINT?
  36. # print 'Number of points: ', grass.Vect_get_num_primitives(map,GV_POINT)
  37. # confusing:
  38. #print 'Number of lines: ', grass.Vect_get_num_primitives(map,GV_LINE)
  39. #print 'Number of areas:', grass.Vect_get_num_primitives(map,GV_AREA)
  40. print 'Number of areas:', grass.Vect_get_num_areas(map)
  41. # close map
  42. grass.Vect_close(map)
  43. ## end of the python script