Skip to content

Instantly share code, notes, and snippets.

@ChocopieKewpie
Created February 27, 2024 02:35
Show Gist options
  • Save ChocopieKewpie/3e9efde9163cebfde1854046c3205afe to your computer and use it in GitHub Desktop.
Save ChocopieKewpie/3e9efde9163cebfde1854046c3205afe to your computer and use it in GitHub Desktop.
Joining vectors
import os
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
folder_path = 'E:/DGGS_Benchmark/vectors'
# Get a list of all GPKG files in the folder
v_files = [file for file in os.listdir(folder_path) if file.endswith('.gpkg')]
v_files = sorted(v_files)
# Specify the number of files to open
num_files_to_open = 10
combined_df = gpd.read_file('E:/DGGS_Benchmark/vectors/vector_001.gpkg')
combined_df.columns = ['001', *combined_df.columns[1:]] #Setting the column to the file
output_directory= 'E:/DGGS_Benchmark/frames'
# Loop through each GPKG file and join
for file in v_files[1:num_files_to_open]:
file_path = os.path.join(folder_path, file)
col_name = file.split('_')[1].split('.')[0] # Extracting the column name from the file name
df = gpd.read_file(file_path)
df.columns = [col_name, *df.columns[1:]] #Setting the column to the file
combined_df = gpd.overlay(combined_df, df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment