Skip to content
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

qgepdss/export.py - rohrprofil_geometry etc. add if filtered #144

Merged
merged 115 commits into from
Jul 18, 2024

Conversation

sjib
Copy link
Contributor

@sjib sjib commented May 14, 2024

Missing filter for selection in INTERLIS export configuration:

  • rohrprofil_geometrie

First test to solve QGEP/QGEP#856

@sjib sjib added the fix label May 14, 2024
@sjib sjib added this to the 1.6.2 - 2024.1 milestone May 14, 2024
@sjib
Copy link
Contributor Author

sjib commented May 14, 2024

@urskaufmann Can you copy this adaption to your installation and test? If ok I will work on other missing classes.

@urskaufmann
Copy link

urskaufmann commented May 14, 2024

not ok. Sorry, the "correct" error is here:

Ein Fehler trat bei der Ausführung von Python-Code auf:

sqlalchemy.exc.InvalidRequestError: Don't know how to join to . Please use the .select_from() method to establish an explicit left side, as well as providing an explcit ON clause if not present already to help resolve the ambiguity.
Traceback (most recent call last):
File "C:\Users/KAU/AppData/Roaming/QGIS/QGIS3\profiles\qgep161_prerealise/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\gui_init_.py", line 613, in action_do_export
qgepdss_export(selection=export_dialog.selected_ids, labels_file=labels_file_path, orientation=eorientation)
File "C:\Users/KAU/AppData/Roaming/QGIS/QGIS3\profiles\qgep161_prerealise/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\qgepdss\export.py", line 2086, in qgep_export
query = query.join(
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\query.py", line 2391, in join
return self._join(
File "", line 2, in _join
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\base.py", line 227, in generate
fn(self, *args[1:], **kw)
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\query.py", line 2587, in _join
self._join_left_to_right(
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\query.py", line 2611, in _join_left_to_right
) = self._join_determine_implicit_left_side(left, right, onclause)
File "C:\PROGRA~1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\query.py", line 2756, in _join_determine_implicit_left_side
raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Don't know how to join to . Please use the .select_from() method to establish an explicit left side, as well as providing an explcit ON clause if not present already to help resolve the ambiguity.

Python-Version: 3.9.18 (heads/master:5eba59e, Feb 1 2024, 20:02:10) [MSC v.1929 64 bit (AMD64)]
QGIS-Version: 3.34.4-Prizren Prizren, decd43dc

@sjib
Copy link
Contributor Author

sjib commented May 15, 2024

@urskaufmann rohrprofil_geometrie is not directly connected with reach - I have to adjust the join:
1051_klassendiagramm_2020_auszug

Add whole line of references to wastewater_networkelement
@sjib
Copy link
Contributor Author

sjib commented May 15, 2024

@urskaufmann Can you test again with the updated join statement?

@sjib
Copy link
Contributor Author

sjib commented May 15, 2024

I used this example as role model for a join with several classes:

    logger.info("Exporting QGEP.dryweather_downspout -> ABWASSER.trockenwetterfallrohr, ABWASSER.metaattribute")
    query = qgep_session.query(QGEP.dryweather_downspout)
    if filtered:
        query = query.join(QGEP.wastewater_structure, QGEP.wastewater_networkelement).filter(
            QGEP.wastewater_networkelement.obj_id.in_(subset_ids)
        )

@urskaufmann
Copy link

There is another error. Seems that the pipe_profile - code now works.
Special: there is for sure no Anschlussobjekt connected to the 6 reaches and there nodes that I have selected to start...

Ein Fehler trat bei der Ausführung von Python-Code auf:

sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) insert or update on table "anschlussobjekt" violates foreign key constraint "anschlussobjekt_abwassernetzelementref_fkey" DETAIL: Key (abwassernetzelementref)=(546) is not present in table "abwassernetzelement". (Background on this error at: http://sqlalche.me/e/13/gkpj)
Traceback (most recent call last):
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 771, in _commit_impl
self.engine.dialect.do_commit(self.connection)
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\default.py", line 561, in do_commit
dbapi_connection.commit()
psycopg2.errors.ForeignKeyViolation: insert or update on table "anschlussobjekt" violates foreign key constraint "anschlussobjekt_abwassernetzelementref_fkey"
DETAIL: Key (abwassernetzelementref)=(546) is not present in table "abwassernetzelement".

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users/KAU/AppData/Roaming/QGIS/QGIS3\profiles\qgep161_prerealise/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\gui_init_.py", line 613, in action_do_export
qgepdss_export(selection=export_dialog.selected_ids, labels_file=labels_file_path, orientation=eorientation)
File "C:\Users/KAU/AppData/Roaming/QGIS/QGIS3\profiles\qgep161_prerealise/python/plugins\qgepplugin\qgepqwat2ili\qgepqwat2ili\qgepdss\export.py", line 3613, in qgep_export
abwasser_session.commit()
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\session.py", line 1046, in commit
self.transaction.commit()
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\orm\session.py", line 508, in commit
t[1].commit()
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1762, in commit
self._do_commit()
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1793, in _do_commit
self.connection.commit_impl()
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 773, in _commit_impl
self._handle_dbapi_exception(e, None, None, None, None)
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1510, in handle_dbapi_exception
util.raise
(
File "C:\PROGRA~1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\util\compat.py", line 182, in raise

raise exception
File "C:\PROGRA1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 771, in _commit_impl
self.engine.dialect.do_commit(self.connection)
File "C:\PROGRA
1\QGIS3\apps\Python39\lib\site-packages\sqlalchemy\engine\default.py", line 561, in do_commit
dbapi_connection.commit()
sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) insert or update on table "anschlussobjekt" violates foreign key constraint "anschlussobjekt_abwassernetzelementref_fkey"
DETAIL: Key (abwassernetzelementref)=(546) is not present in table "abwassernetzelement".

(Background on this error at: http://sqlalche.me/e/13/gkpj)

@sjib
Copy link
Contributor Author

sjib commented May 16, 2024

@urskaufmann The reason is, that we do not have defined a filter criteria for Anschlussobjekte and subclasses:

    logger.info("Exporting QGEP.building -> ABWASSER.gebaeude, ABWASSER.metaattribute")
    query = qgep_session.query(QGEP.building)
    for row in query:

With the current configuration all Anschlussobjekt (Brunnen, Einzelflaechen, Gebaeude, Reservoir) will be exported, even if they are not attached to a selected Abwassernetzelement.

@urskaufmann
Copy link

then nobody will be able to export a dss-selection if there are this filter missing, because the unfiltered records will in most cases have foregin keys to elements, that are not in the selection, and there we will get always an error.

If the export of a selection should be an option, then all this filter have to be set.
At least for those tables, that are also in DSS 2020. (If somebody really has data in Subsystem Gewässer, he can not use the selection-export)

@sjib sjib changed the title qgepdss/export.py - rohrprofil_geometry add if filtered qgepdss/export.py - rohrprofil_geometry etc. add if filtered Jun 3, 2024
@ponceta ponceta merged commit 48c8a7f into master Jul 18, 2024
4 checks passed
@ponceta ponceta deleted the 2024-05-14-add-missing-filters-interlis-export branch July 18, 2024 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants