Skip to content
Advertisement

Using Triggers in PGAdmin4 v5 to get the geom of a line being generated in QGIS

So I have a database of pipes that is visually coded in qgis. My goal is to add a trigger to PGAdmin4 v5 that uses ST_StartPoint() and ST_EndPoint() to get the end points of the polyline (the pipe) as it is being entered. Then, I was going use this geometry to grab the nearest structure (a point) and autocomplete two columns with corresponding data. I have working code that gets me the endpoints of existing pipes and finds the nearest structures, but I want to use the newly created lines (the pipes) to complete the form automatically as it is being entered into the database.

Working Code:

I need to figure out how to get data from an update (adding an entry to qgis) and use its geometry instead of the geometry of existing pipes.

Advertisement

Answer

Just put this query into a function ..

And attach a trigger to it, e.g. a BEFORE INSERT OR UPDATE trigger:

This demo might give you some hints: db<>fiddle

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement