繁体   English   中英

将 shp 文件读取到 geopandas 到具有相同名称的字典

[英]reading shp files to geopandas to dictionary with the same name

我正在浏览一个目录结构,查找所有扩展名为 .shp 的文件并将它们存储在字典中。 但是,有些文件的名称相同,如何在不覆盖的情况下将同名文件存储在字典中? 在这种情况下,将文件结构附加到名称是可以接受的。 这是怎么做的?

当前的“工作”代码:

def get_all_shp(mydir):
    # layers = []
    data = {}
    for root, dirs, files in os.walk(mydir):
        for file in files:
            try:
                if file.endswith(".shp"):
                    shp = os.path.join(root, file)
                    # layers.append(shp)
                    path = root + "/" + file
                    # print("path: " + path)
                    data[file] = gpd.read_file(path)

            except:
                pass
def get_all_shp(mydir):
    # layers = []
    data = {}
    for root, dirs, files in os.walk(mydir):
        for file in files:
            try:
                if file.endswith(".shp"):
                    shp = os.path.join(root, file)
                    # layers.append(shp)
                    path = root + "/" + file
                    # print("path: " + path)
                    data[path] = gpd.read_file(path)
            except:
                pass

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM