mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
coordinate distance functions
This commit is contained in:
parent
0fa3c29253
commit
1577d90263
2 changed files with 58 additions and 2 deletions
|
|
@ -5,9 +5,12 @@ logger = setup_logger()
|
|||
|
||||
|
||||
class OpenUprnClient:
|
||||
COLUMN_NAMES = [
|
||||
"""
|
||||
Specs for this dataset can be found here:
|
||||
https://www.ordnancesurvey.co.uk/documents/product-support/tech-spec/open-uprn-techspec-v1.pdf
|
||||
"""
|
||||
|
||||
]
|
||||
# TODO: Document this
|
||||
|
||||
def __init__(self, path, uprns):
|
||||
self.path = path
|
||||
|
|
|
|||
|
|
@ -165,3 +165,56 @@ def handler():
|
|||
# DATE_K_TYP
|
||||
# DATE_ENTER
|
||||
# AGS_LOG_UR
|
||||
|
||||
from pyproj import Proj, transform, Geod
|
||||
|
||||
def distance_between_coords(longitude, latitude, x_bng, y_bng):
|
||||
# Define the projections
|
||||
wgs84 = Proj(init='epsg:4326') # WGS84 (longitude, latitude)
|
||||
bng = Proj(init='epsg:27700') # British National Grid
|
||||
|
||||
# Convert (longitude, latitude) to BNG coordinates
|
||||
x, y = transform(wgs84, bng, longitude, latitude)
|
||||
|
||||
# Define a geographic measure object
|
||||
g = Geod(ellps='WGS84')
|
||||
|
||||
# Calculate the distance between the points
|
||||
# Note: Pyproj's 'Geod.inv' method returns azimuths and distance.
|
||||
# We're only interested in distance here, so we only keep the third result
|
||||
_, _, distance = g.inv(x, y, x_bng, y_bng)
|
||||
|
||||
return distance
|
||||
|
||||
def distance_between_bng_coords(x1_bng, y1_bng, x2_bng, y2_bng):
|
||||
# Define a geographic measure object
|
||||
g = Geod(ellps='airy') # Airy ellipsoid is used by the British National Grid
|
||||
|
||||
# Calculate the distance between the points
|
||||
# Note: Pyproj's 'Geod.inv' method returns azimuths and distance.
|
||||
# We're only interested in distance here, so we only keep the third result
|
||||
_, _, distance = g.inv(x1_bng, y1_bng, x2_bng, y2_bng)
|
||||
|
||||
return distance
|
||||
|
||||
import math
|
||||
|
||||
import math
|
||||
|
||||
def distance_between_bng_coords(x1_bng, y1_bng, x2_bng, y2_bng):
|
||||
# Calculate the Euclidean distance between the points
|
||||
distance_m = math.sqrt((x2_bng - x1_bng) ** 2 + (y2_bng - y1_bng) ** 2)
|
||||
distance_km = distance_m / 1000 # convert meters to kilometers
|
||||
return distance_m, distance_km
|
||||
|
||||
property = input_properties[0]
|
||||
|
||||
borehold_compare_to = borehole_data[0]
|
||||
|
||||
dist_m, dist_km = distance_between_bng_coords(
|
||||
x1_bng=property.coordinates["x_coordinate"],
|
||||
y1_bng=property.coordinates["y_coordinate"],
|
||||
x2_bng=borehold_compare_to["X"],
|
||||
y2_bng=borehold_compare_to["Y"],
|
||||
)
|
||||
# ground source heat pump.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue