On Wed, 13 Nov 2013 02:48:27 +0100, Stefan Keller wrote:
> I can't follow your reasoning why it should'nt be possible to have
> views with differing geometry type as in the original table.
>
Hi Stefan,
I wasn't saying at all that it's not possible to create a plain normal
View returning a different geometry; it's obviously possible, even
using SQLite + SpatiaLite.
What I was exactly saying was that in such circumstances it's not
possible registering a "Spatial View"; and consequently visualizing
(e.g. on QGIS) a View applying any kind of modification of the
original Geometry is not a currently supported option.
> Geometry functions like ST_Centroid() have a defined output geometry
> type. So there's no need guessing.
>
absolutely true, I fully agree with you.
> I quickly tested the above Towns view example with PostGIS - it works
> there as expected:
>
> -- Create view with geometry type point (from ST_Centroid)
>
> create view v_towns as
> select PK_UID as ROWID, "Name" as "Name", ST_Centroid(Geometry) as
> Geometry
> from Towns;
> -- (Registering SQL command ommited...)
>
> -- ST_X only works on Points (so Geometry is of geometry type Point)!
> select ST_X(Geometry) from Towns;
>
> --> ERROR: Argument to X() must be a point
> select rowid, ST_X(Geometry) from v_towns;
>
> --> OK
>
> select distinct geometrytype(Geometry) from v_towns;
>
> --> All of geometry type Point!
>
certainly yes; and exactly the same will happen using SpatiaLite.
This one is not a problem directly related to SQL as such; it's a
problem arising from the QGIS data provider current implementation.
When an user connects any generic vector datasource to QGIS, the
data provider is expected to immediately report to the main app:
- a precisely identified Geometry Type
- a SRID
- a full extent Bounding Box
- if the datasource is read-only or read-write
- if there is any supporting Spatial Index
If the data source is directly supported by some kind of metadata
this is an obviously trivial task just requiring micro-seconds.
If no metadata are available, then the unique viable approach is
the one to perform a full table scan directly exploring the whole
datasource from start to end.
If the generic View to be preliminary checked does actually
return some million features (may be requiring to compute some
computationally heavy SQL function such as ST_Transform,
ST_Buffer or ST_Union, or possibly a mix of all them), then
you'll probably discover that any single connection attempt
will probably require many long minutes, leaving QGIS completely
frozen in the meanwhile.
It doesn't look to be a reasonable design approach.
Using a "registered View" surely has its limitations (you cannot
change the original input geometry in any way), but at least has
the strong advantage that it allows to visualize on QGIS any Spatial
View exactly as it was a read-only Table, this including supporting
an eventually available Spatial Index (inherited from the parent
Geometry).
It certainly isn't a perfect solution covering any possible case,
but it's a reasonable solution useful in many ordinary cases.
bye Sandro