A ranking algorithm I'm developing for a Django webapp requires performing spatial operations (within, intersections, sym_difference, etc.) using a query against large number of geometry objects.

Presently, the algorithm is very time-consuming, and the profiler reveals that the bottleneck is django.contrib.gis.geos.prototypes.threadsafe.__call__, which are called by virtually every methods in GEOSGeometry. From what I understand, threadsafe.py is a wrapper to the underlying GEOS's threadsafe API.

In this case the threadsafe-checking presents huge overhead to the computation time. Also my computation is strictly single threaded. From these reasons, I wonder is it possible to bypass or avoid the thread-safety checking performing by Django's GEOS API?

  • try contacting the people in ticket #10923 – Mike T Jul 12 '11 at 21:32

If you have one target geometry with a batch of many test geometries, try using a prepared geometry. See this page for a good description of a prepared geometry.

  • +1 "Prepared geometry" is a crucial concept for efficient GIS analysis; it's nice to see it getting implemented somewhere! – whuber Jul 12 '11 at 13:32
  • I use PreparedGeometry for spatial predicate methods in my algorithm as well. The performance bottleneck, however, are mainly from topological methods (e.g. intersection, sym_difference), in which PreparedGeometry does not support. The algorithm needs these topological methods to find area of intersection, for instance. – ejel Jul 12 '11 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.