SELECT * FROM mypolygs, mypoints
WHERE ST_Contains(mypolygs.geom, mypoints.geom) = 1
AND mypoints.ROWID IN (
SELECT ROWID FROM SpatialIndex
WHERE f_table_name = 'mypoints'
AND search_frame = mypolygs.geometry);
just two possible flaws to be checked:
a) both tables *must* be in the same Reference System (SRID-value)
b) testing if ST_Contains() actually return 1 (TRUE) always is a good
idea
bye Sandro
--
Il messaggio e' stato analizzato alla ricerca di virus o
contenuti pericolosi da MailScanner, ed e'
risultato non infetto.
SpatialIndex is a "virtual table"; any SpatiaLite's own DB surely
contains a "SpatialIndex" table, intended to make simpler and easier
using a spatial index in your queries:
http://www.gaia-gis.it/gaia-sins/SpatialIndex-Update.pdf
If your DB has no SpatialIndex table at all, this probably means that
you are currently using some archaic, obsolete and deprecated version;
and in this case upgrading to some more recent release (e.g. 3.x.x)
is strongly suggested.
I ignore what operating system you are using: anyway, you can
download Windows binaries from here:
http://www.gaia-gis.it/gaia-sins/
and if you are on Linux you can easily build from yourself using
the latest sources (available on the same download site)
> I built a table buffer with this explication :
> Create table test_buffer ((id integer Primary key autoincrement, Name
> text, description text);
> SELECT AddGeometryColumn('test_buffer', 'geometry',4326, 'POLYGON',
> 'XY');
> INSERT INTO 'test_buffer' (id, geometry, Name) select Null, st_buffer
> (geometry, 0.000009), Name, description from "ENC";
Why a Null ID?
> The result is 4 rows, however for my test, it does have only one.
Can you show the real results? Its a bit difficult to tell what the
issues could be without real information.
> I tried the same query with arcgis (with my shapefiles) and the result
> is true.
Can you show the real results here too?
Brad
+1
> Why a Null ID?
>
because it's INTEGER PRIMARY KEY AUTOINCREMENT
that's fine, the SQLite core will automatically replace
this NULL using the next available id-value
> Can you show the real results here too?
>
+1 (again)
and in addtion: can you kindly tell us which spatialite's
version and which operating system are you using ?
yes, you can send your sample DB to my private mail address;
and includinging a short but clear description of any step you've
attempted since now surely helps.
bye sandro
the original Teddy's query
--------------------------
SELECT *
from "PAPIER", "test_buffer"
where st_contains("test_buffer.Geometry",
"PAPIER.Geometry");
======
the resultset contains 4 rows, i.e. it simply is the
cartesian product of both tables
another slightly modified query
-------------------------------
SELECT *
from "PAPIER", "test_buffer"
where st_contains("test_buffer.Geometry",
"PAPIER.Geometry") = 1;
======
this time the resultset is empty: really puzzling, isn't ?
where is the problem ?
quite simple to identified ... for en expert eye, but probably
not at all so obvious for a beginner ;-)
the expected SQL syntax was instead:
------------------------------------
SELECT *
from "PAPIER", "test_buffer"
where st_contains("test_buffer"."Geometry",
"PAPIER"."Geometry") = 1;
======
the resultset now contains one unique row, as expected :-D
please carefully pay attention on double-quotes.
Post Mortem:
============
accordingly to SQL syntax rules, "test_buffer"."Geometry"
is a valid reference to the value of a column named
"Geometry" within a table named "test_buffer".
"test_buffer.Geometry" is a completely different thing,
it simply is a TEXT CONSTANT, not at all a column name.
Accordingly to strictly pedantic SQL syntax rules a Text Constant
is expected to be written as 'test_buffer.Geomeyry' (please
note, single-quoted).
anyway many SQL engines (this including SQLite) will
indifferently accept as well any Text Constant enclosed
within double-quotes.
just a quick debug/check:
SELECT ST_Contains("test_buffer.Geometry", "PAPIER.Geometry");
==========
the result is: -1
and the ST_Contains doc says:
"The return type is Integer, with a return value of 1 for TRUE,
0 for FALSE, and –1 for UNKNOWN corresponding to a function
invocation on NULL arguments"
neither the first nor the second arg are valid Geometries (they
simply are Text Constants), and accordingly to this -1 is returned.
but -1 isn't a synonym for FALSE, in boolean terms it's TRUE ...
and this fully explains why Teddy's initial query simply returned
the cartesian product :-D
Lessons to learn:
=================
never use double-quoted names if there isn't any compelling
reason to do this; this simply risk to confuse you.
SELECT *
from PAPIER, test_buffer
where st_contains(test_buffer.Geometry,
PAPIER.Geometry);
this simplest query will work nicely, and there aren't any confusing
double-quotes ;-)
bye Sandro