From 8ecfe5f701438f71d805bf5ca0694b0fe87d830f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Sun, 14 Jul 2019 18:31:55 +0200 Subject: [PATCH] Speed up with spatial index in analyser_osmosis_relation_public_transport --- analysers/analyser_osmosis_relation_public_transport.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/analysers/analyser_osmosis_relation_public_transport.py b/analysers/analyser_osmosis_relation_public_transport.py index aebe723f9..2f70079ac 100644 --- a/analysers/analyser_osmosis_relation_public_transport.py +++ b/analysers/analyser_osmosis_relation_public_transport.py @@ -151,6 +151,10 @@ ) """ +sql20b = """ +CREATE INDEX indx_stop_platform_geom ON stop_platform USING gist(geom) +""" + sql21 = """ CREATE TEMP TABLE route_geom AS SELECT @@ -173,7 +177,8 @@ stop_platform JOIN route_geom ON route_geom.id = stop_platform.id AND - ST_Distance(route_geom.geom, stop_platform.geom) BETWEEN 50 AND 1000 + ST_DWithin(route_geom.geom, stop_platform.geom, 1000) AND + ST_Distance(route_geom.geom, stop_platform.geom) BETWEEN 50 AND 1000 """ sql30 = """ @@ -272,6 +277,7 @@ def analyser_osmosis_common(self): self.run(sql01) self.run(sql10, self.callback10) self.run(sql20.format(self.config.options.get("proj"))) + self.run(sql20b) self.run(sql21.format(self.config.options.get("proj"))) self.run(sql22, self.callback20) self.run(sql30, self.callback30)