You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by David Torres <da...@gmail.com> on 2014/07/11 13:47:50 UTC

guidance to improve Spatial Queries

Hi,

I've been testing Jena Spatial with good results, it's very useful and easy
to configure it, but in my opinion is still limited.

For example, in my queries I get some results satisfying nearby queries,
but (as long as I know) there is not an in-built method to order properly
these results by distance (I consider that getting first the nearest
results it's a typical feature).

For example it'd be perfect something like this:

SELECT ?point ?distance
{
    ?point rdf:type geo:SpatialThing .
    ?point geo:lat ?lat .
    ?point geo:long ?long .
    ?point spatial:withinCircle (41.2085 -3.713 85)
    ?distance spatial:distance (?lat ?long 41.2085 -3.713 'km')
}

ORDER BY ?distance

I offer myself to make this improvement (and maybe other in the future) but
I'd need some guidance to perform this. My first question is if it is
possible to be done, because after reviewing the code I've noted all the
implemented functions only says if the result fits or not ("distance" is
not a SpatialOperation like the rest..). How do you approach the
development of this feature?

Thanks in advance,
David

Re: guidance to improve Spatial Queries

Posted by Andy Seaborne <an...@apache.org>.
On 11/07/14 12:47, David Torres wrote:
> Hi,
>
> I've been testing Jena Spatial with good results, it's very useful and easy
> to configure it, but in my opinion is still limited.
>
> For example, in my queries I get some results satisfying nearby queries,
> but (as long as I know) there is not an in-built method to order properly
> these results by distance (I consider that getting first the nearest
> results it's a typical feature).
>
> For example it'd be perfect something like this:
>
> SELECT ?point ?distance
> {
>      ?point rdf:type geo:SpatialThing .
>      ?point geo:lat ?lat .
>      ?point geo:long ?long .
>      ?point spatial:withinCircle (41.2085 -3.713 85)
>      ?distance spatial:distance (?lat ?long 41.2085 -3.713 'km')
> }
>
> ORDER BY ?distance
>
> I offer myself to make this improvement (and maybe other in the future) but
> I'd need some guidance to perform this. My first question is if it is
> possible to be done, because after reviewing the code I've noted all the
> implemented functions only says if the result fits or not ("distance" is
> not a SpatialOperation like the rest..). How do you approach the
> development of this feature?
>
> Thanks in advance,
> David
>

David,

Such an improvement would be great - I don't the details of how Lucene 
spatial is provided but if nothing else, getting the necessary points 
and doing a sort then returning the results in order from 
spatial:withinCircle would work. IIRC Lucene does not return results in 
a sorted order (it might well do - I just don't know).

One note - there is no formal guarantee in SPARQL on preserving ordering 
- indeed an OPTIONAL (a left join) could scramble the ordering by using 
a hash join.

However, ARQ currently has more predictability than the standard requires.

	Andy