Wednesday 20 November 2019

Can QGIS Read Spatialite Views?



I have a spatialite database I created that spans several years of crime data. To facilitate a real-world scenario where I may simplify the interaction for a user by introducing a View that simply limits the time span or what types of crimes are returned, I want to know if it is possible for QGIS to read this View like it would any other spatial table in my database. The point here is that I obviously do not want to create a separate table for every possible View I may use, and I am trying to make it simple by not requiring the user to know the database and the appropriate SQL to subset the data themselves. A similar workflow in the ArcGIS world might be creating separate layer files that the user could open in ArcMap that access the database (say, SQL Server) and present only the limited data set.


I created a View in my database, but it does not show up in the list of feature classes I can import when I connect to the spatialite db in QGIS. Maybe Views aren't considered spatial? (This is something I'm going to look into later, but I thought I already did; I just don't recall the conclusion.) In any case, how might one replicate the sort of work flow I want or the similar ArcGIS alternative?



Answer



I think you have to register the view in geometry_columns table to be able to use it in QGIS.


A good resource is "Hand-writing your own Spatial VIEW" with the following example:



INSERT INTO views_geometry_columns
(view_name, view_geometry, view_rowid, f_table_name, f_geometry_column)
VALUES ('italy', 'geometry', 'ROWID', 'local_councils', 'geometry');


Anyway you must register this VIEW into the views_geometry_columns, so to make it become a real Spatial View.



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...