Skip to content

nearest lat and lon #1

@hafez-ahmad

Description

@hafez-ahmad

`
lat, lon = dataset['latitude'], dataset['longitude']

np.min(np.abs(coordinates['point1'][0] - lat[:]))

stack the latitude and longitude into 1 array

latlon = np.stack([lat, lon], -1)

get euclidean distance between latlon and the point we're looking for, as an array

NOTE: this is not the great circle distance, so it's not exactly the best point, always, but will usually be right

dists = np.linalg.norm(latlon - np.array(list(coordinates['point1'])), axis=-1)

gets the index of the minimum distance (of the flattened array)

min_dist_idx = np.argmin(dists)
min_dist_y = min_dist_idx // dists.shape[1]
min_dist_x = min_dist_idx % dists.shape[1]
latlon[min_dist_y, min_dist_x]

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions