Geographic Information Systems Asked by Techie_Gus on July 6, 2021
I am in the process of populating a PostGIS database from a bunch of shapefiles loaded in a QGIS project. The field names of the shapefiles don’t match those in the database so it is not possible to use the built-in loader. So I was trying to use an INSERT query in the DB Manager to do so. However, it seems that the DB manager has either a DB scope or a virtual layer scope, and it does not seem possible to copy from a project file to a database table by mapping the field names to each other.
I used a query that goes along this form:
INSERT INTO public.table (field1, field2, geom)
SELECT field_one, field_two, geometry FROM project_layer
Is there a workaround that allows using a SQL query in the DB manager to INSERT features from a project layer into a PostGIS table?
You could look at Refactor fields tool in the QGIS processing toolbox. With that you can map the fields in your shapefile to match the ones in your table. Load the target table to your project and use that as the template layer and use your shapefiles as the input layer. You can also use QGIS expressions to convert data on the fly if necessary. The tool then creates a temporary (or on disk) file from your mapped data which can be uploaded to PostGIS with the built-in tools.
Answered by tjukanov on July 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP