[GRASS-dev] DEM, natural neighbor interpolation and Grass

Hi!

Maybe some of you remember my notes about the nnbathy (a natural
neighbor interpolation program), it's usability for producing DEMs from
clustered, heterogenous input and it's complicated interaction with
Grass.

nnbathy performs great. Now I wrote a script which is an easy to
use interface between nnbathy and Grass. All you need to do to run it
is to specify the input raster name and the output name. The script will
transform your input into x,y,z which nnbathy accepts, let nnbathy
interpolate the grid, then let awk do the processing from x,y,z nnbathy
output into Grass ASCII raster, and, finaly, r.in.ascii imports.

Please take a look at it and let me know what you think (also about the
html man page). I'll be putting the script on WIKI in few days if
nobody minds.

In order to obtain nnbathy with serial input processing enabled (to
interpolate any large grid with minor memory usage), please compile
it yourself following the instructions in the man page. The prebuilt
binaries at http://www.marine.csiro.au/~sakov don't have serial input
processing turned on.

Cheers
Maciek

P.S.

Please note that nnbathy accepts quite few options which modify the way
the output is produced. I have set the following ones in my script:

'-W 0' which limits the output non-NULL area only to the convex hull
encompasing the input data. You could let nnbathy extrapolate if
you need to, by modyfing the number after -W.

'-P alg=nn -n' which chooses the Sibson natural neighbor interpolation
algorithm. However, other 2 are possible - non-Sibsonian natural
neighbor, and linear (which looks exactly the same as the triangulation
eg. in Saga).

I haven't implemented controlling any nnbathy options through my
script, because for DEM production I'm most happy with output produced
by those particular settings I hardcoded. I guess you should be happy
with the result too.

There are several more options in nnbathy, if you want to experiment
the script is easy to modify. Please consult with nnabthy help page to
learn more.

Maciek

--------------------
W polskim Internecie s? setki milion?w stron. My przekazujemy Tobie tylko najlepsze z nich!
http://katalog.panoramainternetu.pl/

(attachments)

r.surf.nnbathy (4.83 KB)
r.surf.nnbathy.html (3.91 KB)

Maciek Sieczka wrote:

Hi!

Maybe some of you remember my notes about the nnbathy (a natural
neighbor interpolation program), it's usability for producing DEMs from
clustered, heterogenous input and it's complicated interaction with
Grass.

nnbathy performs great. Now I wrote a script which is an easy to
use interface between nnbathy and Grass. All you need to do to run it
is to specify the input raster name and the output name. The script will
transform your input into x,y,z which nnbathy accepts, let nnbathy
interpolate the grid, then let awk do the processing from x,y,z nnbathy
output into Grass ASCII raster, and, finaly, r.in.ascii imports.
  

Hamish - r.in.xyz should be able to import this directly ? so the awk step could be skipped making the procedure
faster - this will help particularly for large data sets. Helena

Please take a look at it and let me know what you think (also about the
html man page). I'll be putting the script on WIKI in few days if
nobody minds.

In order to obtain nnbathy with serial input processing enabled (to
interpolate any large grid with minor memory usage), please compile
it yourself following the instructions in the man page. The prebuilt
binaries at http://www.marine.csiro.au/~sakov don't have serial input
processing turned on.

Cheers
Maciek

P.S.

Please note that nnbathy accepts quite few options which modify the way
the output is produced. I have set the following ones in my script:

'-W 0' which limits the output non-NULL area only to the convex hull
encompasing the input data. You could let nnbathy extrapolate if
you need to, by modyfing the number after -W.

'-P alg=nn -n' which chooses the Sibson natural neighbor interpolation
algorithm. However, other 2 are possible - non-Sibsonian natural
neighbor, and linear (which looks exactly the same as the triangulation
eg. in Saga).

I haven't implemented controlling any nnbathy options through my
script, because for DEM production I'm most happy with output produced
by those particular settings I hardcoded. I guess you should be happy
with the result too.

There are several more options in nnbathy, if you want to experiment
the script is easy to modify. Please consult with nnabthy help page to
learn more.

Maciek

--------------------
W polskim Internecie s? setki milion?w stron. My przekazujemy Tobie tylko najlepsze z nich!
http://katalog.panoramainternetu.pl/
  
------------------------------------------------------------------------

    NAME

/*r.surf.nnbathy*/ - Interpolate surface from rasterized input using nn <http://www.marine.csiro.au/~sakov/&gt; natural neighbor intepolation library.

    SYNOPSIS

*r.surf.nnbathy*
*r.surf.nnbathy help*
*r.surf.nnbathy* *input*=/name/ *output*=/name/

      Parameters:

*input*=/name/
    Input raster name
*output*=/name/
    Output raster name

    DESCRIPTION

/r.surf.nnbathy/ is a Bash and Awk script. It is an interface between the external /nnbathy/ utility and Grass. /nnbathy/ is a surface interpolation program, which uses /nn/ - a natural neighbor interpolation library. /nnbathy/ and /nn/ were written by Pavel Sakov <http://www.marine.csiro.au/~sakov/&gt;\. /nn/ uses /triangle/ software by Jonathan Shewchuk <http://www.cs.berkeley.edu/~jrs/&gt; for performing the Delaunay triangulation.

The *output* raster contains a continous surface interpolated from the *input* raster.

There is no limitation in regard to the shape and distribution of the input cells. The input could be e.g. open or closed elevation contour lines, elevation points, areas and any combination of these. Natural neighbor algorithm exactly follows the input data and is able to produce a good result from very clustered, heterogenous input. It will preserve any rapid value gradient present in the input. It doesn't produce artificial bulges or hollows between the distant input data, only a linear, continous surface. It might lead to bogus flat areas in case of kidney-like shaped contour lines in input.

/nnbathy/, if built with '-DNN_SERIAL' switch, is able to handle a grid of virtually any size, using very little memory. It reads, interpolates and writes one output point at a time only. This eliminates necessity to hold the whole output array in memory.

In order to install /nnbathy/ with serial input processing enabled, do the following:

      1. Download nn.tar.gz from http://www.marine.csiro.au/~sakov/
      <http://www.marine.csiro.au/~sakov/&gt;
      2. tar xzvf nn.tar.gz
      3. cd nn
      4. ./configure
      5. make
      6. gcc -o nnbathy nnbathy.c -g -O2 -Wall -pedantic -I.
      -DNN_SERIAL libnn.a -lm
      7. chmod u+x ./nnbathy

Now copy the /nnbathy/ executable to a directory listed in your PATH.

    NOTES & CAVEATS

      1. The output extent and resolution will match the current
      region settings.
      2. The output non-NULL area will be limited to the convex hull
      encompassing all the non-NULL input cells.
      3. The output is double floating point raster.
      4. Natural neighbor is a an /exact/ interpolation algorithm, so
      all non-NULL input cells have their value exactly preserved in
      the output.
      5. The script will work with /nnbathy/ version 1.63 and higher.

      I'd like to thank Pavel Sakov
      <http://www.marine.csiro.au/~sakov/&gt; for all his support in
      regard to /nn/ and /nnbathy/ usage, and especially for
      implementing serial input processing.

    SEE ALSO

*v.to.rast*
Pavel Sakov <http://www.marine.csiro.au/~sakov/&gt;

    AUTHOR

Maciej Sieczka, Wroclaw, Poland, 2006
Wroclaw University, Intitute of Plant Biology
------------------------------------------------------------------------

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Helena Mitasova
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University
1125 Jordan Hall
NCSU Box 8208
Raleigh, NC 27695-8208
http://skagit.meas.ncsu.edu/~helena/

email: hmitaso@unity.ncsu.edu
ph: 919-513-1327 (no voicemail)
fax 919 515-7802

On Mon, 05 Jun 2006 15:21:00 -0400
Helena Mitasova <hmitaso@unity.ncsu.edu> wrote:

Hamish - r.in.xyz should be able to import this directly ? so the awk
step could be skipped making the procedure faster - this will help
particularly for large data sets.

I prefer to keep r.surf.nnbathy Grass 6.0x compatible, at least for now.

Maciek

--------------------
W polskim Internecie s? setki milion?w stron. My przekazujemy Tobie tylko najlepsze z nich!
http://katalog.panoramainternetu.pl/