-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (41 loc) · 3.63 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
SHELL=bash
WARRENPORT="54.11110,-6.27838"
MUFF="55.06747,-7.26925"
border-posts.zip: border-posts.geojson
-rm -f border-posts.zip
zip border-posts.zip border-posts.geojson
#border-posts.geojson: .imported_into_postgres Makefile
# psql -At -c "with points as (select st_centroid(st_intersection(roads.way, border_segments.way)) as point from planet_osm_line as roads join border_segments on (st_intersects(roads.way, border_segments.way)) where roads.highway is not null), features as ( select 'Feature' as \"type\", ST_AsGeoJSON(points.point)::json as \"geometry\" from points) select row_to_json(fc) from ( select 'FeatureCollection' as \"type\", array_to_json(array_agg(features)) as \"features\" from features ) as fc;" > border-posts.geojson
#
border-posts.csv: .imported_into_postgres Makefile
(echo "lat,lon" ; psql -At -F, -c "select st_y(point) as lat, st_x(point) as lon from (select st_centroid(st_intersection(roads.way, border_segments.way)) as point from planet_osm_line as roads join border_segments on (st_intersects(roads.way, border_segments.way)) where roads.highway is not null and roads.highway NOT IN ('path', 'track', 'footway', 'bridleway')) as points" ) > border-posts.csv
border-posts.geojson: border-posts.csv
ogr2ogr -F GeoJSON border-posts.geojson border-posts.csv -oo X_POSSIBLE_NAMES=lon -oo Y_POSSIBLE_NAMES=lat
.imported_into_postgres: border-region.osm.pbf border-crossings.style
psql -c "DROP TABLE IF EXISTS border_segments;"
osm2pgsql -l -S border-crossings.style border-region.osm.pbf
psql -c "DELETE FROM planet_osm_polygon WHERE admin_level IS NULL OR admin_level != '2'"
psql -c "DELETE FROM planet_osm_line WHERE highway IS NULL"
psql -c "CREATE TABLE border_segments AS select ST_subdivide(st_exteriorring(way), 20) as way from planet_osm_polygon where admin_level = '2';"
psql -c "CREATE INDEX border_segments_geom on border_segments USING gist (way);"
touch .imported_into_postgres
border-region.osm.pbf: ireland-sorted.osm.pbf border-region.geojson
osmium extract -s smart -S types=multipolygon,boundary -p border-region.geojson --overwrite ireland-sorted.osm.pbf -o border-region.osm.pbf
ireland-and-northern-ireland-latest.osm.pbf:
wget -N https://download.geofabrik.de/europe/ireland-and-northern-ireland-latest.osm.pbf
ireland-sorted.osm.pbf: ireland-and-northern-ireland-latest.osm.pbf
osmium sort --overwrite ireland-and-northern-ireland-latest.osm.pbf -o ireland-sorted.osm.pbf
graphhopper-web-0.12.0.jar:
wget https://graphhopper.com/public/releases/graphhopper-web-0.12.0.jar
config-example.yml:
wget https://raw.githubusercontent.com/graphhopper/graphhopper/master/config-example.yml
border-region.osm-gh/properties: config-example.yml border-region.osm.pbf graphhopper-web-0.12.0.jar
-rm -rf border-region.osm-gh/
java -Dgraphhopper.datareader.file=border-region.osm.pbf -jar *.jar import config-example.yml
run-graphhopper: border-region.osm-gh/properties
java -Dgraphhopper.datareader.file=border-region.osm.pbf -jar *.jar server config-example.yml
border-points-matrix.csv: border-posts.csv border-region.osm-gh/properties
( cat border-posts.csv ; echo $(MUFF) ; echo $(WARRENPORT) ) | sed 1d | while read P1 ; do ( cat border-posts.csv ; echo $(MUFF) ; echo $(WARRENPORT) ) | sed 1d | while read P2 ; do DIST=$$(curl -s "http://localhost:8989/route?instructions=false&calc_points=false&point=$${P1/,/%2C}&point=$${P2/,/%2C}&type=json" | jq .paths[0].time) ; echo "$${P1/,/_},$${P2/,/_},$${DIST}" ; done ; done | pv -l -s $$(( $$(cat border-posts.csv | wc -l) ** 2 )) > border-points.matrix.csv
shortest.csv: border-points-matrix.csv
cd tsp-sa
cargo run --release -- border-points-matrix.csv $(MUFF) $(WARRENPORT)