How to use the libpysal.weights.higher_order function in libpysal

To help you get started, we’ve selected a few libpysal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinfleis / momepy / momepy / sandbox / contiguity.py View on Github external
def Queen_higher(dataframe, k):
    first_order = libpysal.weights.Queen.from_dataframe(dataframe)
    joined = first_order
    for i in list(range(2, k + 1)):
        i_order = libpysal.weights.higher_order(first_order, k=i)
        joined = libpysal.weights.w_union(joined, i_order)
    return joined
github martinfleis / momepy / momepy / sandbox / contiguity.py View on Github external
import libpysal
import geopandas as gpd

tessellation = gpd.read_file("/Users/martin/Dropbox/StrathUni/PhD/Sample Data/Prague/Tests/181122/tess_oldtown_nid.shp")

weights_queen = libpysal.weights.Queen.from_dataframe(tessellation)  # classic queen of 1st order
second_order = libpysal.weights.higher_order(weights_queen, k=2)  # second order neighbours (only)
joined_weights = libpysal.weights.w_union(weights_queen, second_order)  # joined together

weights_queen.neighbors[10]
second_order.neighbors[10]
joined_weights.neighbors[10]


def Queen_higher(dataframe, k):
    first_order = libpysal.weights.Queen.from_dataframe(dataframe)
    joined = first_order
    for i in list(range(2, k + 1)):
        i_order = libpysal.weights.higher_order(first_order, k=i)
        joined = libpysal.weights.w_union(joined, i_order)
    return joined

fourth = Queen_higher(tessellation, k=4)