Saturday, 4 November 2017

Making spatial view in PostGIS and adding it as layer in QGIS?


In PostGIS 2.0, I am seeking an efficient way to create a spatially enabled view that is viewable in QGIS.


I followed the context of Part 2 of @Mike Toews answer to How to create a table from existing tables (applying new schemas) in postgis DB?, and the view shows up as a point layer (in my case) in the "Add PostGIS Layers" dialog. But after creating the view and spatially enabling it, I received the following error when trying to add the view to QGIS:




You must select a table in order to add a layer



Can someone explain why the spatial view will not load into QGIS, and what I need to do in order to make it loadable as a layer in QGIS?


I'm currently using QGIS v1.8 from the OSGEO installer


I view is built from the geonames database, loaded into PostGIS. The geoname table/spatial data can be selected/viewed in QGIS just fine.


When I try to select the "mt_view", QGIS sees the view in the dialog, but won't let me select it. It gives a dotted box around the area, but does not highlight and select the view.


QGIS cannot select the mt_view as a layer




I just noticed that when I run my first query:


CREATE OR REPLACE VIEW data.test AS

SELECT * FROM data.geoname
WHERE admin1='MT'

the view shows up in the QGIS Add Layer Dialog, but is unselectable. Then when I run:


SELECT Populate_Geometry_Columns('data.test'::regclass);

I get the result of "0", where according to the documentation, I think it should be returning "1".



Answer



I can confirm that it is not possible to simply select a listed view.


It seems necessary to select the "primary key column" first. Then the table turns selectable:



enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...