[QGIS-Developer] Issues with QgsProcessingParameterFeatureSource

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[QGIS-Developer] Issues with QgsProcessingParameterFeatureSource

C Hamilton
I'm trying to convert one of my Shape Tools algorithms to a processing algorithm. My existing input layer either accepts a point vector layer or a NoGeometry table. I was guessing that the proper way to implement this is:

self.addParameter(
    QgsProcessingParameterFeatureSource(
        self.PrmInputLayer,
        'Input layer',
        [QgsProcessing.TypeFile, QgsProcessing.TypeVectorPoint])
)

TypeFile seems to do nothing. It certainly does not show the CSV file I have loaded that has no geometry. It filters the files so that only point layers are available. Interestingly if I use just TypeFile it seems to select all vector layer types.

Thanks,

Calvin Hamilton



_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Issues with QgsProcessingParameterFeatureSource

Nyall Dawson
"
On Sat, 7 Jul 2018 at 03:26, C Hamilton <[hidden email]> wrote:

>
> I'm trying to convert one of my Shape Tools algorithms to a processing algorithm. My existing input layer either accepts a point vector layer or a NoGeometry table. I was guessing that the proper way to implement this is:
>
> self.addParameter(
>     QgsProcessingParameterFeatureSource(
>         self.PrmInputLayer,
>         'Input layer',
>         [QgsProcessing.TypeFile, QgsProcessing.TypeVectorPoint])
> )
>
> TypeFile seems to do nothing. It certainly does not show the CSV file I have loaded that has no geometry. It filters the files so that only point layers are available. Interestingly if I use just TypeFile it seems to select all vector layer types.

TypeFile is not correct here - from the docs, TypeFile = "Files (i.e.
non map layer sources, such as text files)". There's actually no way
to show only Point layers OR Geometry-less tables. The closest is
TypeVector, which will show all vector sources, including
points/line/polygons AND no geometry tables.

But -- I'd question why you'd want to restrict your algorithm inputs
to Point/NoGeometry only in the first place. If your algorithm can
work with NoGeometry tables, it should also work with inputs with
Lines and Polygon geometries, and just ignore those. Otherwise you're
putting an artificial limitation on the inputs which can be used,
which is sure to annoy users somewhere down the line!

Nyall
_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Issues with QgsProcessingParameterFeatureSource

C Hamilton
The function I am working with is the XY to Line utility which expects each record in the data to have two location points. This could be in the form of just a NoGeometry table with two coordinates as part of the fields or it could be a point layer with one of the points represented by the layer geometry and the other within the table data. I guess I will need to open it up to include Lines and Polygons, but I don't think the source of this data would ever be a line or polygon, but who knows what users may do.

On Fri, Jul 6, 2018 at 8:38 PM, Nyall Dawson <[hidden email]> wrote:
"
On Sat, 7 Jul 2018 at 03:26, C Hamilton <[hidden email]> wrote:
>
> I'm trying to convert one of my Shape Tools algorithms to a processing algorithm. My existing input layer either accepts a point vector layer or a NoGeometry table. I was guessing that the proper way to implement this is:
>
> self.addParameter(
>     QgsProcessingParameterFeatureSource(
>         self.PrmInputLayer,
>         'Input layer',
>         [QgsProcessing.TypeFile, QgsProcessing.TypeVectorPoint])
> )
>
> TypeFile seems to do nothing. It certainly does not show the CSV file I have loaded that has no geometry. It filters the files so that only point layers are available. Interestingly if I use just TypeFile it seems to select all vector layer types.

TypeFile is not correct here - from the docs, TypeFile = "Files (i.e.
non map layer sources, such as text files)". There's actually no way
to show only Point layers OR Geometry-less tables. The closest is
TypeVector, which will show all vector sources, including
points/line/polygons AND no geometry tables.

But -- I'd question why you'd want to restrict your algorithm inputs
to Point/NoGeometry only in the first place. If your algorithm can
work with NoGeometry tables, it should also work with inputs with
Lines and Polygon geometries, and just ignore those. Otherwise you're
putting an artificial limitation on the inputs which can be used,
which is sure to annoy users somewhere down the line!

Nyall


_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer