浏览代码

vector ctypes sample script working now

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@44819 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 14 年之前
父节点
当前提交
7743885b47
共有 1 个文件被更改,包括 15 次插入21 次删除
  1. 15 21
      doc/python/vector_example_ctypes.py

+ 15 - 21
doc/python/vector_example_ctypes.py

@@ -28,10 +28,8 @@ else:
 G_gisinit('')
 
 # find vector map in the search path
-mapset = G_find_vector2(input, '')
-if mapset:
-    print "Vector map found in mapset <%s>" % mapset
-else:
+mapset = G_find_vector2(input, "")
+if not mapset:
     sys.exit("Vector map <%s> not found" % input)
 
 # define map structure
@@ -41,13 +39,13 @@ map = Map_info()
 Vect_set_open_level(2)
 
 # open existing vector map
-Vect_open_old(map, input, mapset)
+Vect_open_old(byref(map), input, mapset)
 
 # query
-print 'Vect map: ',      input
-print 'Vect is 3D: ',    Vect_is_3d(map)
-print 'Vect DB links: ', Vect_get_num_dblinks(map)
-print 'Map Scale:  1:',  Vect_get_scale(map)
+print 'Vector map     :', Vect_get_full_name(byref(map))
+print 'Vector is 3D   :', Vect_is_3d(byref(map))
+print 'Vector DB links:', Vect_get_num_dblinks(byref(map))
+print 'Map Scale:  1  :', Vect_get_scale(byref(map))
 
 # vector box tests
 box = bound_box()
@@ -55,18 +53,14 @@ c_easting1  = 599505.0
 c_northing  = 4921010.0
 c_easting2  = 4599505.0
 
-Vect_get_map_box(map, box)
-print 'Position 1   in box? ', Vect_point_in_box(c_easting1, c_northing, 0, box)
-print 'Position 2   in box? ', Vect_point_in_box(c_easting2, c_northing, 0, box)
-print 'Feature id 2 in box? ', Vect_get_line_box(map, 2, box)
+Vect_get_map_box(byref(map), byref(box))
+print 'Position 1 in box? ', Vect_point_in_box(c_easting1, c_northing, 0, byref(box))
+print 'Position 2 in box? ', Vect_point_in_box(c_easting2, c_northing, 0, byref(box))
 
-print 'Number of features:', Vect_get_num_lines(map)
-# how to access GV_POINT?
-# print 'Number of points: ', grassvect.Vect_get_num_primitives(map,GV_POINT)
-# confusing:
-#print 'Number of lines: ', grassvect.Vect_get_num_primitives(map,GV_LINE)
-#print 'Number of areas:', grassvect.Vect_get_num_primitives(map,GV_AREA)
-print 'Number of areas:',   Vect_get_num_areas(map)
+print 'Number of features:', Vect_get_num_lines(byref(map))
+print 'Number of points  :', Vect_get_num_primitives(byref(map), GV_POINT)
+print 'Number of lines   :', Vect_get_num_primitives(byref(map), GV_LINE)
+print 'Number of areas   :', Vect_get_num_areas(byref(map))
 
 # close map
-Vect_close(map)
+Vect_close(byref(map))