GIScience / orstools-qgis-plugin

Plugin for QGIS with a set of tools to use openrouteservice API´s, based on openstreetmap
https://plugins.qgis.org/plugins/ORStools/
MIT License
91 stars 31 forks source link

Isochrones from layer: save to geopackage only keeping one feature #126

Closed Velocity-TP closed 3 years ago

Velocity-TP commented 3 years ago

Here's what I did

I ran the "Isochrones from layer" batch job using a point layer with one feature as the input, and the following parameters:

Isochrones from Layer Input layer ID Field: fid Travel mode: Cycling-regular (also occurs with other modes) Dimension: time Ranges: 5, 10, 15 Isochrones: Save to GeoPackage


Here's what I got

2021-01-22T10:10:54 INFO url: https://api.openrouteservice.org/v2/isochrones/cycling-regular? Parameters: { "attributes": [ "total_pop" ], "range_type": "time", "range": [ 300, 600, 900 ], "locations": [ [ -0.103824, 51.508222 ] ], "id": 1 }

The algorithm runs correctly (I get a "Algorithm 'Isochrones From Layer' finished" message). However, the output layer only contains one feature (in this case the 15 minute isochrone).

I can replicate the problem by first running the algorithm and using the "[Create temporary layer]" option in the Isochrones parameter box. When I look in the attribute table of the new isochrone scratch layer, the fid of all three features is 1. This then results in the following issue when saving as a geopackage:

Could not make temporary scratch layer permanent. Error: Feature write errors: Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: Cycle_Isochrones.fid) Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: Cycle_Isochrones.fid) Only 1 of 3 features written. This issue only seems to occur when selecting the input layer's fid as the 'Input layer ID field'. I created a new field in the input layer and used that for the 'Input layer ID field' parameter, and the issue did not occur.


Here's what I was expecting

I was expecting a geopackage layer with three features to be saved when running an isochrone on a point layer.


Here's what I think could be improved

I'd like to be able to run the 'Isochrones From Layer' algorithm on a point layer with one feature and only one field (fid=1), return multiple isochrone features and save to Geopackage.

nilsnolde commented 3 years ago

That's a limitation of geopackage/qgis, not the plugin. Basically, never use fid as an ID, ever. QGIS takes that from the driver backend and the handling can cause various headaches. It's one of the reasons why it's not really exposed either, it's internal, not a public API.

Velocity-TP commented 3 years ago

Ok that's great to know, thanks Nils!