Problem with isolated nodes after splitting LineStrings at intersections in EPSG:2180

I’m developing a program to find the shortest path in an infrastructure network. I’m overlaying road and sewage grids (as lists of LineString objects, etc.), all in EPSG:2180 format. I then perform a “snap to grid” operation on these grids. The grids are passed to an algorithm that identifies intersection points of the LineStrings, and it returns a list of split LineStrings, which I then use to create a graph. The intersection points are added as nodes.

The problem is that, in many cases, the added node turns out to be an isolated node. I suspect this is due to precision issues in the calculations with one of the libraries. I’m using networkx and shapely. What can I do to ensure the nodes are placed exactly at the edge intersection points?

red dot – node which should be intersection
green and orange line – road and sewage grids

My code:

def find_intersection_points_on_list_of_linestrings(line_groups):
    # List for intersection points
    intersection_points = []

    # Combine all lines from the groups into a single list
    all_lines = []
    for group in line_groups:
        all_lines.extend(group)

    # Iterate through all combinations of LineString pairs
    for i, line1 in enumerate(all_lines):
        for j, line2 in enumerate(all_lines):
            # Ensure not to compare the same LineString
            if i < j:
                # Check for line intersection
                intersection = line1.intersection(line2)
                # If the intersection is a point, add it to the result list
                if isinstance(intersection, Point):
                    intersection_points.append(intersection)
                # If the intersection is a MultiPoint, add all points as well
                elif intersection.geom_type == 'MultiPoint':
                    intersection_points.extend(intersection.geoms)

    return intersection_points
def add_points_as_nodes(graph, points):
    """
    This function adds nodes to the graph based on a list of Shapely Point objects,
    converting them into tuples (x, y).
    
    :param graph: A graph object from networkx (e.g., nx.Graph())
    :param points: A list of Shapely Point objects
    """
    for index_, point in tqdm(enumerate(points), total=len(points), desc="Adding nodes"):
        # Check if the point has x and y attributes (if it's a Point object from Shapely)
        if hasattr(point, 'x') and hasattr(point, 'y'):
            # Add the tuple (x, y) as a node to the graph
            graph.add_node((point.x, point.y))
        else:
            raise ValueError(f"Unsupported point type: {point}")

I tried using shapely to find the intersection points of the LineStrings and then splitting the LineStrings at those points. I expected that after splitting the LineStrings and adding the intersection points as nodes to the graph, all nodes would be correctly connected. However, I’m noticing that some nodes are isolated, indicating they are not properly connected to the corresponding edges, likely due to precision issues during the intersection and splitting process.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật