[postgis-devel] Optimizing distance routines in PostGIS

Daniel Baston dbaston at gmail.com
Mon Oct 31 15:17:34 PDT 2016


I recently ported the IndexedFacetDistance class from JTS to GEOS.
This class provides optimized distance routines that work by
constructing Rtree indexes over both of the input geometries, and
performing distance calculations only between the nearest portions
(facets) of the two inputs.  This can produce massive performance
improvements on distance calculations.  (An example discussed in trac
#3587 goes from about 42 seconds to 0.1 seconds.)  Additionally, the
indexes can be retained (much like a PreparedGeometry), for the case
where many inputs need to be tested against a single large geometry
(this last bit hasn't been exposed in the C API).

Is this something we should explore using in ST_Distance / ST_DWithin,
or maybe elsewhere in PostGIS?  It would have to be limited to types
supported by GEOS (2D only, no curves), and we'd probably need to find
some heuristics about when it's worth the effort (rather than a
standard lwgeom_mindistance2d).

Dan



More information about the postgis-devel mailing list