简体   繁体   English

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

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

I'm walking through a directory structure finding all files with the .shp extension and storing them in a dictionary.我正在浏览一个目录结构,查找所有扩展名为 .shp 的文件并将它们存储在字典中。 However, some files are named the same, how do I store files of the same name in a dictionary without overwriting?但是,有些文件的名称相同,如何在不覆盖的情况下将同名文件存储在字典中? Appending the file structure to the name would be acceptable in this case.在这种情况下,将文件结构附加到名称是可以接受的。 How is that done?这是怎么做的?

Current 'working' code:当前的“工作”代码:

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.

相关问题 具有 .dbf、.prj、.shp 和 .shx 文件时如何在 geopandas 中读取 shapefile? - How to read shapefile in geopandas when having .dbf, .prj, .shp and .shx files? Geopandas 在 for 循环中读取 gdb 层名称到对象 - Geopandas reading gdb layer name to object in for loop AttributeError:在邮政编码 shp 文件中绘制事件的 Geopandas 中的未知属性列 - AttributeError: Unknown property column in Geopandas plotting of events in zipcode shp file 读取 geopandas 的数据集 - Reading datasets for geopandas 将文本文件读入 Python 字典列表 - Reading text files into a python list of dictionary Python - 通过读取文本文件和搜索该字典来创建字典 - Python - Creating Dictionaries by reading text files and searching through that dictionary 按线路名称和地理位置对GeoPandas进行排序 - Sort GeoPandas by Name Of Line And By Geographic Location 如果名称相同,则将 2 个目录中的同名文件过滤到第三个文件夹中 - Filtering files with same name from 2 directories into third folder if the name is same 如何创建字典外的列表,其名称与字典键相同,并且大小与该键的值相同? - How do I create lists out of dictionary, having same name as dictionary keys and same size as value of that key? GeoPandas dataFrame 使用 iterrows() 用列数据填充字典 - GeoPandas dataFrame using iterrows() to fill a dictionary with column data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM