· 9 years ago · Jan 02, 2017, 04:24 PM
1drop table if exists building_travel_curve;
2create table building_travel_curve as (
3 select
4 ST_MakeLine(ST_Centroid(p.way)
5 order by tsp.seq) as geom,
6 1 as id
7 from pgr_tsp(
8 $$
9 select
10 osm_id :: int4 as id,
11 st_X(ST_Centroid(way)) as x,
12 st_Y(ST_Centroid(way)) as y
13 from planet_osm_polygon
14 where building is not null and not tags ? 'building:levels'
15 order by way <-> ST_Transform(ST_SetSRID(ST_MakePoint(27.57241, 53.91993), 4326), 3857)
16 limit 100
17 $$,
18 (
19 select osm_id :: int4
20 from planet_osm_polygon
21 where building is not null and not tags ? 'building:levels'
22 order by way <-> ST_Transform(ST_SetSRID(ST_MakePoint(27.57241, 53.91993), 4326), 3857)
23 limit 1
24 )
25 ) tsp
26 join planet_osm_polygon p on (tsp.id2 = p.osm_id)
27);