Add basic_functions, import it in the split_layer_...
This commit is contained in:
parent
df8a0674a4
commit
0f81781a42
21
services_scripts/basic_functions.py
Normal file
21
services_scripts/basic_functions.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
|
||||
def create_folders(directory, num_folders):
|
||||
"""
|
||||
Create a specified number of folders in the given directory.
|
||||
|
||||
Args:
|
||||
- directory (str): The directory where folders will be created.
|
||||
- num_folders (int): The number of folders to create.
|
||||
"""
|
||||
# Check if the directory exists, if not, create it
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
# Create folders
|
||||
for i in range(num_folders):
|
||||
folder_name = f"layer_{i}"
|
||||
folder_path = os.path.join(directory, folder_name)
|
||||
os.makedirs(folder_path)
|
||||
print(f"Created folder: {folder_path}")
|
@ -2,6 +2,7 @@ from qgis.core import QgsApplication, QgsVectorLayer, QgsProject, QgsProcessingF
|
||||
from qgis.analysis import QgsNativeAlgorithms
|
||||
import processing
|
||||
import os
|
||||
from basic_functions import create_folders
|
||||
|
||||
|
||||
# This function loads a layer. It's used to count the data records
|
||||
@ -14,26 +15,6 @@ def load_layer(path, layer_name):
|
||||
return the_layer, layer_name
|
||||
|
||||
|
||||
def create_folders(directory, num_folders):
|
||||
"""
|
||||
Create a specified number of folders in the given directory.
|
||||
|
||||
Args:
|
||||
- directory (str): The directory where folders will be created.
|
||||
- num_folders (int): The number of folders to create.
|
||||
"""
|
||||
# Check if the directory exists, if not, create it
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
# Create folders
|
||||
for i in range(num_folders):
|
||||
folder_name = f"layer_{i}"
|
||||
folder_path = os.path.join(directory, folder_name)
|
||||
os.makedirs(folder_path)
|
||||
print(f"Created folder: {folder_path}")
|
||||
|
||||
|
||||
# Set the path to QGIS installation
|
||||
QgsApplication.setPrefixPath('C:/Program Files/QGIS 3.34.1/apps/qgis', True)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user