base
Neighbourhood interface.
¶
Bases: ABC
, Generic[IndexType]
Neighbourhood interface.
This class abstracts away getting the neighbours of a region. It allows to get the neighbours at a certain distance or up to a certain distance. It is worth noting, that the distance here is not a metric distance, but a number of hops. This definition makes most sense semantically for grid systems such as H3 or S2 but should work for arbitrary neighbourhoods as well.
The subclasses only need to implement the get_neighbours
method, but can also override the
get_neighbours_up_to_distance
and get_neighbours_at_distance
methods for performance
reasons. See the H3Neighbourhood
class for an example. The class also provides a
_handle_center
method, which can be used to handle including/excluding the center region.
PARAMETER | DESCRIPTION |
---|---|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
Source code in srai/neighbourhoods/_base.py
¶
abstractmethod
Get the direct neighbours of a region using its index.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Get the neighbours of a region up to a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
distance |
Maximum distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |
Source code in srai/neighbourhoods/_base.py
¶
Get the neighbours of a region at a certain distance.
PARAMETER | DESCRIPTION |
---|---|
index |
Unique identifier of the region. Dependant on the implementation.
TYPE:
|
distance |
Distance to the neighbours.
TYPE:
|
include_center |
Whether to include the region itself in the neighbours.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[IndexType]
|
Set[IndexType]: Indexes of the neighbours. |