access.Access.create_euclidean_distance

Access.create_euclidean_distance(name='euclidean', threshold=0, centroid_o=False, centroid_d=False)[source]

Calculate the Euclidean distance from demand to supply locations. This is simply the geopandas distance function. The user is responsible for putting the geometries into an appropriate reference system.

Parameters:
namestr

Column name for euclidean distances

thresholdint

Buffer threshold for non-point geometries, AKA max_distance

centroid_obool

If True, convert geometries of demand_df (origins) to centroids; otherwise, no change

centroid_dbool

If True, convert geometries of supply_df (destinations) to centroids; otherwise, no change

Examples

NOTE: Creating euclidean distance measures requires having a geometry column in a geopandas.GeoDataFrame.

Import the base Access class and Datasets.

>>> from access import Access, Datasets

Load each of the example datasets which correspond to the demand (population), supply (doctors and dentists) and cost (travel time), respectively. The sample data represents the Chicago metro area with a 50km buffer around the city boundaries.

>>> chi_docs_dents   = Datasets.load_data('chi_doc_geom')
>>> chi_population   = Datasets.load_data('chi_pop_geom')
>>> chi_travel_costs = Datasets.load_data('chi_times')
>>> chi_docs_dents.head()
             doc  dentist                       geometry
geoid
17031010100    1        1  POINT (354916.992 594670.505)
17031010201    0        1  POINT (354105.876 594088.600)
17031010202    4        1  POINT (354650.684 594093.822)
17031010300    4        1  POINT (355209.361 594086.149)
17031010400    0        2  POINT (355809.748 592808.043)
>>> chi_population.head()
              pop                       geometry
geoid
17031010100  4854  POINT (354916.992 594670.505)
17031010201  6450  POINT (354105.876 594088.600)
17031010202  2818  POINT (354650.684 594093.822)
17031010300  6236  POINT (355209.361 594086.149)
17031010400  5042  POINT (355809.748 592808.043)

The chi_travel_costs dataset is the cost matrix, showing the travel time between each of the Census Tracts in the Chicago metro area.

>>> chi_travel_costs.head()
        origin         dest   cost
0  17093890101  17031010100  91.20
1  17093890101  17031010201  92.82
2  17093890101  17031010202  92.95
3  17093890101  17031010300  89.40
4  17093890101  17031010400  84.97

Now, create an instance of the Access class and specify the demand, supply, and cost datasets.

>>> chicago_primary_care = Access(demand_df = chi_population, demand_index = "geoid",
                                  demand_value = "pop",
                                  supply_df = chi_docs_dents, supply_index = "geoid",
                                  supply_value = ["doc", "dentist"],
                                  cost_df = chi_travel_costs, cost_origin  = "origin",
                                  cost_dest = "dest", cost_name = "cost")

To calculate euclidean distances between Census Tracts within 250km of eachother, you can set the threshold to 250000 (meters). Setting centroid_o and centroid_d to True calculates the centroid of the geom in your dataset.

>>> chicago_primary_care.create_euclidean_distance(threshold = 250000, centroid_o = True, centroid_d = True)

The newly calculated euclidean costs are added to the cost_df attribute of the Access class.

>>> chicago_primary_care_geom.cost_df.head()
        origin         dest   cost     euclidean
0  17093890101  17031010100  91.20  63630.788476
1  17093890101  17031010201  92.82  62632.675522
2  17093890101  17031010202  92.95  63073.735631
3  17093890101  17031010300  89.40  63520.029749
4  17093890101  17031010400  84.97  63268.514352