Hi Brent,

I've often found that the problem with views has come from the id column.  Does 
the integer "station_no" column have a unique constraint?  It may need one.

I put some notes on Spatialite views in this Stack Exchange answer a few years 
ago.

https://gis.stackexchange.com/a/301444/64762

John

From: QGIS-User <qgis-user-boun...@lists.osgeo.org> On Behalf Of Brent Wood via 
QGIS-User
Sent: 05 December 2024 21:53
To: 'Qgis-user@lists.osgeo.org' <qgis-user@lists.osgeo.org>
Subject: [Qgis-user] Help opening a Spatialite view in QGIS

Hi,

I have created a view in a spatialite database, but am unable to open it in 
QGIS.

I can't find any documentation on how this works.

I have a table "stations" which contains a station_no column (integer) and a 
point geometry column (startp, EPSG 4326).

The view is created by:
create view v_stat as select station_no, startp from station;


I add an entry to the Spatialite views_geometry_columns table to populate the 
metadata describing the view.
insert into views_geometry_columns
        (view_name, view_geometry, view_rowid, f_table_name, f_geometry_column, 
read_only)
      values
        ('v_stat', 'startp', 'station_no', 'station', 'startp', 1)

QGIS now lists the view correctly as a table with a geometry & lists startp as 
the geometry, but when I try to open it, I just get an "invalid layer" error 
message.

 dbname='/home/baw/tan2413/tan2413.spdb' table="v_stat" (startp) is an invalid 
layer - not loaded


Can anyone tell me how to set up a Spatialite view so it can be successfully 
opened in QGIS?


Thanks

Brent Wood

Principal Technician, Fisheries
NIWA
DDI:  +64 (4) 3860529
[Image removed by sender.]<https://www.niwa.co.nz/>
Brent Wood
Principal Technician - GIS and Spatial Data Management
Programme Leader - Environmental Information Delivery
+64-4-386-0529

National Institute of Water & Atmospheric Research Ltd (NIWA)
301 Evans Bay Parade Hataitai Wellington New Zealand
Connect with NIWA: niwa.co.nz<https://www.niwa.co.nz> 
Facebook<https://www.facebook.com/nzniwa> 
LinkedIn<https://www.linkedin.com/company/niwa> 
Twitter<https://twitter.com/niwa_nz> 
Instagram<https://www.instagram.com/niwa_science> 
YouTube<https://www.youtube.com/channel/UCJ-j3MLMg1H59Ak2UaNLL3A>
To ensure compliance with legal requirements and to maintain cyber security 
standards, NIWA's IT systems are subject to ongoing monitoring, activity 
logging and auditing. This monitoring and auditing service may be provided by 
third parties. Such third parties can access information transmitted to, 
processed by and stored on NIWA's IT systems.
Note: This email is intended solely for the use of the addressee and may 
contain information that is confidential or subject to legal professional 
privilege. If you receive this email in error please immediately notify the 
sender and delete the email.


This email and any attachments are intended solely for the use of the named 
recipients. If you are not the intended recipient you must not use, disclose, 
copy or distribute this email or any of its attachments and should notify the 
sender immediately and delete this email from your system. UK Research and 
Innovation (UKRI) has taken every reasonable precaution to minimise risk of 
this email or any attachments containing viruses or malware but the recipient 
should carry out its own virus and malware checks before opening the 
attachments. UKRI does not accept any liability for any losses or damages which 
the recipient may sustain due to presence of any viruses.

_______________________________________________
QGIS-User mailing list
QGIS-User@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to