On Tue, 4 May 2010, Gavin Heavyside wrote:

On 4 May 2010 14:30, Roger Bivand <roger.biv...@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,

Yes, thanks, Gavin. I had looked at the callback and thought it looked forbidding, but the results are good - despite compiler warnings both building the tree and querying it. We can now find census blocks that neighbour one another in Los Angeles (almost 90K polygons) in under 10 seconds, compared to over 10 minutes without spatial indexing. I'm only retrieving the input envelope ID values, not the geometries, which for our purposes are not needed.

Roger


Gavin


--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no
_______________________________________________
geos-devel mailing list
geos-devel@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/geos-devel

Reply via email to