access.Access.create_euclidean_distance_neighbors

Access.create_euclidean_distance_neighbors(name='euclidean', threshold=0, centroid=False)[source]

Calculate the Euclidean distance among demand locations.

Parameters:
namestr

Column name for euclidean distances neighbors

thresholdint

Buffer threshold for non-point geometries, AKA max_distance

centroidbool

If True, convert geometries 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

Make sure you assign your desired geometry projection, which you can change as follows.

>>> chi_population = chi_population.to_crs(epsg = 2790)
>>> chi_docs_dents = chi_docs_dents.to_crs(epsg = 2790)

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_neighbors(name= 'euclidean_neighbors', threshold = 250000, centroid_o = True, centroid_d = True)

The newly calculated euclidean distance is stored in the neighbor_cost_df attribute.

>>> chicago_primary_care_geom.neighbor_cost_df.head()
        origin         dest  euclidean_neighbors
0  17031010100  17031010100             0.000000
1  17031010100  17031010201           998.259243
2  17031010100  17031010202           635.203387
3  17031010100  17031010300           653.415713
4  17031010100  17031010400          2065.375554