[geos-devel] use of STRtree functions in C API

Gavin Heavyside gavin.heavyside at gmail.com
Tue May 4 11:26:53 EDT 2010


On 4 May 2010 14:30, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> Hi,
>
> I'm investigating the use of STRtree functions in C API to find candidate
> GEOS_MULTIPOLYGON or GEOS_POLYGON objects to test for contiguity, with
> GEOSDisjoint() or GEOSTouches(). I think that I can see how to build the
> tree with envelopes of the polygon objects, using an int ID number as the
> inserted item. However, I'm very unsure how:
>
> extern void GEOS_DLL GEOSSTRtree_query_r(GEOSContextHandle_t handle,
>                                         GEOSSTRtree *tree,
>                                         const GEOSGeometry *g,
>                                         GEOSQueryCallback callback,
>                                         void *userdata);
>
> should be understood. The first three arguments appear clear, but neither of
> the remaining two is. userdata out could be a structure with a pre-allocated
> int array long enough to hold any intersected object IDs, with an int saying
> how many are present. Does anyone have any use examples of GEOSSTRtree_query
> in the C API?
>
> Grateful for any pointers,
>

I don't have any example code handy, but I did get a test program
working with the RTree API a little while ago.

If I remember correctly, you define your own GEOSQueryCallback
function and pass the address in when you make the query. Your
callback is then called once for each geometry in the RTree that
bounding-box-overlaps the geometry passed to the query.

The userdata pointer allows you to provide a pointer to whatever data
you might need.  Your callback receives the matching geometry from the
rtree and your userdata each time it is called, you can cast it back
to the appropriate type in the callback.  e.g. You might want to pass
a pointer that gives you access to the geometry used in the query, so
you can do more specific comparisons between the geometries.

Hope this helps a little,

Gavin


More information about the geos-devel mailing list