如何解决这个问题:parallel_offset 不再起作用

问题描述

你能帮我解决这个问题吗?之前用jupyter记事本的时候,没有任何问题。现在我正在处理 Django 项目,而我的 parallel_offset 函数不再起作用。当我将旧几何与新 _offset 几何进行比较时,我看到线几何被偏移了。但是我图输出,看不到双路。

col_list = ['geometry','oneway']
edges_gdf['_offset_geometry_'] = edges_gdf[col_list].apply(lambda x: 
                                 x['geometry'].parallel_offset(distance_offset,link_side) 
                                 if not x['oneway'] else x['geometry'].parallel_offset(0,link_side),axis=1)

edges_gdf.drop('geometry',axis=1,inplace=True)
edges_gdf.set_geometry('_offset_geometry_',inplace=True)
edges_gdf.to_crs(crs=CRS84,inplace=True) # Converting back in 4326 before ploting

完整视图:

def retrieve_data_from_postgres(network_id,Simple,set_initial_crs=4326,zone_radius=15,intersection_radius_percentage=0.8,distance_offset_percentage=0.8,line_color='orange',link_side='left',):
    initial_crs = "epsg:{}".format(set_initial_crs)
    initial_crs = CRS(initial_crs)
    CRS84 = "epsg:4326"
    default_crs = "epsg:3857"

    edges = Edge.objects.filter(network_id=network_id)
    edges = serialize('geojson',edges,fields=('id','param1','param2','param3','speed','length','lanes','geometry','name','source','target','network','road_type'))

    edges = json.loads(edges)
    edges_gdf = gpd.GeoDataFrame.from_features(edges['features']) # Convert a geojson as geodataframe

    nodes = Node.objects.filter(network_id=network_id).values()
    nodes_df = pd.DataFrame(nodes)
    nodes_df['location'] = nodes_df['location'].apply(geometry.Point)
    nodes_gdf = gpd.GeoDataFrame(nodes_df,geometry=nodes_df['location'])

    edges_gdf.set_crs(initial_crs,inplace=True)
    nodes_gdf.set_crs(initial_crs,inplace=True)
    nodes_gdf.to_crs(CRS84,inplace=True)
    edges_gdf = edges_gdf[edges_gdf.geometry.length > 0]
    zone_radius = zone_radius
    intersection_radius = intersection_radius_percentage * zone_radius
    distance_offset = distance_offset_percentage * zone_radius
    tiles_layer = 'OpenStreetMap'

    edges_gdf["oneway"] = edges_gdf.apply(lambda x: not edges_gdf[
            (edges_gdf["source"] == x["target"]) &
            (edges_gdf["target"] == x["source"])
            & (edges_gdf.index != x.name)].empty,axis=1)

    edges_gdf.to_crs(crs=default_crs,inplace=True)

    col_list = ['geometry','oneway']
    edges_gdf['_offset_geometry_'] = edges_gdf[col_list].apply(
        lambda x: x['geometry'].parallel_offset(
            distance_offset,link_side) if not x['oneway']
        else x['geometry'].parallel_offset(0,axis=1)

    edges_gdf.drop('geometry',inplace=True)
    edges_gdf.set_geometry('_offset_geometry_',inplace=True)
    edges_gdf.to_crs(crs=CRS84,inplace=True) # Converting back in 4326 before ploting
    
    latitudes = list(nodes_gdf['geometry'].y)
    longitudes = list(nodes_gdf['geometry'].x)

    # Initialize the map
    m = folium.Map(location=[latitudes[0],longitudes[0]],max_zoom=18,prefer_canvas=True,tiles=tiles_layer)

    layer=folium.GeoJson(
        edges_gdf,tooltip=folium.GeoJsonTooltip(fields=['oneway','name'],localize=True),style_function=lambda x: {'color': line_color}).add_to(m)

    # Bounding Box the map such that the network is entirely center and visible
    m.fit_bounds(layer.get_bounds())

    # Adding the nodes points
    for lat,long in list(zip(latitudes,longitudes)):
        folium.Circle(location=[lat,long],color='cyan',fill=True,fill_opacity=1,radius=intersection_radius).add_to(m)

    m.save('templates/visualization/visualization.html')

我应该有这样的东西

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)