On QGis, I have a series of points that I want to transform into a path, with the qgis tool "from points to path". these points, in their attributes table, have a column called Time, expressed like this e.g. 140370.908. another called Image expressed like this e.g. VAL_ISARCO_01\LadybugPanoramas\T20241007145532891.jpg. before the extension .jpeg the filename seems to express a date and time fraction
This fields are usually constant sometimes, instead, they differ by a tot in its sequentiality. e.g. 140370.908 up to Point 140371.812. when i encounter this, with a gap between two valors kinda high, the tool "from points to path" generates me an artifactual connection line. It is because of this gap, between the two values (of 2127 for this layer). what I would like to do, in the presence of the gap, is to make 140370.908 for example the last vertex of a part of the path and 140371.812 the first beginning vertex of a new line. just to avoid the creation of artifacts. or TO AVOID THIS UNWANTED CONCATENTION. the points-to-path tool allows regex input maybe it can be done that way. i dont want to manully reve all the unwanted lines obviously as it could take me forever. Be careful.
i can paste you the 2127 field attribute table to find a time path
Assistant
To resolve the issue of unwanted artifact lines when converting your points to paths in QGIS, you'll need to intelligently group your points based on the Time attribute. This ensures that significant gaps in time result in separate paths rather than continuous ones. Here's a step-by-step guide to achieve this:
1. Define the Time Gap Threshold
First, determine what constitutes a "significant" gap in your Time values. For example, if a gap of more than 1 (based on your Time format like 140370.908) is considered significant, you can set this as your threshold. Adjust this value based on your specific dataset and requirements.
2. Sort Your Points by Time
Ensure your point layer is sorted in ascending order based on the Time attribute. This is crucial for accurately identifying gaps between consecutive points.
Open the Attribute Table:
Right-click on your point layer and select Open Attribute Table.
Sort by Time:
Click on the header of the Time column to sort the table. Ensure it's sorted in ascending order.
3. Create a Group Identifier Based on Time Gaps
You'll need to create a new field that assigns a unique group ID to sequences of points without significant time gaps. When a gap exceeds your threshold, the group ID increments, signaling the start of a new path.
Open Field Calculator:
In the attribute table, click on the Field Calculator icon.
Create a New Field:
Check "Create a new field".
Name the field (e.g., group_id).
Set the Output field type to Whole number (integer).
Use Virtual Layer for Advanced Calculation:
QGIS's standard Field Calculator doesn't support accessing previous rows directly. Instead, use a Virtual Layer with an SQL query to compute the group IDs.
a. Create a Virtual Layer:
Go to Layer > Add Layer > Add/Edit Virtual Layer.
b. Write the SQL Query:
Replace your_point_layer with the actual name of your point layer.
sql
SELECT
a.*,
SUM(case when (a.Time - b.Time) > 1 then 1 else 0 end) OVER (ORDER BY a.Time) as group_id
FROM
your_point_layer a
LEFT JOIN
your_point_layer b
ON
a.Time > b.Time
WHERE
NOT EXISTS (
SELECT 1 FROM your_point_layer c
WHERE c.Time > b.Time AND c.Time < a.Time
)
ORDER BY
a.Time
Explanation:
This query assigns a group_id that increments each time there's a gap greater than 1 in the Time field.
c. Add the Virtual Layer:
After writing the query, click OK to add the Virtual Layer to your project.
Verify the Group IDs:
Open the attribute table of the Virtual Layer and ensure that group_id increments appropriately where significant time gaps exist.
4. Convert Points to Paths Using Group IDs
Now that each point has an associated group_id, you can use this to create separate paths for each group.
Open the "Points to Path" Tool:
Go to Processing Toolbox (you can open it from Processing > Toolbox).
Search for "Points to Path" and open it.
Configure the Tool:
Input Layer: Select your Virtual Layer with the group_id.
Order Field: Choose Time to ensure points are connected in chronological order.
Group Field: Select group_id to separate paths based on your defined groups.
Output Path Layer: Specify where to save the resulting paths.
Run the Tool:
Click Run to execute the tool. This will generate a new line layer with paths that respect the defined time gaps, eliminating unwanted artifact connections.
5. (Optional) Automate Group ID Assignment with Python
If you're comfortable with Python and QGIS's PyQGIS API, you can automate the group ID assignment process, especially for large datasets. Here's a simplified script outline:
python
from qgis.PyQt.QtCore import QVariant
from qgis.core import QgsProject, QgsField, QgsFeature, QgsExpression
layer = QgsProject.instance().mapLayersByName('your_point_layer')[0]
# Sort features by Time
features = sorted(layer.getFeatures(), key=lambda f: f['Time'])
group_id = 0
previous_time = None
group_ids = []
threshold = 1 # Define your threshold here
for feat in features:
current_time = feat['Time']
if previous_time is not None:
if (current_time - previous_time) > threshold:
group_id += 1
group_ids.append(group_id)
previous_time = current_time
# Add the group_id field
layer.startEditing()
layer.dataProvider().addAttributes([QgsField('group_id', QVariant.Int)])
layer.updateFields()
# Assign group IDs
for feat, gid in zip(layer.getFeatures(), group_ids):
layer.changeAttributeValue(feat.id(), layer.fields().indexFromName('group_id'), gid)
layer.commitChanges()
Note: Replace 'your_point_layer' with the actual name of your point layer and adjust the threshold as needed.
6. Final Verification
Inspect the Paths:
Once the paths are created, visually inspect them to ensure that the gaps are correctly handled and no unwanted lines are present.
Adjust if Necessary:
If you notice any issues, revisit the threshold value or the group ID assignment logic to make necessary adjustments.
Summary
By grouping your points based on significant gaps in the Time attribute and then converting these groups into separate paths, you can effectively eliminate artifact lines. This method leverages QGIS's powerful data manipulation and processing capabilities to automate what would otherwise be a tedious manual task.
If you encounter any issues or need further assistance with specific steps, feel free to provide more details, and I'll be happy to help!