[GIS] How to update postgis layer from shapefile in QGIS

loadingpostgresqlqgisshapefileupdate

My usual workflow with updating layer from shapefile was to:

Open DB Manager;

  1. Load SHP files into QGIS;
  2. Open DB Manager;
  3. Import file (with drop option).

Now my problem is that I have created views on data in Postgresql and I can't just drop that table any more. Now my question would be:

If I can't drop tables any more how to effectively update PostGIS layer from SHP file ?

Since this is a point layer I currently make select by location / invert to get points not included in PostGIS layer.

Is there any effective solution to automate this proces or even better is there graphical tool to update PostGIS layer from SHP maybe based on attribute join / location checking?

Thanks !

Best Answer

I finally managed to resolve my problem. My solution was to load data into temporary spatial table on PostGIS server, delete all records from table and then insert all records from temporary table to database.

DELETE FROM public.target_table;

INSERT INTO public.target_table

SELECT * FROM public.source_temporary_table;

All you need is a table with same columns and geometry type.

I hope this helps someone.

Related Question