Mapping geographic point coordinates to a coordinate grid - speeding it up
12 views (last 30 days)
Show older comments
Hi all
I'm sure this must be answered somewhere but I'm struggling to find anything, perhaps because of my poor knowledge of the appropriate terminology. I have a set of geographic point coordinates (lat,lon) - these are my locations. I have a geographic coordinate grid (LAT,LON). I have a data grid, data = f(LAT,LON). I need to find and store the data for each point location. I have been using the 'distance' function in a loop, something like this:
for idx = 1:100
% Calculate distance from a point location to each grid coordinate
distDeg = distance(lat(idx),lon(idx),LAT,LON);
% Find the mininum distance = correct grid cell index
gridIdx = find(distDeg==min(distDeg(:)));
% Use the index to obtain the data for that location
locData(idx) = data(gridIdx);
end
Is there another way that does not require a loop, or perhaps a function in the Mapping toolbox that could, for example, create a raster array (same size as LAT,LON) from my point coordinates that I can then use to index into my data array? I tried using vec2mtx but I still need a loop as it wants to treat vectors of point coordinates as a polygon, unless I'm missing something (probably). Any help would be much appreciated.
2 Comments
José-Luis
on 7 Jul 2016
I am not sure I follow. Do you want to interpolate a grid from a series of coordinates with data.
Answers (1)
Chad Greene
on 18 Jul 2016
Eebs, Is your dataset regular? By that I mean, is it a bunch of scattered points, or do your data points already fit nicely into a regular grid? If your data points are regular, there's no need to interpolate. Just use grid2xyz in the form:
locData = grid2xyz(lon,lat,data);
2 Comments
Ananya Ray
on 29 Mar 2024
looking for an answer. I am calculating satellite coverage. so i get a lat long of a point on earth and a predefined lat-long grid. I need to know which grid point is the closest match.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!