Hi John, Thanks for getting back to me.
The following commands are used to create the view (from a bash script), they include creating the unique index on station_no. QGIS is still unable to load the layer, despite listing it as a spatial table in the database. I have not tried using the station_no column as a primary key, which may make a difference, though it shouldn't. DB=tan2413.spdb # create unique constraint on station_no echo "drop index uniq_stn;" | spatialite $DB echo "create unique index uniq_stn on station(station_no);" | spatialite $DB # remove existing view & metadata before creating echo "drop view v_stat;" | spatialite $DB echo "delete from views_geometry_columns where view_name = 'v_stat';" | spatialite $DB # create view and register echo "create view v_stat as select station_no, startp from station;" | spatialite $DB echo "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);" | spatialite $DB So I still can't add a view in QGIS. Brent Wood Principal Technician, Fisheries NIWA DDI: +64 (4) 3860529 ________________________________ From: John Stevenson - BGS <jos...@bgs.ac.uk> Sent: Saturday, December 7, 2024 06:51 To: Brent Wood <brent.w...@niwa.co.nz>; 'Qgis-user@lists.osgeo.org' <qgis-user@lists.osgeo.org> Subject: RE: Help opening a Spatialite view in QGIS 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