Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix network layout script #3409

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions cea/technologies/network_layout/connectivity_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,14 @@ def nearest_neighbor_within(others, point, max_distance):


def near_analysis(building_centroids, street_network, crs):
near_point = []
building_name = []
for point, name in zip(building_centroids.geometry, building_centroids.Name):
point._crs = crs
distance = 10e10
for line in street_network.geometry:
line._crs = crs
nearest_point_candidate = line.interpolate(line.project(point))
distance_candidate = point.distance(nearest_point_candidate)
if distance_candidate < distance:
distance = distance_candidate
nearest_point = nearest_point_candidate
building_name.append(name)
near_point.append(nearest_point)

geometry = near_point
df = gdf(geometry=geometry, crs=crs)
df["Name"] = building_name
# Get the nearest edge for each building centroid
nearest_indexes = street_network.sindex.nearest(building_centroids.geometry, return_all=False)[1]
nearest_lines = street_network.iloc[nearest_indexes].reset_index(drop=True) # reset index so vectorization works

# Find length along line that is closest to the point (project) and get interpolated point on the line (interpolate)
nearest_points = nearest_lines.interpolate(nearest_lines.project(building_centroids))

df = gdf({"Name": building_centroids["Name"]}, geometry=nearest_points, crs=crs)
return df


Expand Down
Loading