vector.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Vector
  2. ========
  3. Instantiation and basic interaction. ::
  4. >>> from pygrass.vector import VectTopo
  5. >>> municip = VectTopo('boundary_municp_sqlite')
  6. >>> municip.is_open()
  7. False
  8. >>> municip.mapset
  9. ''
  10. >>> municip.exist() # check if exist, and if True set mapset
  11. True
  12. >>> municip.mapset
  13. 'user1'
  14. Open the map with topology: ::
  15. >>> municip.open()
  16. get the number of primitive:
  17. >>> municip.num_primitive_of('line')
  18. 0
  19. >>> municip.num_primitive_of('centroid')
  20. 3579
  21. >>> municip.num_primitive_of('boundary')
  22. 5128
  23. ask for other feature in the vector map: ::
  24. >>> municip.number_of("areas")
  25. 3579
  26. >>> municip.number_of("islands")
  27. 2629
  28. >>> municip.number_of("holes")
  29. 0
  30. >>> municip.number_of("lines")
  31. 8707
  32. >>> municip.number_of("nodes")
  33. 4178
  34. >>> municip.number_of("pizza") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
  35. Traceback (most recent call last):
  36. ...
  37. ValueError: vtype not supported, use one of: 'areas', ..., 'volumes'
  38. Suppose that we want to select all and only the areas that have an
  39. area bigger than 10000m2: ::
  40. >>> big = [area for area in municip.viter('areas')
  41. ... if area.alive() and area.area >= 10000]
  42. it's pretty easy, isn't it?!? :-)
  43. the method "viter" return an iterator object of the vector features,
  44. in this way no memory is wasted... User can choose on which
  45. vector features want to iterate...
  46. then you can go on with python stuff like, sort by area dimension: ::
  47. >>> from operator import methodcaller as method
  48. >>> big.sort(key = method('area'), reverse = True) # sort the list
  49. >>> for area in big[:3]:
  50. ... print area, area.area()
  51. Area(3102) 697521857.848
  52. Area(2682) 320224369.66
  53. Area(2552) 298356117.948
  54. or sort for the number of isles that are contained inside: ::
  55. >>> big.sort(key = lambda x: x.isles.__len__(), reverse = True)
  56. >>> for area in big[:3]:
  57. ... print area, area.isles.__len__()
  58. ...
  59. Area(2682) 68
  60. Area(2753) 45
  61. Area(872) 42
  62. or you may have only the list of the areas that contain isles inside, with: ::
  63. >>> area_with_isles = [area for area in big if area.isles]
  64. >>> area_with_isles # doctest: +ELLIPSIS
  65. [Area(...), ..., Area(...)]
  66. Of course is still possible work only with a specific area, with: ::
  67. >>> from pygrass.vector.geometry import Area
  68. >>> area = Area(v_id=1859, c_mapinfo=municip.c_mapinfo)
  69. >>> area.area()
  70. 39486.05401495844
  71. >>> area.bbox() # north, south, east, west
  72. Bbox(175711.718494, 175393.514494, 460344.093986, 460115.281986)
  73. >>> area.isles
  74. Isles([])
  75. Now, find an area with an island inside... ::
  76. >>> area = Area(v_id=2972, c_mapinfo=municip.c_mapinfo)
  77. >>> area.isles # doctest: +ELLIPSIS
  78. Isles([Isle(1538), Isle(1542), Isle(1543), ..., Isle(2571)])
  79. >>> isle = area.isles[0]
  80. >>> isle.bbox()
  81. Bbox(199947.296494, 199280.969494, 754920.623987, 754351.812986)
  82. VectorTopo
  83. ----------
  84. .. autoclass:: pygrass.vector.VectorTopo
  85. :members:
  86. Vector
  87. ----------
  88. .. autoclass:: pygrass.vector.Vector
  89. :members:
  90. Vector Features
  91. ===============
  92. Point
  93. ------
  94. .. autoclass:: pygrass.vector.geometry.Point
  95. :members:
  96. Line
  97. -----
  98. .. autoclass:: pygrass.vector.geometry.Line
  99. :members:
  100. Boundary
  101. --------
  102. .. autoclass:: pygrass.vector.geometry.Boundary
  103. :members:
  104. Isle
  105. -----
  106. .. autoclass:: pygrass.vector.geometry.Isle
  107. :members:
  108. Isles
  109. -----
  110. .. autoclass:: pygrass.vector.geometry.Isles
  111. :members:
  112. Area
  113. --------
  114. .. autoclass:: pygrass.vector.geometry.Boundary
  115. :members:
  116. Utils
  117. =====
  118. Bbox
  119. ----
  120. .. autoclass:: pygrass.vector.basic.Bbox
  121. :members:
  122. BoxList
  123. --------
  124. .. autoclass:: pygrass.vector.basic.BoxList
  125. :members:
  126. Ilist
  127. -----
  128. .. autoclass:: pygrass.vector.basic.Ilist
  129. :members:
  130. Cats
  131. -----
  132. .. autoclass:: pygrass.vector.basic.Cats
  133. :members: