Beispiel #1
0
    def get_osm_node(self):
        self.osm_edge = load_postgis(self.osm_edge_pg,
                                     geom_wkt=self.geofence.to_wkt())
        helper = lambda x: self.link_type_no_dict[
            x] if x in self.link_type_no_dict else 99
        self.osm_edge.loc[:,
                          "road_level"] = self.osm_edge.road_type.apply(helper)

        node_lst = np.unique(
            self.osm_edge.query('road_level < 6')[[
                's', 'e'
            ]].values.flatten()).tolist()
        self.osm_node = load_postgis(
            self.osm_node_pg,
            geom_wkt=self.geofence.to_wkt()).query('nid in @node_lst')

        return self.osm_node
Beispiel #2
0
    def upload_pano_node(self, gdf: gpd.GeoDataFrame = None):
        # 经过测试,上传的 list 数据会自动序列化
        gdf = gdf if gdf is not None else self.gdf_pano_node
        gdf.loc[:, "ID"] = gdf.index

        db_pano_base = load_postgis(self.pano_node_pg)
        ori_size, new_size = db_pano_base.shape[0], gdf.shape[0]
        tmp = gdf.append(db_pano_base).drop_duplicates("ID", keep='first')

        if ori_size == tmp.shape[0]:
            return True

        return gdf_to_postgis(tmp, self.pano_node_pg)
def get_unvisited_point(panos, bbox=None, geom_wkt=None, buffer_dis=15, plot=True):
    osm_nodes = load_postgis('topo_osm_shenzhen_node', bbox=bbox, geom_wkt=geom_wkt)

    if panos is None or panos.shape[0]==0:
        return [ (i[0], i[1]) for i in  osm_nodes[['x','y']].values.tolist()]

    osm_nodes.loc[:, 'area'] = osm_nodes.to_crs(epsg=900913).buffer(buffer_dis).to_crs(epsg=4326)
    osm_nodes.reset_index(inplace=True)
    osm_nodes.set_geometry('area', inplace=True)

    visited = gpd.sjoin(left_df=osm_nodes, right_df=panos, op='contains')['index'].unique().tolist()
    res = osm_nodes.query( f"index not in {visited} " )
    
    if plot:
        map_visualize(res)

    return [ (i[0], i[1]) for i in  res[['x','y']].values.tolist()]
Beispiel #4
0
    def load_pano_node(self):
        print('loading pano data:')
        gdf = load_postgis(self.pano_node_pg, geom_wkt=self.geofence.to_wkt())

        lst_atts = ['MoveDir']
        for att in lst_atts:
            gdf.loc[:, att] = gdf[att].astype(np.float)

        lst_atts = [
            'ImgLayer',
            'Links',
            'SwitchID',
            'TimeLine',
            'Roads',
        ]
        for att in tqdm(lst_atts, "Transfer"):
            gdf.loc[:, att] = gdf[att].apply(eval)

        gdf.index = gdf.ID

        return gdf.to_dict('index')
Beispiel #5
0
def delete_history_error_dir_panos(download_new_pano=True, update=False):
    """
    Deleted photos with incorrect azimuth due to historical reasons
    """

    df_panos = load_postgis('panos')
    df_panos.set_index('PID', inplace=True)

    df_key_panos = load_postgis('pano_base')
    df_key_panos.set_index('ID', inplace=True)

    df_panos.loc[:, 'DIR_bak'] = df_panos.DIR
    df_panos = update_move_dir(df_panos, df_key_panos)

    rm_lst = df_panos.query("DIR != -1 and DIR != DIR_bak ").reset_index()[[
        'PID', 'DIR_bak'
    ]].values.tolist()

    remove_count = 0
    for pid, heading in tqdm(rm_lst):
        try:
            os.remove(os.path.join(PANO_FOLFER, f"{pid}_{heading}.jpg"))
            remove_count += 1
        except:
            continue

    print(f"Delete {remove_count} pano imgs")

    if download_new_pano:
        pano_imgs_exist = load_exist_pano_imgs()

        df_panos = df_panos.drop(
            columns=['DIR_bak', 'url']).reset_index().drop_duplicates(
                ['PID', 'DIR'])
        pano_lst = df_panos[['PID', 'DIR']].rename(columns={
            'PID': 'pid',
            'DIR': 'heading'
        })
        pano_lst = pano_lst.merge(pano_imgs_exist,
                                  left_on=['pid', 'heading'],
                                  right_on=['pid', 'dir'],
                                  how='left')
        pano_lst = pano_lst[pano_lst.fn.isna()][['pid',
                                                 'heading']].to_dict('records')

        fetch_pano_img_parallel(pano_lst)

    if update:
        df_panos = df_panos.set_index('PID')
        df_panos.loc[:, 'PID'] = df_panos.index
        df_panos.loc[:, 'url'] = df_panos.apply(
            lambda x: f"http://192.168.135.15:9000/panos/{x.PID}_{x.DIR}.jpg",
            axis=1)
        attrs_order = [
            'PID', 'DIR', 'RID', 'Order', 'Type', 'X', 'Y', 'geometry', 'url',
            'lane_num'
        ]

        gdf_to_postgis(df_panos[attrs_order], 'panos')

    return