vectorlib_faq.dox 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*! \page vlibFAQ Vector FAQ
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. <dl>
  4. <dt>What is the difference between line and boundary?</dt>
  5. <dd>
  6. Only boundaries are used to construct areas. Boundaries know the areas to their
  7. left and right.
  8. </dd>
  9. <dt>What is the difference between feature id and category?</dt>
  10. <dd>
  11. A category, as the name implies, is used to assign a feature to a certain
  12. category. A category is thus not a unique id, even though it can be used as
  13. such. Unique feature id's are created automatically be the vector lib and can
  14. change when the vector is modified (features added, deleted, topology rebuilt).
  15. </dd>
  16. <dt>In my module I need a unique identifier for feature. The identifier is for
  17. internal use only, i.e values will be used to identify features only when
  18. module is running. Can I use (internal) feature id for this?</dt>
  19. <dd>
  20. </dd>
  21. If you want to be sure that feature number x is always the same, it is safer to
  22. set categories such that they can be used as feature ids.
  23. </dd>
  24. <dt>I need a unique identifier of a feature. I'm using category for this. How
  25. should I check and handle states when number of categories for one line is not
  26. equal to 1?</dt>
  27. <dd>
  28. A category always belongs to a given layer. Check if there is one and only one
  29. category for the desired layer. If there is no category value set, skip this
  30. feature. If there are more categories set for the desired layer, the procedure
  31. depends on the purpose of the module. For example, \gmod{v.extract} would
  32. extract a feature if any of the categories set for the given layer is in the
  33. list of categories to be selected.
  34. </dd>
  35. <dt>I'm using category as a unique identifier of a feature. Thus, the case when
  36. number of categories is zero or more than one, I cannot continue in processing.
  37. Should I print warning or should I call G_fatal_error()?</dt>
  38. <dd>
  39. Both cases are generally valid in GRASS. Do not print a warning, maybe a verbose
  40. message. It is the responsibility of a module to make a reasonable plan how to
  41. handle these cases.
  42. </dd>
  43. <dt>My module requires using categories. When iterating over features, my
  44. algorithm have to bother with checking of input. It is possible to check
  45. categories in some other way i.g., for the whole map at once?</dt>
  46. <dd>
  47. \code{.py}
  48. # Python example using ctypes
  49. # checking category for each feature
  50. if areaCats.contents.n_cats == 0:
  51. # skip processing
  52. continue
  53. \endcode
  54. </dd>
  55. <dt>What is feature and what is line (not particular geometry type GV_LINE
  56. but the object read by Vect_read_line() function)?</dt>
  57. <dd>
  58. Vect_read_line() reads a feature from the coor file or from external
  59. datasources which can be for native GRASS vectors of type GV_POINT,
  60. GV_LINE, GV_BOUNDARY, GV_CENTROID or GV_FACE. In the code of the
  61. vector library and modules, the word 'line' often refers to a feature in
  62. general, not only to features of type GV_LINE.
  63. </dd>
  64. <dt>Can one feature have several categories? Do these categories have to be
  65. assigned to one feature in different layers (i.e. can I assign two or more
  66. categories to one feature in one layer)?</dt>
  67. <dd>
  68. GRASS supports M:N mapping of categories. Several features can share the same
  69. category, and one feature can have several categories. Further more, one
  70. feature can have several categories in the same layer. See manual of
  71. \gmod{v.buffer} (GRASS 7 only) for an example.
  72. </dd>
  73. <dt>What can I expect to get from function Vect_read_line() according to
  74. various combinations of features and categories in vector map?</dt>
  75. <dd>
  76. The return value of Vect_read_line() is the feature type, which must be
  77. positive, otherwise the read request was illegal. Vect_read_line() fills the
  78. Points and Cats structures with coordinates and categories.
  79. </dd>
  80. <dt>Why there is no function such as Vect_get_point() or
  81. Vect_get_boundary_points()?</dt>
  82. <dd>
  83. Because Vect_read_line() does that, i.e. it can read points, lines,
  84. boundaries, centroids, faces. The coordinates of these primitive features
  85. are stored in one file, and this file does not have separate
  86. sections for points, lines, boundaries, centroids, faces. The equivalent of
  87. Vect_get_point() etc is done on module level by checking the return type of
  88. Vect_read_line(). Further on, sometimes it is desired to work with more than
  89. one type at the same time. That's the reason for
  90. \code{.c}
  91. if (!(ltype & type))
  92. continue;
  93. \endcode
  94. </dd>
  95. <dt>Can I read areas with Vect_read_next_line()?</dt>
  96. <dd>
  97. No. An area is constructed from boundaries and centroids.
  98. </dd>
  99. <dt>What are the standard options for module which has a vector map without
  100. attribute table as an input?</dt>
  101. <dd>
  102. Input, output, type. Sometimes layer and category lists.
  103. </dd>
  104. <dt>What are the standard options for module which has a vector map with
  105. attribute table as an input?</dt>
  106. <dd>
  107. The above plus where for SQL where option.
  108. </dd>
  109. <dt>When should be layer number taken into account if user requires to do
  110. so?</dt>
  111. <dd>
  112. If the user requires it, you have to take it into account if you read features
  113. from a map or data from attribute table. More generally, whenever you work with
  114. categories.
  115. </dd>
  116. <dt>After reading feature by Vect_read_line() function you should loop over
  117. categories in line_cats structure?</dt>
  118. <dd>
  119. It depends. If the feature should only be processed if it belongs to a certain
  120. category, yes.
  121. </dd>
  122. <dt>My module reads some data from attribute table columns specified by user.
  123. What should I check before I can read from attribute table?</dt>
  124. <dd>
  125. If the columns exist. But sometimes column can be an expression of columns,
  126. e.g. col_a/col_b. Otherwise nothing unusual.
  127. </dd>
  128. <dt>My module writes some data to attribute table columns specified by
  129. user.</dt>
  130. <dd>
  131. What should I check before I can write to attribute table?
  132. If the specified table doesn't exists, should I create one?
  133. If the module does not create a new vector, and a table exists, check if the
  134. column exists and is of the correct type, if not, create the column. If the
  135. module does create a new vector, a new table must also be created.
  136. </dd>
  137. <dt>I should add features to vector map, add tables or columns only if \c
  138. \-\-overwrite was specified, right?</dt>
  139. <dd>
  140. The behaviour for db operations is not cleary defined in GRASS. Quite a lot
  141. works without \c \-\-overwrite. Try \gmod{v.db.update} or \gmod{v.to.db}.
  142. </dd>
  143. <dt>Checking user input is tedious are there any functions which makes it
  144. easier?</dt>
  145. <dd>
  146. Not really. There is G_legal_filename(), Vect_legal_filename() and
  147. Vect_check_input_output_name(). Module-specific options must be checked by the
  148. module.
  149. </dd>
  150. <dt>How can I handle memory correctly?</dt>
  151. <dd>
  152. <ul>
  153. <li>
  154. Memory allocated by Vect_new_line_struct() and Vect_new_cats_struct() can be
  155. automatically reallocated many times by various library functions. However at
  156. the end of your work you have to deallocate memory by calling functions
  157. Vect_destroy_line_struct() and Vect_destroy_cats_struct().
  158. <li>
  159. Structure Map_info is usually created on stack so no need for deallocating.
  160. Structure Map_info is used by modules like this:
  161. \code{.c}
  162. struct Map_info In, Out;
  163. \endcode
  164. So, no pointers, no allocation, no deallocation.
  165. </ul>
  166. As a rule of thumb, whenever you use some \c Vect_new_*() function, there
  167. should also be a corresponding \c Vect_destroy_*() function. These deallocating
  168. functions need only be used if the \c Vect_new_*() functions are called in a
  169. loop. A one-time call does not matter, memory is freed by the system when the
  170. module exits.
  171. </dd>
  172. <dt>What is the purpose of cat_list and ilist structures?</dt>
  173. <dd>
  174. A cat_list is used to store a list of cats, e.g. from a cats option. The ilist
  175. struct is a list of integers.
  176. </dd>
  177. <dt>How can I handle data without topology or data which are topologically
  178. incorrect?</dt>
  179. <dd>
  180. Use Vect_read_next_line() function.
  181. </dd>
  182. <dt>How can I handle overlapping areas? Can I use boundaries (GV_BOUNDARY)
  183. instead of areas (GV_AREA)?</dt>
  184. <dd>
  185. Overlapping boundaries are not topologically correct either. Either break
  186. boundaries, or (internal use only) do not build areas, or use lines if lines
  187. can hold all the info you need.
  188. </dd>
  189. <dt>Can I use boundaries or lines to represent topologically incorrect (i.e.
  190. overlapping) areas?</dt>
  191. <dd>
  192. In general, overlapping areas must be broken up into non-overlapping
  193. components. Some of the new areas will have several categories, one for each
  194. original area. For internal use, lines may be ok. Use lines instead of
  195. boundaries if you don't want to break into non-overlapping components.
  196. </dd>
  197. <dt>Region is not taken into account by vector library functions. Should my
  198. module do the same or it should do its work only in current region?</dt>
  199. <dd>
  200. It depends what your module is supposed to do. See \gmod{v.in.ogr},
  201. \gmod{v.in.region} or \gmod{v.to.rast} for examples where the current region is
  202. considered.
  203. </dd>
  204. <dt>When should I use the digitization threshold value from vector map
  205. metadata?</dt>
  206. <dd>
  207. </dd>
  208. <dt>What is the advantage of automatically attaching centroids to areas? How
  209. can one be sure that connecting will be successful?</dt>
  210. <dd>
  211. This question is unclear. What would be the alternative? The method to attach
  212. centroids to areas is well tested and has been working reliably for many years.
  213. </dd>
  214. <dt>Are there any functions providing functionality of \gmod{v.to.rast} and
  215. \gmod{r.to.vect} modules?</dt>
  216. <dd>
  217. No. Considering the large code base of these two modules, this would require
  218. new libraries which in turn would depend on both the vector and the raster
  219. libraries.
  220. </dd>
  221. <dt>What is Vector Simple Feature Access API? Is it related to OGC standard
  222. (like ST_ functions in Postgis)?</dt>
  223. <dd>
  224. </dd>
  225. </dl>
  226. */