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

Roger Bivand Roger.Bivand at nhh.no
Tue May 4 10:26:50 EDT 2010


On Tue, 4 May 2010, Howard Butler wrote:

> Roger,
>
> I would suggest at least investigating libspatialindex, which is an R* 
> tree (and linear and quadratic splitting as well) implementation that is 
> much more featureful than the unexposed internal indexing of GEOS.  I 
> have just added a C API (GDAL or GEOS-style, it's a total rip-off of 
> them) to libspatialindex, to allow users to do the basics like insertion 
> and querying quite easily.  Additionally, with libspatialindex, you have 
> the option of storing your index on disk and bulk loading (pre-sorting 
> for much faster insert performance) the index.
>
> http://trac.gispython.org/spatialindex/wiki
> http://lists.gispython.org/mailman/listinfo/spatialindex
>

Thanks for the suggestion.

I'm sorry, but I don't see any documentation whatsoever, after 
successfully building. So "quite easily" is maybe not my impression, I'm 
afraid, coming from C and interfacing with R.

I need GEOS for Touches/Disjoint (topology operations) anyway, so extra 
dependencies are not a help, rather the opposite. All I need is to 
identify which bounding boxes (envelopes in GEOM-speak) intersect for a 
fixed set of objects whose bounding boxes I can compute, and where GEOS is 
already present and running.

The underlying motivation is to find contiguous polygon neighbours for 
spatial analysis, hoping to avoid doing Touches on n*((n-1)/2) pairs of 
polygons by indexing the bounding boxes and querying which of them 
intersect which others.

> Howard
>
> PS, if you are in the Python world, you can use the Shapely (GEOS 
> wrapper) and Rtree (libspatialindex wrapper) combination to do all kinds 
> of magic quite painlessly.

No, the R world, additional dependencies are not welcome, believe me. 
Maybe they provide use examples (all I asked for) ... links?

Roger

>
> On May 4, 2010, at 8:30 AM, Roger Bivand 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,
>>
>> Roger
>>
>> --
>> 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.Bivand at nhh.no
>>
>> _______________________________________________
>> geos-devel mailing list
>> geos-devel at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/geos-devel
>
>

-- 
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.Bivand at nhh.no



More information about the geos-devel mailing list