Skip to content

Net

Net类初始化

Parameters:

Name Type Description Default
link_gdf GeoDataFrame

gpd.GeoDataFrame, 线层数据, 必需参数

None
node_gdf GeoDataFrame

gpd.GeoDataFrame, 点层数据, 必需参数

None
link_path str

str, link层的路网文件路径, 若指定了该参数, 则直接从磁盘读取线层, 可选参数

None
node_path str

str, node层的路网文件路径, 若指定了该参数, 则直接从磁盘读取点层, 可选参数

None
cut_off float

路径搜索截断长度, 米, 可选参数

1200.0
not_conn_cost float

float, 不连通路径的阻抗(m), 可选参数

1000.0
fmm_cache bool

bool, 是否启用路径预计算, 可选参数

False
cache_cn int

int, 使用几个核进行路径预计算, 可选参数

2
cache_slice int

int, 大于0的整数, 表示将路径预计算结果切分为cache_slice份(大规模路网启用预计算时, 增大该值可以防止内存溢出)

None
fmm_cache_fldr str

str, 存储路径预计算结果的文件目录, 可选参数

'./'
recalc_cache bool

bool, 是否重新进行路径预计算, 取值False时, 程序会去fmm_cache_fldr下读取缓存, 若读取失败则会重新进行路径预计算, 可选参数

True
prj_cache bool

bool, 是否启用投影缓存, 可选参数

True
is_hierarchical bool

bool, 是否启用空间分层, 可选参数

False
grid_len float

float, 启用空间分层时, 该参数起效, 意为将路网区域划分为grid_len(m)的栅格, 可选参数

2000.0
cache_name str

路径预存储的标志名称, 默认cache

'cache'
plane_crs str

str, 要使用的平面投影坐标系, 用户若不指定, 程序会依据路网的经纬度范围自动进行6度投影带的选择, 推荐使用程序自动

None
weight_field str

str, 搜路权重字段, 目前只能为length

'length'
create_single bool

bool, 是否在初始化的时候创建单项路网, 可选参数

True
search_method str

str, 路径搜索方法, 目前只能为dijkstra

'dijkstra'
is_sub_net bool

bool, 用户不可指定

False
init_from_existing bool

bool, 用户不可指定

False
double_single_mapping dict

dict, 用户不可指定

None
link_ft_mapping dict

dict, 用户不可指定

None
link_f_mapping dict

dict, 用户不可指定

None
link_t_mapping dict

dict, 用户不可指定

None
link_geo_mapping dict

dict, 用户不可指定

None
ft_link_mapping dict

dict, 用户不可指定

None
Source code in src/gotrackit/map/Net.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
@function_time_cost
def __init__(self, link_path: str = None, node_path: str = None, link_gdf: gpd.GeoDataFrame = None,
             node_gdf: gpd.GeoDataFrame = None, weight_field: str = 'length', init_from_existing: bool = False,
             is_check: bool = True, create_single: bool = True, search_method: str = 'dijkstra',
             ft_link_mapping: dict = None, double_single_mapping: dict = None, link_ft_mapping: dict = None,
             link_t_mapping: dict = None, link_f_mapping: dict = None, link_geo_mapping: dict = None,
             not_conn_cost: float = 1000.0, cache_path: bool = True, cache_id: bool = True,
             is_sub_net: bool = False, fmm_cache: bool = False, cache_cn: int = 2, cache_slice: int = None,
             fmm_cache_fldr: str = r'./', prj_cache: bool = True, grid_len: float = 2000.0, is_hierarchical: bool = False,
             cache_name: str = 'cache', recalc_cache: bool = True,
             cut_off: float = 1200.0, delete_circle: bool = True, plane_crs: str = None):
    """Net类初始化

    Args:
        link_gdf: gpd.GeoDataFrame, 线层数据, 必需参数
        node_gdf: gpd.GeoDataFrame, 点层数据, 必需参数
        link_path: str, link层的路网文件路径, 若指定了该参数, 则直接从磁盘读取线层, 可选参数
        node_path: str, node层的路网文件路径, 若指定了该参数, 则直接从磁盘读取点层, 可选参数
        cut_off: 路径搜索截断长度, 米, 可选参数
        not_conn_cost: float, 不连通路径的阻抗(m), 可选参数
        fmm_cache: bool, 是否启用路径预计算, 可选参数
        cache_cn: int, 使用几个核进行路径预计算, 可选参数
        cache_slice: int, 大于0的整数, 表示将路径预计算结果切分为cache_slice份(大规模路网启用预计算时, 增大该值可以防止内存溢出)
        fmm_cache_fldr: str, 存储路径预计算结果的文件目录, 可选参数
        recalc_cache: bool, 是否重新进行路径预计算, 取值False时, 程序会去fmm_cache_fldr下读取缓存, 若读取失败则会重新进行路径预计算, 可选参数
        prj_cache: bool, 是否启用投影缓存, 可选参数
        is_hierarchical: bool, 是否启用空间分层, 可选参数
        grid_len: float, 启用空间分层时, 该参数起效, 意为将路网区域划分为grid_len(m)的栅格, 可选参数
        cache_name: 路径预存储的标志名称, 默认cache
        plane_crs: str, 要使用的平面投影坐标系, 用户若不指定, 程序会依据路网的经纬度范围自动进行6度投影带的选择, 推荐使用程序自动
        weight_field: str, 搜路权重字段, 目前只能为length
        create_single: bool, 是否在初始化的时候创建单项路网, 可选参数
        search_method: str, 路径搜索方法, 目前只能为dijkstra
        is_sub_net: bool, 用户不可指定
        init_from_existing: bool, 用户不可指定
        double_single_mapping: dict, 用户不可指定
        link_ft_mapping: dict, 用户不可指定
        link_f_mapping: dict, 用户不可指定
        link_t_mapping: dict, 用户不可指定
        link_geo_mapping: dict, 用户不可指定
        ft_link_mapping: dict, 用户不可指定
    """
    self.not_conn_cost = not_conn_cost
    self.geo_crs = geo_crs
    self.search_method = search_method
    self.weight_field = weight_field
    self.all_pair_path_df = pd.DataFrame()
    self.__stp_cache = dict() or pd.DataFrame
    self.__done_path_cost = dict() or pd.DataFrame
    self.__done_stp_cost_df = pd.DataFrame()
    self.__cache_prj_inf = dict()
    self.cache_path = cache_path
    self.cache_id = cache_id
    self.__is_sub_net = is_sub_net
    self.fmm_cache = fmm_cache
    self.cut_off = cut_off
    if cache_cn > os.cpu_count():
        cache_cn = os.cpu_count()
    self.cache_cn = cache_cn
    self.cache_name = cache_name
    self.fmm_cache_fldr = fmm_cache_fldr
    self.prj_cache = prj_cache
    self.recalc_cache = recalc_cache
    self.cache_slice = cache_slice
    self.delete_circle = delete_circle
    self.grid_len = 2000.0 if grid_len < 2000.0 else grid_len
    self.is_hierarchical = is_hierarchical
    self.region_grid = gpd.GeoDataFrame()
    self.grid_cor_link = pd.DataFrame()
    self.done_sjoin_cache = False
    if self.cache_slice is None:
        self.cache_slice = 2 * self.cache_cn

    if node_gdf is None:
        self.__node = Node(node_gdf=gpd.read_file(node_path), is_check=is_check, init_available_node=self.cache_id,
                           plane_crs=plane_crs)
    else:
        self.__node = Node(node_gdf=node_gdf, is_check=is_check, init_available_node=self.cache_id,
                           plane_crs=plane_crs)

    if not init_from_existing:
        self.__node.init_node()
    else:
        pass

    if link_gdf is None:
        self.__link = Link(link_gdf=gpd.read_file(link_path), weight_field=self.weight_field, is_check=is_check,
                           planar_crs=self.__node.planar_crs, init_available_link=self.cache_id,
                           not_conn_cost=self.not_conn_cost, delete_circle=self.delete_circle)
    else:
        self.__link = Link(link_gdf=link_gdf, weight_field=self.weight_field, is_check=is_check,
                           planar_crs=self.__node.planar_crs, init_available_link=self.cache_id,
                           not_conn_cost=self.not_conn_cost, delete_circle=self.delete_circle)
    self.__planar_crs = self.__node.planar_crs
    self.to_plane_prj()
    if not self.is_sub_net:
        self.del_zero_degree_nodes()
        self.__link.renew_length()
    if not init_from_existing:
        if create_single:
            self.__link.init_link()
    else:
        if create_single:
            # for sub net
            self.__link.init_link_from_existing_single_link(single_link_gdf=link_gdf,
                                                            double_single_mapping=double_single_mapping,
                                                            ft_link_mapping=ft_link_mapping,
                                                            link_ft_mapping=link_ft_mapping,
                                                            link_t_mapping=link_t_mapping,
                                                            link_f_mapping=link_f_mapping,
                                                            link_geo_mapping=link_geo_mapping)
    if is_check:
        self.check()

Parameters:

Name Type Description Default
o int
None
d int
None
k int
2

Returns:

Source code in src/gotrackit/map/Net.py
924
925
926
927
928
929
930
931
932
933
934
935
936
def shortest_k_paths(self, o: int = None, d: int = None, k: int = 2):
    """

    Args:
        o:
        d:
        k:

    Returns:

    """
    g = self.__link.get_graph()
    return list(islice(nx.shortest_simple_paths(g, o, d, weight=self.weight_field), k))