X

NV5 Geospatial Blog

Each month, NV5 Geospatial posts new blog content across a variety of categories. Browse our latest posts below to learn about important geospatial information or use the search bar to find a specific topic or author. Stay informed of the latest blog posts, events, and technologies by joining our email list!



NV5 at ESA’s Living Planet Symposium 2025

NV5 at ESA’s Living Planet Symposium 2025

9/16/2025

We recently presented three cutting-edge research posters at the ESA Living Planet Symposium 2025 in Vienna, showcasing how NV5 technology and the ENVI® Ecosystem support innovation across ocean monitoring, mineral exploration, and disaster management. Explore each topic below and access the full posters to learn... Read More >

Monitor, Measure & Mitigate: Integrated Solutions for Geohazard Risk

Monitor, Measure & Mitigate: Integrated Solutions for Geohazard Risk

9/8/2025

Geohazards such as slope instability, erosion, settlement, or seepage pose ongoing risks to critical infrastructure. Roads, railways, pipelines, and utility corridors are especially vulnerable to these natural and human-influenced processes, which can evolve silently until sudden failure occurs. Traditional ground surveys provide only periodic... Read More >

Geo Sessions 2025: Geospatial Vision Beyond the Map

Geo Sessions 2025: Geospatial Vision Beyond the Map

8/5/2025

Lidar, SAR, and Spectral: Geospatial Innovation on the Horizon Last year, Geo Sessions brought together over 5,300 registrants from 159 countries, with attendees representing education, government agencies, consulting, and top geospatial companies like Esri, NOAA, Airbus, Planet, and USGS. At this year's Geo Sessions, NV5 is... Read More >

Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

6/3/2025

Rethinking the Reliability of Type 1a Supernovae   How do astronomers measure the universe? It all starts with distance. From gauging the size of a galaxy to calculating how fast the universe is expanding, measuring cosmic distances is essential to understanding everything in the sky. For nearby stars, astronomers use... Read More >

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

5/26/2025

Whether you’re new to remote sensing or a seasoned expert, there is no doubt that large language models (LLMs) like OpenAI’s ChatGPT or Google’s Gemini can be incredibly useful in many aspects of research. From exploring the electromagnetic spectrum to creating object detection models using the latest deep learning... Read More >

1345678910Last
«September 2025»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
15506 Rate this article:
5.0

Speeding up linear gridding of irregular points with multiple values (GRIDDATA)

Anonym

Gridding or interpolating large amounts of data is a common task for some IDL and ENVI users. Here, I am showing a trick that can speed up bi-linear interpolation using a triangulated collection of irregularly gridded points in 2-D. The assumption here is that there are multiple values for each distinct point (x,y), and instead of using GRIDDATA repeatedly for several hundred values at the same locations, the code is pre-computing weights for the triangle corners. This saves computations in the final step and thus achieves a nice speed improvement.

The speed improvement on my computer was going from 31.4 seconds to 8.4 seconds. Here is the output produced by the example code:

 

IDL> grid_speed

% Compiled module: GRID_SPEED.

% Time elapsed: 31.422000 seconds.

% Time elapsed: 8.4380002 seconds.

Mean, Variance, Skewness, Kurtosis

    0.426667    0.0376666      1.26416     0.492909

    0.426667    0.0376666      1.26416     0.492909

 

min, mean, max difference

-1.19209e-007 1.24474e-011 1.19209e-007

 

 

Here is the example code:

 

 

pro grid_speed

 compile_opt idl2,logical_predicate

 

 ;Set up random data points

 ;Let's say 200,000 spatial (X,Y) points with 400 measurements each

 npts = 200000

 nbands = 400

 im = randomu(seed, npts, nbands)

 x = randomu(seed, npts)

 y = randomu(seed, npts)

 

 ;Set up an output gridded space for desired locations

 nx = 768

 ny = 768

 start = [0,0]

 delta = 1d / [nx, ny]

 dim = [nx, ny]

 gridIm1 = fltarr(nx, ny, nbands)

 gridIm2 = fltarr(nx, ny, nbands)

 

 ;traditional approach for bilinear gridding

 tic

 triangulate, x, y, tr

 for i=0, nbands-1 do begin

   gridIm1[0,0,i] = griddata(x, y, im[*,i], triangles=tr, /linear, $

     start=start, delta=delta, dimension=dim)

 endfor

 toc

 

 tic

 triangulate, x, y, tr

 

 ;compute triangle numbers for each input point

 ;multiply by 3 so that triangles are numbered

 ;by the starting index 0, 3, 6, 9, ...

 index = lindgen(n_elements(tr))/3*3

 xt = x[tr[*]]

 yt = y[tr[*]]

 linTr = lindgen(size(tr, /dimensions))

 tr_num = round( $

   griddata(xt, yt, float(index),triangles=linTr, /linear, $

     start=start, delta=delta, dimension=dim))

 

 ;Compute weights for each of the 3 points in the enclosing triangle

  wts = ptrarr(3)

 for i=0, 2 do begin 

   w = griddata(xt, yt, lindgen(n_elements(xt)) mod 3 eq i, $

     triangles=linTr, /linear, $

     start=start, delta=delta, dimension=dim)

   wts[i] = ptr_new(w, /no_copy)

 endfor

 

 ;Compute interpolation for all bands using weights

 ;instead of GRIDDATA

 for i=0, nbands-1 do begin

   gridIm2[0,0,i] = im[tr[tr_num] + i*n_elements(x)] * (*wts[0])

   gridIm2[*,*,i] += im[tr[tr_num+1] + i*n_elements(x)] * (*wts[1])

   gridIm2[*,*,i] += im[tr[tr_num+2] + i*n_elements(x)] * (*wts[2])

 endfor

 toc

 

 ;Verify that the results are the same for both

 ;methods.

 print, 'Mean, Variance,Skewness, Kurtosis'

 print, moment(gridIm1)

 print, moment(gridIm2)

 print

 diff = gridIm2 - gridIm1

 print, 'min, mean, maxdifference'

 print, min(diff, max=maxDiff), mean(diff), maxDiff

end

Please login or register to post comments.