vectoraccess.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. from grass.lib import grass
  11. from grass.lib import vector as grassvect
  12. if not os.environ.has_key("GISBASE"):
  13. print "You must be in GRASS GIS to run this program."
  14. sys.exit(1)
  15. if len(sys.argv)==2:
  16. input = sys.argv[1]
  17. else:
  18. input = raw_input("Vector Map Name? ")
  19. # initialize
  20. grass.G_gisinit('')
  21. # find map in search path
  22. mapset = grass.G_find_vector2(input,'')
  23. # define map structure
  24. map = grassvect.Map_info()
  25. # define open level (level 2: topology)
  26. grassvect.Vect_set_open_level (2)
  27. # open existing map
  28. grassvect.Vect_open_old(map, input, mapset)
  29. # query
  30. print 'Vect map: ', input
  31. print 'Vect is 3D: ', grassvect.Vect_is_3d (map)
  32. print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)
  33. print 'Map Scale: 1:', grassvect.Vect_get_scale(map)
  34. # misleading:
  35. # print 'Number of lines:', grassvect.Vect_get_num_lines(map)
  36. # how to access GV_POINT?
  37. # print 'Number of points: ', grassvect.Vect_get_num_primitives(map,GV_POINT)
  38. # confusing:
  39. #print 'Number of lines: ', grassvect.Vect_get_num_primitives(map,GV_LINE)
  40. #print 'Number of areas:', grassvect.Vect_get_num_primitives(map,GV_AREA)
  41. print 'Number of areas:', grassvect.Vect_get_num_areas(map)
  42. # close map
  43. grassvect.Vect_close(map)
  44. ## end of the python script