New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin can't add a PostgreSQL view #86

Closed
Guts opened this Issue Dec 27, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@Guts
Member

Guts commented Dec 27, 2016

Reported by @siglagglo.

Problem

Trying to add a PostGIS view scanned by Isogeo raises an error popup syaing that the layer is not valid contrary to what QGIS log message says:

qgis_plugin_pgis_invalid

Diagnosis

In QGIS, a FeatureId is required to add a table to the map canvas. PostgreSQL versions anterior to 9.4.x don't allow to create equivalent to materialized views, so views are considered as lacking of a field key.

qgis_pgview_featureidrequired

Solution

It's an already known behavior (see: GIS SE 28743) and it's possible to to specify a field as FeatureId through PyQGIS API (see: API doc).

3 levels of solution are possible:

  1. a minimum must be to display a more complete error message
  2. automatically pass one of the view fields to PyQGIS as FeatureId, first considering fields name containing id or gid. Maybe it could reduce performance.
  3. replicate QGIS integrated PostGIS widget: show a drop-down list inviting the user to pick the field to consider as FeatureId. Ina perfect world, the option picked could be memorized to avoid repetitive required action.

@Guts Guts added this to the Version 2 milestone Dec 27, 2016

@Guts Guts added the bug label Dec 27, 2016

@Guts Guts modified the milestones: Version 1.5, Version 2 Jan 30, 2017

@Guts Guts self-assigned this Feb 27, 2017

Guts added a commit that referenced this issue Feb 27, 2017

@Guts

This comment has been minimized.

Show comment
Hide comment
@Guts

Guts Feb 27, 2017

Member

Bug fixed.

Solution implemented:

  1. check if layer is valid before adding it. and catching QGIS error msg
  2. if error message contains "postgis" and "prim" as ("primary key", "clé primaire"...), gets the layer fields list
  3. sorts the fields list to begin with field name containing "id"
  4. loops on fiield list and try to set as uriKeyColumn until to reach a valid layer
  5. if ok, add the layer. if not => error message

@vblanlot : bien tester et choisir si on enlève la contrainte de filtre "prim" qui n'est pas internationale (les messages d'erreurs de QGIS sont traduits).

Member

Guts commented Feb 27, 2017

Bug fixed.

Solution implemented:

  1. check if layer is valid before adding it. and catching QGIS error msg
  2. if error message contains "postgis" and "prim" as ("primary key", "clé primaire"...), gets the layer fields list
  3. sorts the fields list to begin with field name containing "id"
  4. loops on fiield list and try to set as uriKeyColumn until to reach a valid layer
  5. if ok, add the layer. if not => error message

@vblanlot : bien tester et choisir si on enlève la contrainte de filtre "prim" qui n'est pas internationale (les messages d'erreurs de QGIS sont traduits).

@Guts Guts closed this Feb 27, 2017

Guts added a commit that referenced this issue Mar 2, 2017

@Guts Guts added this to Archives in Roadmap Oct 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment