raster_elements.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. Raster elements
  2. =================
  3. .. _RasterCategory-label:
  4. Categories
  5. ----------
  6. All the raster classes support raster categories and share commons methods
  7. to modify the raster category.
  8. It is possible to check if the map has or not the categories with the
  9. ``has_cats`` method. ::
  10. >>> elev.has_cats()
  11. False
  12. Opening a map that has category, for example the "landcove_1m" raster map
  13. from the North Carolina mapset. The ``has_cats`` method return True. ::
  14. >>> land = raster.RasterRow('landcover_1m')
  15. >>> land.has_cats()
  16. True
  17. Get and set the categories title, with: ::
  18. >>> land.cats_title
  19. 'Rural area: Landcover'
  20. >>> land.cats_title = 'Rural area: Landcover2'
  21. >>> land.cats_title
  22. 'Rural area: Landcover2'
  23. >>> land.cats_title = 'Rural area: Landcover'
  24. Get the number of categories of the map with: ::
  25. >>> land.num_cats()
  26. 11
  27. See all the categories with: ::
  28. >>> land.cats
  29. [('pond', 1, None),
  30. ('forest', 2, None),
  31. ('developed', 3, None),
  32. ('bare', 4, None),
  33. ('paved road', 5, None),
  34. ('dirt road', 6, None),
  35. ('vineyard', 7, None),
  36. ('agriculture', 8, None),
  37. ('wetland', 9, None),
  38. ('bare ground path', 10, None),
  39. ('grass', 11, None)]
  40. Access a single category, using Rast_get_ith_cat(), with: ::
  41. >>> land.cats[0]
  42. ('pond', 1, None)
  43. >>> land.cats['pond']
  44. ('pond', 1, None)
  45. >>> land.get_cat(0)
  46. ('pond', 1, None)
  47. >>> land.get_cat('pond')
  48. ('pond', 1, None)
  49. Add new or change existing categories: ::
  50. >>> land.set_cat('label', 1)
  51. >>> land.get_cat('label')
  52. ('label', 1, None)
  53. >>> land.set_cat('pond', 1, 1)
  54. Sort categories, with: ::
  55. >>> land.sort_cats()
  56. Copy categories from another raster map with: ::
  57. >>> land.copy_cats(elev)
  58. Read and Write: ::
  59. >>> land.read_cats()
  60. >>> #land.write_cats()
  61. Get a Category object or set from a Category object: ::
  62. >>> cats = land.get_cats()
  63. >>> land.set_cats(cats)
  64. Export and import from a file: ::
  65. >>> land.write_cats_rules('land_rules.csv', ';')
  66. >>> land.read_cats_rules('land_rules.csv', ';')
  67. .. autoclass:: pygrass.raster.category.Category
  68. :members:
  69. .. _Buffer-label:
  70. Buffer
  71. ------
  72. The buffer class is used to interact with a memory buffer of a map like a
  73. raster row. The buffer class is based on the `numpy.ndarray`_ class. Therefore
  74. all the nice feature of the ndarray are allowed.
  75. .. autoclass:: pygrass.raster.buffer.Buffer
  76. :members:
  77. .. _numpy.ndarray: http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html
  78. .. _RowIO-label:
  79. RowIO
  80. ------
  81. .. autoclass:: pygrass.raster.rowio.RowIO
  82. :members:
  83. .. _Segment-label:
  84. Segment
  85. -------
  86. .. autoclass:: pygrass.raster.segment.Segment
  87. :members:
  88. .. _History-label:
  89. History
  90. --------
  91. .. autoclass:: pygrass.raster.history.History
  92. :members: