How to find the immediate neighbors of a point in a map?

1 view (last 30 days)
I'm trying to evaluate the effect of deforestation in a region of the Brazilian Amazon. And to do this, I have a matrix with known latitude and longitude points. Each of these represents a certain area of the terrain, and have information about that area, as deforestation level and type of forest.
What I need to know is how many of the 8 immediate neighbors of each point are deforested, (see image). My point is, although I know the lat/lon of each point, I don't know an efficient way of how to find these neighbors. This matrix has more than 1 million points, and it can be really time consuming.

Accepted Answer

Chad Greene
Chad Greene on 16 Jun 2015
There are a number of ways to find immediate neighbors, but no matter which way you do it, convert your lat/lons to some appropriate projected coordinates, perhaps using projfwd. Coordinates need to be projected because a degree of latitude does not equal a degree of longitude, so calculating a nearest neighbor by hypotenuse would be invalid.
Convert lat/lons to meters, then I recommend John D'Errico's ipdm function with 'Subset','smallestfew','limit',8 to subset to the 8 nearest neighbors for each point.

More Answers (1)

Image Analyst
Image Analyst on 16 Jun 2015
If you have the Statistics Toolbox you might be able to use pdist(). It gives the distance of every point to every other point. If each point is a blue circle in your image, then it looks like there are only a few thousand points and so pdist() shouldn't take that long. For each row (each point) you can sort the row in ascending order with sort() to find the other points that are closest.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!