How can I calculate distance between a point in a given radius inside a geographic coordinate grid?

21 views (last 30 days)
Hello all,
I tried to search for similar questions, and I have got different solutions, but nothing to combine all my tasks, hence I still can't find the proper approach for my problem. Some of the approaches include:
I need to create a grid which contains earthquake data, namely longitude and latitude points (N & E geographic coordinates). What I need is to divide the area into a 0.5 km interval 2-D grid in the horizontal coordinates.
For each grid point, I would need to plot a circle with radius 6 km, and count how many events fall within the circle as well as calculate the distance between the center point of the circle and each event point (earthquake event).
Attached is the file containing the earthquake data needed for the analysis.
Cheers,
H.
  9 Comments
darova
darova on 12 Mar 2020
  • What I'd like, is an algorithm that could divide the area into a uniform grid points, with intervals of 0.5 km in the horizontal coordiatnes
You have lat and long but want to draw grid 0.5km. Can you explain more?
Is this correct?
Harith Al Kubaisy
Harith Al Kubaisy on 12 Mar 2020
Yes, I'd like the grid points to be spaced out 0.5 km from each other, which equates to 0.004 in the decimal degrees.
The figure you put is exactly what I want. Circle around every grid point, prefrably around the cell's center, but this will do also. Thank you for keeping up with my questions!

Sign in to comment.

Accepted Answer

darova
darova on 12 Mar 2020
Here is how i see solution for this question
clc,clear
long = [57;52.1;50;52;43.5;50;53.5;52;43.2];
lat = [16;15.7;13.5;14.5;11.8;13.5;14.5;14;11.7];
step = 1;
x = min(lat):step:max(lat);
y = min(long):step:max(long);
[X,Y] = meshgrid(x,y); % create grid
R = 1; % circle radius
plot(lat,long,'.r') % plot data
hold on
for i = 1:length(x)
viscircles([x(i),y(1)], R) % plot circle
ix = (lat-x(i)).^2 + (long-y(1)).^2 < R^2;
plot(lat(ix),long(ix),'ob') % plot data inside circle (if exists)
end
plot(X,Y,'k',X',Y','k') % plot grid
hold off
view(2)
  66 Comments
Harith Kubaisy
Harith Kubaisy on 11 Apr 2020
Edited: Harith Kubaisy on 11 Apr 2020
Thank you a million! This definitely solves a major issue. Alright.
For cell N(21,43), which has two earthquakes within the circle, who are both 0.0016 degrees away from the grid point, which approximates to d(n) = 0.1776 km. T = 104 years. r = 6 km. sigma = 2.
Solving by hand for the eathquake kernel density of cell N(21,43) gives me a value of about 8.468e-05, while the array p from the script returns it as 1.6932e-04.
There is something off.
Scratch that. I forgot to multiply by two. My calculator reads 1.6936e-04 now. Thank you.
Harith Kubaisy
Harith Kubaisy on 26 Jul 2020
Hello Darova, I need to visualize the final density values (p) on a proper, projected geographic map. Is there a way to do this on MATLAB with the current script? If not, what is the best way to export the data to be able to visualize it on ArcMap 10.4?

Sign in to comment.

More Answers (1)

Cris LaPierre
Cris LaPierre on 12 Mar 2020
You can compute distances between two lat/lon coorinates using the Haversine formula. You can google it to find the equation. You can see an example of its implementation in MATLAB around the 6:50 mark in this video.
  2 Comments
Harith Al Kubaisy
Harith Al Kubaisy on 12 Mar 2020
Thanks for the response. That I'm aware of, but this partially captures the task I'm facing. I need to create circles around arbitrary grid points, which are uniformly spaced at 0.5 km (0.09 decimal degrees) intervals in the horizontal coordinates. How would I go ahead establishing this grid and circles automatically, not having to write down coordinates for each circle?
Harith Al Kubaisy
Harith Al Kubaisy on 12 Mar 2020
I don't have the lat/lon coordinates for the grid points, because they are not defined yet. This is part of the question I'm asking: defining the grid points.

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!