2011/11/1 a.furieri <a.fu...@lqt.it>:
Hi Sandro
I'm migrating a simple ST_Contains (ST_Within) query from PostGIS to
spatialite and I'm little confused by the three versions you
summarized before.
That's what I'd like to do: I'd like to make a point in polygon test
for points (table orte/places) in order to spatially join and add an
attribute (Name) from a polygon table (table gemeinden/communities)
using spatialite 2.4 and 3.x (newest):
SELECT pt.ROWID, pt.PKUID, pt.NAME, pt.Geometry, po.name
FROM orte AS pt, gemeinden AS po
WHERE ST_Contains(pt.way, po.way);
Note: Thats ISO/OGC standard and includes an index von geometry
attributes from both(!) tables.
Now, for spatialite 3x this seems to be one of the newer syntaxes:
SELECT pt.ROWID, pt.PKUID, pt.NAME, pt.Geometry, po.name
FROM orte AS pt, gemeinden AS po
WHERE ST_Contains(po.Geometry, pt.Geometry)
AND pt.ROWID IN (
SELECT ROWID FROM idx_Orte_Geometry
WHERE RTreeContains(po.Geometry, pt.Geometry) = 1
);
My questions:
* Is this the preferred syntax for this task?
* What is the preferred syntax for spatialite v. 2.4 (which is in
current stable QGIS)?
* Why is the Spatial Index only applied for one table (here:
idx_Orte_Geometry) and not for both (here: idx_Gemeinden_Geometry)?
Yours, Stefan
I correct myself: This is what really used the index:
SELECT pt.PKUID, pt.NAME, pt.Geometry, po.Name
FROM orte AS pt, gemeinden AS po
WHERE ST_Within(pt.Geometry, po.Geometry)
AND pt.ROWID IN (
SELECT pkid FROM idx_Orte_Geometry
WHERE pkid MATCH RTreeIntersects(
MbrMinX(po.Geometry), MbrMinY(po.Geometry),
MbrMaxX(po.Geometry), MbrMaxY(po.Geometry))
)
But my questions remain:
* Isn't there a more elegant and intuitive subquery?
* At least when two polygons would be involved I would expect two
index subqueries one for each
Yours, S.
2012/4/23 <a.fu...@lqt.it>:
> --
> You received this message because you are subscribed to the Google Groups
> "SpatiaLite Users" group.
> To post to this group, send email to spatiali...@googlegroups.com.
> To unsubscribe from this group, send email to
> spatialite-use...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/spatialite-users?hl=en.
>
2012/4/23 <a.fu...@lqt.it>:
I just tested this out with SpatiaLite ver. 2.4.0 which is the one in
current stable QGIS 1.7.
There, form #3 does not work because SpatialIndex does not yet exist.
So what do you recommend in this case? Deprecated form #2 or form #1?
Yours, S.
yes, it's a quite recent introduction
> So what do you recommend in this case? Deprecated form #2 or form #1?
>
IMHO form #1: it's absolutely stable, and it will surely be supported
for a very long time.
Hi Micha,
there is nothing odd in all this: please note, SpatialIndex is
a *VirtualTable*, not a real table ...
in other words, it's simply an abstract interface, actual data
are "magically" provided as appropriate by the underlying driver.
if you are curious to know, the actual workflow implemented by
SpatialIndex is:
a) checking if the table identified by "WHERE f_table_name = x"
actually exists, and if it has a corresponding R*Tree
b) if yes, than a nested query on behalf of this R*Tree is
silently performed using as appropriate the MBR deriving
from the "WHERE search_frame = g" clause
c) and finally all the ROWIDs found are inserted into the
resultset to be returned
in other words, it simply is "syntactic sugar", no more than
this (anyway, really useful because it allows writing simpler
and clearer queries) ;-)
Hi Micha,
this is because there are *two* different columns named ROWID in
your query: one coming from the SpatialIndex table, and another
one coming from the GeoPC table.
you are simply required to disambiguate/qualify all column names,
as in:
SELECT SpatialIndex.ROWID, adm2.ROWID
FROM SpatialIndex, adm2
WHERE f_table_name='GeoPC' AND search_frame=adm2.Geometry;