(
    objects,
    nodes,
    edges,
    node_id,
    edge_id=None,
    edge_keys=None,
    edge_values=None,
    verbose=True,
)
return series
Snap each building to closest street network node on the closest network edge.

    Adds node ID to objects (preferably buildings). Gets ID of edge
    (:func:`momepy.get_network_id` or :func:`get_network_ratio`)
    , and determines which of its end points is closer to building centroid.

    Pass either ``edge_id`` with a single value or ``edge_keys`` and ``edge_values``
    with ratios.

    Parameters
    ----------
    objects : GeoDataFrame
        GeoDataFrame containing objects to snap
    nodes : GeoDataFrame
        GeoDataFrame containing street nodes with unique node ID.
        If there is none, it could be generated by :func:`momepy.unique_id`.
    edges : GeoDataFrame
        GeoDataFrame containing street edges with unique edge ID and IDs of start
        and end points of each segment. Start and endpoints are default
        outcome of :func:`momepy.nx_to_gdf`.
    node_id : str, list, np.array, pd.Series
        the name of the nodes dataframe column, ``np.array``, or ``pd.Series``
        with unique id
    edge_id : str (default None)
        the name of the objects dataframe column
        with unique edge id (like an outcome of :func:`momepy.get_network_id`)
    edge_keys : str (default None)
        name the name of the objects dataframe column with edgeID_keys
        (like an outcome of :func:`momepy.get_network_ratio`)
    edge_values : str (default None)
        name the name of the objects dataframe column with edgeID_values
        (like an outcome of :func:`momepy.get_network_ratio`)
    verbose : bool (default True)
        if True, shows progress bars in loops and indication of steps

    Returns
    -------
    node_ids : Series
        Series containing node ID for objects
Snap each building to closest street network node on the closest network edge.
Snap each building to closest street network node on the closest network edge .
def get_node_id(
    objects,
    nodes,
    edges,
    node_id,
    edge_id=None,
    edge_keys=None,
    edge_values=None,
    verbose=True,
):
    """
    Snap each building to closest street network node on the closest network edge.

    Adds node ID to objects (preferably buildings). Gets ID of edge
    (:func:`momepy.get_network_id` or :func:`get_network_ratio`)
    , and determines which of its end points is closer to building centroid.

    Pass either ``edge_id`` with a single value or ``edge_keys`` and ``edge_values``
    with ratios.

    Parameters
    ----------
    objects : GeoDataFrame
        GeoDataFrame containing objects to snap
    nodes : GeoDataFrame
        GeoDataFrame containing street nodes with unique node ID.
        If there is none, it could be generated by :func:`momepy.unique_id`.
    edges : GeoDataFrame
        GeoDataFrame containing street edges with unique edge ID and IDs of start
        and end points of each segment. Start and endpoints are default
        outcome of :func:`momepy.nx_to_gdf`.
    node_id : str, list, np.array, pd.Series
        the name of the nodes dataframe column, ``np.array``, or ``pd.Series``
        with unique id
    edge_id : str (default None)
        the name of the objects dataframe column
        with unique edge id (like an outcome of :func:`momepy.get_network_id`)
    edge_keys : str (default None)
        name the name of the objects dataframe column with edgeID_keys
        (like an outcome of :func:`momepy.get_network_ratio`)
    edge_values : str (default None)
        name the name of the objects dataframe column with edgeID_values
        (like an outcome of :func:`momepy.get_network_ratio`)
    verbose : bool (default True)
        if True, shows progress bars in loops and indication of steps

    Returns
    -------
    node_ids : Series
        Series containing node ID for objects

    """
    nodes = nodes.set_index(node_id)

    if not isinstance(node_id, str):
        nodes["mm_noid"] = node_id
        node_id = "mm_noid"

    results_list = []
    if edge_id is not None:
        edges = edges.set_index(edge_id)
        centroids = objects.centroid
        for eid, centroid in tqdm(
            zip(objects[edge_id], centroids),
            total=objects.shape[0],
            disable=not verbose,
        ):
            if np.isnan(eid):
                results_list.append(np.nan)
            else:
                edge = edges.loc[eid]
                startID = edge.node_start
                start = nodes.loc[startID].geometry
                sd = centroid.distance(start)
                endID = edge.node_end
                end = nodes.loc[endID].geometry
                ed = centroid.distance(end)
                if sd > ed:
                    results_list.append(endID)
                else:
                    results_list.append(startID)

    elif edge_keys is not None and edge_values is not None:
        for edge_i, edge_r, geom in tqdm(
            zip(objects[edge_keys], objects[edge_values], objects.geometry),
            total=objects.shape[0],
            disable=not verbose,
        ):
            edge = edges.iloc[edge_i[edge_r.index(max(edge_r))]]
            startID = edge.node_start
            start = nodes.loc[startID].geometry
            sd = geom.distance(start)
            endID = edge.node_end
            end = nodes.loc[endID].geometry
            ed = geom.distance(end)
            if sd > ed:
                results_list.append(endID)
            else:
                results_list.append(startID)

    series = pd.Series(results_list, index=objects.index)
    return series
def get_node_id ( objects , nodes , edges , node_id , edge_id = None , edge_keys = None , edge_values = None , verbose = True , ) : nodes = nodes . set_index ( node_id ) if not isinstance ( node_id , str ) : nodes [ "mm_noid" ] = node_id node_id = "mm_noid" results_list = [ ] if edge_id is not None : edges = edges . set_index ( edge_id ) centroids = objects . centroid for eid , centroid in tqdm ( zip ( objects [ edge_id ] , centroids ) , total = objects . shape [ 0 ] , disable = not verbose , ) : if np . isnan ( eid ) : results_list . append ( np . nan ) else : edge = edges . loc [ eid ] startID = edge . node_start start = nodes . loc [ startID ] . geometry sd = centroid . distance ( start ) endID = edge . node_end end = nodes . loc [ endID ] . geometry ed = centroid . distance ( end ) if sd > ed : results_list . append ( endID ) else : results_list . append ( startID ) elif edge_keys is not None and edge_values is not None : for edge_i , edge_r , geom in tqdm ( zip ( objects [ edge_keys ] , objects [ edge_values ] , objects . geometry ) , total = objects . shape [ 0 ] , disable = not verbose , ) : edge = edges . iloc [ edge_i [ edge_r . index ( max ( edge_r ) ) ] ] startID = edge . node_start start = nodes . loc [ startID ] . geometry sd = geom . distance ( start ) endID = edge . node_end end = nodes . loc [ endID ] . geometry ed = geom . distance ( end ) if sd > ed : results_list . append ( endID ) else : results_list . append ( startID ) series = pd . Series ( results_list , index = objects . index ) return series