2

enter image description here

I have multiple ".xyz" format coordinate files (50 files), I want to merge or combine all these 50 files into one ".xyz" format file. Above image shows how my date look like.

Is there any plug-in available in QGIS?

I have tried "r.out.xyz" command in QGIS GRASS, but it is not combining my multiple dataset, I have jut got an empty file as an output.

0

1 Answer 1

1

Copy the code below and insert it in the Python console within QGIS: Replace the path C:\Users\Username with your path the .xyz files are stored

import os
import pandas as pd

#enter path with .xyz files here --> # replace C:\Users\Username with the path where all files are stored
path = r'C:\Users\Username\\'

x = [a for a in os.listdir(path) if a.endswith(".xyz")]

for i in x:
    df = pd.read_csv(path + i, sep=' ', error_bad_lines=False)
    df_new = df.append(df, ignore_index=True)

#new file is written to same directory
df_new.to_csv(path + 'dgm_merged.xyz', sep=' ')
9
  • are you sure every file has same columns? Sep 21, 2021 at 11:12
  • yes, i have checked it Sep 21, 2021 at 11:18
  • run line by line and tell when the error occurs. Have you tried using another script platform such as Jupyter Notebook from Anaconda distribution? Sep 21, 2021 at 11:19
  • I did try to run in in Python IDEL, but it is not working either. I think the script is not importing pandas as pd Sep 21, 2021 at 11:29
  • 1
    For me the code works but the merged file is no longer readable by QGIS (Version 3.24). Do xyz-files need the coordinates in the filename like HGT ones do? Mar 14, 2022 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.