vectoraccess.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # initialize
  14. grasslib.G_gisinit('')
  15. # find map in search path
  16. mapset = grasslib.G_find_vector2(input,'')
  17. # define map structure
  18. map = grassvect.Map_info()
  19. # define open level (level 2: topology)
  20. grassvect.Vect_set_open_level (2)
  21. # open existing map
  22. grassvect.Vect_open_old(map, input, mapset)
  23. # query
  24. print 'Vect map: ', input
  25. print 'Vect is 3D: ', grassvect.Vect_is_3d (map)
  26. print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)
  27. print 'Map Scale: 1:', grassvect.Vect_get_scale(map)
  28. # misleading:
  29. # print 'Number of lines:', grassvect.Vect_get_num_lines(map)
  30. # how to access GV_POINT?
  31. # print 'Number of points: ', grassvect.Vect_get_num_primitives(map,GV_POINT)
  32. # confusing:
  33. #print 'Number of lines: ', Vect_get_num_primitives(map,GV_LINE)
  34. #print 'Number of areas:', Vect_get_num_primitives(map,GV_AREA)
  35. print 'Number of areas:', grassvect.Vect_get_num_areas(map)
  36. # close map
  37. grassvect.Vect_close(map)
  38. ## end of the python script