Sorry for the delay. With your comments in mind, I ended up coding it this way:
- define a zero-value one cell border around the whole array.
- walk through each row horizontally, looking for vertical changes in value. Store each one in a structure containing the left and right values, and the coordinates of the end points
- walk through each column vertically, looking for horizontal changes in value, as above.
- search for adjoining vertical segments, and merge them.
- search for adjoining horizontal segments, and merge them.
- Write out the lists of line segments.
It appears that the mapping tool we use is clever enough to join up adjacent lines into areas, so lines are all we need. The reason for the zero-value border isn't initially obvious, but it's necessary for the contouring routine to get its senses right.
I put an example of what a tiny (300m x 300m) test file in my blog, if anyone cares to see what it looks like.
I know my algorithm isn't that efficient; it took nearly 8 hours to process a real 73 x 58 km dataset on a P4-2800. My Fortran version (compiled with the excellent free-for-personal use Intel Fortran Compiler for Linux) looks like it will run at least an order of magnitude quicker.
I'm beginning to warm to Fortran (90, or 95; F77 I cannot love). It has a nifty WHERE command which is somewhere between map and grep.
Yes, at this point, you can say 'He's got away from us Jack.' ...
-- bowling trophy thieves, die!
| [reply] [d/l] [select] |
| [reply] |
Okay, a full set of (small) examples are in my scratchpad. It's a knotty wee problem.
-- bowling trophy thieves, die!
| [reply] |