A
A
agent_22032021-01-20 12:13:51
Python
agent_2203, 2021-01-20 12:13:51

How to create a radius at any distance m/km located around a coordinate and get a list of those coordinates?

The essence of the question is that there is a yandex map, in it we take any coordinate in latitude and longitude, let's say 55.880707, 37.55513 .

I need to find all coordinates within a radius, spaced every, say, a meter.
Don't know how to do it in python ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-01-20
@agent_2203

Let the coordinates x0,y0. The distance can be calculated using this formula ( wiki ).
You will either have to copy the code from the link and rewrite it in python, or use this package.
Further, you need to learn to retreat from a given point to the north or east by 1 meter. You can either meditate on the formula above, or you can simply run a binary search that will look for a change in latitude or longitude. Let d - how much you need to set aside in meters, R - the radius of the earth in meters. Then look for a change in the interval (0, 4*r*180/(2*Pi*R)). Try to postpone the current value in latitude or longitude, calculate the distance using the formula and, if it is greater than d, replace the upper limit of the segment with the middle, otherwise replace the lower limit. Stop bin.search when the segment becomes small enough (eg <1e-10).
Using the binsearch above, you can find how much latitude or longitude you need to offset in degrees to make the point move 1m. Now we can make the main loop.
First, generate points on the same vertical as the initial one. To do this, repeatedly set aside 1m north and south of it until the distance to (x0,y0) is greater than your radius. Binpoisk is enough to run exactly once at the very beginning and then postpone this increment up and down.
Then, in the same way, set aside new points to the west and east from each generated point. First, for each point, use a binsearch to find the desired increment in longitude. Then move it left and right until you go beyond the radius from (x0,y0).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question