a.furieri
unread,Nov 5, 2010, 8:14:27 AM11/5/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to SpatiaLite Users
Hi Daniel,
supporting the PostGIS-like ST_DWithin()
function in SpatiaLite is quite impossible:
- we have no Geography data-type: we simply
have Geometry
- in SpatiaLite directly accessing a Spatial
Index from a SQL function isn't possible
at all.
- computing geodesic distances for complex
Linestrings or Polygons seems to require
an intolerable amount of time.
Anyway, something like ST_DWithin() is
surely useful and absolutely required.
---------------
Boolean PtDistWithin (
geom1 Geometry,
geom2 Geometry,
dist Double precision
[, use_spheroid Boolean] )
a] if *geom1* and/or *geom2* are invalid,
return value is NULL
b] if both *geom1* and *geom2* are simple
POINTs into the 4326 SRID (WGS84),
then the GreatCircle (or Geodesic)
distance is evaluated (measured in
Meters)
c] in any other case the 'plain' distance
will be evaluated as usual, and the measure
unit will be the 'natural' one for the
corresponding SRID
d] if the computed distance (following the
above rule) is <= *dist*, the function
will return TRUE
otherwise will return FALSE
the optional arg *use_spheroid* is used
only in the b] case:
- if *use_spheroid=TRUE* the geodesic
distance will be computed (slowest,
but most accurate)
- if *use_spheroid=FALSE* the great
circle distance will be computed
(fastest, bet less accurate)
Default: FALSE (great circle)
code snippet #1:
=====================================
CREATE TABLE MyPoints (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL);
SELECT AddGeometryColumn ('MyPoints',
'Geometry', 4326, 'POINT', 'XY');
INSERT INTO MyPoints ....;
SELECT * FROM MyPoints
WHERE PtDistWithin(Geometry,
MakePoint(11.87691, 43.46139, 4326),
10000.0) = 1;
SELECT * FROM MyPoints
WHERE PtDistWithin(Geometry,
MakePoint(11.87691, 43.46139, 4326),
2500.0, 1) = 1;
the first query will identify
any point laying within a radius
of 10 km (using the fastest great
circle distance)
the second query will identify
any point laying within a radius
of 2.5 km (using the most accurate
geodesic distance)
code snippet #2:
===========================
SELECT CreateSpatialIndex('MyPoints',
'Geometry');
SELECT * FROM MyPoints
WHERE PtDistWithin(Geometry,
MakePoint(11.87691, 43.46139, 4326),
2500.0, 1) = 1 AND ROWID IN (
SELECT pkid FROM idx_MyPoints_Geometry
WHERE pkid MATCH RTreeIntersects(
11.87691 - 0.5, 43.46139 - 0.5,
11.87691 + 0.5, 43.46139 + 0.5)
);
and when the dataset to be inspected does
actually contains an huge number of rows,
using a Spatial Index is a really good
idea :-)
=====================================
to be released ASAP (really ...)
bye Sandro