-
Notifications
You must be signed in to change notification settings - Fork 10
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
Create nodes at edge intersections #15
Comments
Notes towards this: intersection_node_geoms = []
for edge in edges.itertuples(index=False):
geom = edge.geometry
candidate_idxs = list(edges.sindex.intersection(geom.bounds))
candidates = n.edges.iloc[candidate_idxs]
intersections = candidates.intersection(geom)
for intersection in intersections:
geom_type = intersection.geom_type
if intersection.is_empty:
continue
elif: geom_type == 'Point':
intersection_node_geoms.append(intersection)
elif geom_type == 'MultiPoint':
for point in intersection.geoms:
intersection_node_geoms.append(point)
elif: geom_type == 'MultiLineString':
for line in intersection.geoms:
start = Point(line.coords[0])
end = Point(line.coords[-1])
intersection_node_geoms.append(start)
intersection_node_geoms.append(end)
else:
print(intersection.geom_type)
nodes = geopandas.GeoDataFrame(intersection_node_geoms, columns=['geometry']) MultiLineString intersections happen when lines run almost-overlapping for a stretch. |
see argentina-transport preprocessing/network_road_topology |
Hi Tom, New in the field of spatial networks, I've been searching into the related python ecosystem for network-oriented packages, and After reading the code, I think the following would make sense. You already did most of the work with your notes above.
I'll be implementing it and will make a PR if that makes sense to you. Any recommendation and advise is welcome. What do you think? |
Hi @jmon12 thanks for the message 🙂 Yes, a PR for this would be welcome. Here's a bit more quick thinking about implementation details of
Yes, a few tests would be welcome - try and exercise a couple of simple cases and any corner cases you can come up with:
|
Thank you for your advises! I was actually trying to find a way to reuse For the 2nd approach, since every iteration identifies all the intersections of a given edge, this should also give the correct topology. For the corner cases, I think that the case of an edge crossing an end-point should be considered: should it be recognized as an intersection or not? This would make Anyway, further points and questions will come while coding, I'll keep you updated. As soon as I have something mature-enough, I'll open a PR for you to review. Have a nice evening! |
Hi @tomalrussell, I just commited the first working version with a basic test. I will open a PR so you can have a first look and comment directly there, if that's alright with you. Every feedback is welcome since I'm not familiar with the tools at play. I will do and implement the following tests:
The main design question I think is the following. Since I'm creating new points at intersections, the internal
I chose the 2. option because it's less disruptive for the structure of your code. I might miss something here. Potential issues:
Concerning linting and coding style, I tried as much as possible to respect your style, but still:
|
Thanks for the draft PR, looks like a great start
This makes sense to me - I generally use the sindex to quickly look up candidates then check whether they actually intersect
See my comment on #51 - I wonder if end points should also cause edges to be split
A self-loop edge should be no problem for
All look good. The comments in line with the code are helpful notes on implementation detail 👍🏻
I like
The docs are fairly lightweight - it would be cool to add an example to the demo notebook - and documentation comments will get picked up in the API reference |
Just skimming through the above, if it's not already included, being able to restrict the node creation/line splitting to just those intersections of lines which share common attributes (along the same lines as i.e. for a road network, you wouldn't want nodes created where a tunnel happens to pass under local (ground level) roads. Likely the same for any other hierarchal network which could be at different 'levels' and/or elevations above/below ground? |
Hey @czor847 - yes, that would be useful related functionality, I'd say nice-to-have for this issue rather than essential. What do you reckon, @jmon12 ? One approach would be to pass in a |
@czor847 Yes that's definitely a nice feature, thank you for pointing it out. As you mentioned and for multilayer networks in general, it could do the job. |
No description provided.
The text was updated successfully, but these errors were encountered: