man: Improve segment library documentation, provide examples#20
man: Improve segment library documentation, provide examples#20wenzeslaus wants to merge 13 commits intoOSGeo:mainfrom
Conversation
|
|
||
| /* determine the input map type (CELL/FCELL/DCELL) */ | ||
| map_type = Rast_map_type(input_name, ""); | ||
| size_t cell_size = Rast_cell_size(map_type); |
There was a problem hiding this comment.
move "size_t cell_size;" up, just after "RASTER_MAP_TYPE map_type;"
| ncols = Rast_window_cols(); | ||
|
|
||
| /* size of a segment */ | ||
| int srows = 64; |
There was a problem hiding this comment.
Move "int srows, scols, num_seg;" up
| int num_seg = 4; | ||
|
|
||
| /* segment structure */ | ||
| SEGMENT raster_seg; |
There was a problem hiding this comment.
move "SEGMENT raster_seg;" up
|
|
||
| /* pass the pointer, set the value */ | ||
| Segment_put(raster_seg, values, row, col); | ||
| } |
| ncols = Rast_window_cols(); | ||
|
|
||
| /* size of a segment */ | ||
| int srows = 64; |
There was a problem hiding this comment.
as for r.example.segment, move int srows, sclos, nsegs; up
| int nsegs = 4; | ||
|
|
||
| map_type = DCELL_TYPE; | ||
| size_t cell_size = Rast_cell_size(map_type); |
There was a problem hiding this comment.
Move "size_t cell_size, segment_cell_size;" up
| output_fd = Rast_open_new(output_name, map_type); | ||
|
|
||
| /* segment structure */ | ||
| SEGMENT raster_seg; |
| G_fatal_error(_("Unable to create temporary segment file")); | ||
|
|
||
| /* array to store file descriptors */ | ||
| int *input_fds = G_malloc(ninputs * sizeof(int)); |
| } | ||
|
|
||
| /* allocate input buffer */ | ||
| DCELL *row_buffer = Rast_allocate_d_buf(); |
There was a problem hiding this comment.
move "DCELL *row_buffer, *seg_buffer;" up
|
|
||
| /* pass the pointer, set the value */ | ||
| Segment_put(raster_seg, values, row, col); | ||
| } |
|
|
||
| <em> | ||
| <a href="r.example.html">r.example</a> | ||
| <a href="r.example.html">r.example.segment</a> |
| * <b>Buf</b> will be filled with <em>ncols*len</em> bytes of data | ||
| * corresponding to the <b>row</b> in the data matrix. | ||
| * \pre *buf* points to an allocated array of length <em>ncols*len</em> | ||
| * where *len* is size of one stored value (cell). |
There was a problem hiding this comment.
e.g. cell or a custom data structure
| * Segment_init(), all-in-memory mode initialization, and temporary | ||
| * file handling. | ||
| * | ||
| * The values are not guaranteed to be initialized to zero or NULL. |
There was a problem hiding this comment.
not values, but bytes, they are indeed initialized to zero because of lseek and calloc
| the raster you need to access: | ||
|
|
||
| \code | ||
| for (int row = 0; row < Rast_window_rows(); row++) { |
There was a problem hiding this comment.
for (int row = 0; ...) is C++ style
|
|
||
| \skip G_free | ||
| \until Rast_close(output_fd); | ||
|
|
Please use standard C style in sample code.
See "man calloc". malloc does not initialize the memory while calloc does.
No.
Yes, that's the reason: Segment_get_row() bypasses the internal cache and reads directly from the temporary file. |
|
Considering examples on how to use the segment library, it is IMHO sufficient to mention current working modules like r.cost, r.walk, r.watershed, r.stream.extract. |
|
Jumping into this discussion a bit late, so just two short comments:
I don't think this has been done as such in the code doc, yet, but maybe we could just add specific references to the existing production modules directly into the doc ? |
|
Note to myself: It seems that it worth explicitly noting that functions such as |
|
@wenzeslaus would you mind to rebase this PR? |
|
@wenzeslaus I manually resolved the conflicts |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
echoix
left a comment
There was a problem hiding this comment.
@wenzeslaus is this still relevant now? It is currently in a state where it up to date enough to pass CI, but there are still some very old (6 years) review comments.
Also, could you take a new look, to tell us if it still shows the patterns we want to show as an example?
It's kind of funny to still see the issue/pr number #20, that is still open. Probably the oldest we have open. Edit: it is the oldest open PR or issue we have
There was a problem hiding this comment.
Remember to apply the changes in a new markdown file when updating the PR.
There was a problem hiding this comment.
Remember to apply the changes in a new markdown file when updating the PR.
|
Hi! @wenzeslaus and @echoix, I was just seeing the oldest PRs for fun and found that this was stuck on some old merge conflicts and needed the docs converted to Markdown, so I decided to take a look ... I've gone ahead and rebased this work and converted the docs to Markdown to resolve the conflicts. |
This PR adds two examples into
doc/exampleswhich can be compiled as GRASS modules and executed. It adds 3 new sections to the library dox file: about general use with raster, about use with list of rasters (includes portions of one of the examples, so the code is only at one place), and a complete example (here including whole files). Finally, it modifies documentation for two functions.Besides asking for general review of best practices in using this library, I'm asking these two questions:
Segment_get_row()? DoesSegment_get()need the same one?Segment_flush()description suggests that only writing to disk andSegment_get_row()need that andSegment_get_row()does not call any page function if that has any influence.