I have found a more efficient way to filter objects inside boundaries.

Looks like the approach I used before:

FILTER ( ?lat >= 56.4881360279505 && ?lat <= 56.5118226056529 && ?long >=
>> 84.9451732635498 && ?long <= 84.9880886077881 )

doesn't use geo index at all. That's why I decided to prefilter objects
using bif:st_intersects function. As we know boundaries we can calculate
rectangle diagonal using Haversine
formula<http://www.movable-type.co.uk/scripts/latlong.html>.
After that we can "draw" a circle from the center of rectangular with radius
equal to diagonal/2: http://img717.imageshack.us/img717/6931/maptl.png

bif:st_intersects filters objects inside this circle and after that we need
just to filter objects that are inside the circle but outside the boundaries
(as I did it before). So the final query is like this:

FILTER ( bif:st_intersects (?geo, bif:st_point (-85.7686328887939,
41.0006278592186), 2.548784053237235) && ?lat >= 40.9844337033077 && ?lat <=
41.0168220151295 && ?long >= -85.7900905609131 && ?long <= -85.7471752166748
)

and it's performance is much better.

2010/4/26 Nathan <[email protected]>

> Nathan wrote:
> > Alexander Sidorov wrote:
> >> Hello!
> >>
> >> What is the most efficient way of filtering geomerty objects by
> >> latitude/longitude? I need to retrieve LinkedGeoData objects inside some
> >> rectangular boundaries. Here is how I filter objects now :
> >>
> >> where
> >> {
> >>   ?entity geo:lat ?lat .
> >>   ?entity geo:long ?long .
> >>   FILTER ( ?lat >= 56.4881360279505 && ?lat <= 56.5118226056529 && ?long
> >=
> >> 84.9451732635498 && ?long <= 84.9880886077881 )
> >> }
> >>
> >> One more possible implementation:
> >>
> >> where
> >> {
> >>   ?entity geo:geometry ?geo .
> >>   FILTER ( bif:st_y(?geo) >= 56.4881360279505 && bif:st_y(?geo) <=
> >> 56.5118226056529 && bif:st_x(?geo) >= 84.9451732635498 && bif:st_x(?geo)
> <=
> >> 84.9880886077881 )
> >> }
> >>
> >> What is the most efficient way?
> >
> > I would have though st_within [1] would have been fastest, but you could
> > just run the three versions and time each one to see which is fastest.
> >
> > http://docs.openlinksw.com/virtuoso/fn_st_within.html
> >
>
> ack ignore that, getting confused between mysql and virtuoso; was
> thinking of "mbr contains" functionality where you see if points are
> within a minimum bounding rectangle.
>
> staff: is support for mbr and related functions planned, wip or due soon?
>
> Best,
>
> Nathan
>

Reply via email to