Convert to csv

This commit is contained in:
Alireza Adli 2024-09-25 16:46:02 -04:00
parent 2955451a5d
commit dac51051ba
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
from scrub_layer_class import *
import pandas as pd
qgis_path = 'C:/Program Files/QGIS 3.34.1/apps/qgis'
cmm_path = \
'C:/Users/a_adli/PycharmProjects/cmm_gis_oo/' \
'data/output_data/cmm_points_function_vintage_surface/' \
'cmm_points_function_vintage_surface.shp'
cmm = ScrubLayer(qgis_path, cmm_path, 'QC GDTable')
field_names = ['id_provinc', 'mat_18', 'code_util', 'superficie',
'nom_etage', 'anne_cnstr', 'supfi_etag', 'typ_btmn', 'nom_logm']
# Get the indices of the specified fields
field_indices = [cmm.layer.fields().indexOf(field) for field in field_names]
# Extract the attribute values and store them in a list of dictionaries
data = []
for feature in cmm.layer.getFeatures():
attributes = [feature.attributes()[index] for index in field_indices]
data.append(dict(zip(field_names, attributes)))
# Create a DataFrame from the list of dictionaries
df = pd.DataFrame(data)
df.to_csv('../data/csv_files/cmm_points_function_vintage_surface.csv',
index=False)