-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetHighway.m
61 lines (52 loc) · 2.25 KB
/
getHighway.m
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
57
58
59
60
61
function [result] = getHighway(place)
% Constructs a query to retrieve highway information
%
% INPUT:
% place (String) - Name of an area polygon in OpenSteetMap
% OUTPUT:
% result(:,1:2) (Doubles) - Longitude and Latitude
% result(:,3) (Integer) - Index of a given path
% result(:,4) (Integer) - Highway class
% result(:,5) (Boolean) - Oneway or not
% EXAMPLE:
% [result] = getHighway('Bristol')
% NOTE:
% Highway classes are defined in getHighwayTagsAsNumbers
% ISSUES:
% If there are 'java.lang.OutOfMemoryError: Java heap space'
% problems, refer to the following link for instructions:
% http://www.mathworks.co.uk/support/solutions/en/data/1-18I2C/
load('global');
query = ['SELECT ST_X((g.p).geom), ST_Y((g.p).geom), (g.p).path[1], g.h, g.o '...
'FROM ('...
' SELECT 1 AS edge_id, ST_DumpPoints(r.way) AS p, r.highway AS h, r.oneway as o '...
' FROM '...
' planet_osm_line AS r,'...
' (SELECT way FROM planet_osm_polygon WHERE name = ''' place ''' AND boundary=''administrative'' ORDER BY ST_area(way) DESC LIMIT 1) AS s'...
' WHERE r.highway <> '''' AND ST_Intersects(r.way, s.way)'...
') AS g'];
% query = ['SELECT ST_X((g.p).geom), ST_Y((g.p).geom), (g.p).path[1], g.h, g.o '...
% 'FROM ('...
% ' SELECT 1 AS edge_id, ST_DumpPoints(r.way) AS p, r.highway AS h, r.oneway as o '...
% ' FROM '...
% ' planet_osm_line AS r'...
% ' WHERE r.highway IN (''motorway'',''motorway_link'',''trunk'',''trunk_link'',''primary'',''primary_link'') '...
% ') AS g'];
%
% Entire Database
% query = ['SELECT ST_X((g.p).geom), ST_Y((g.p).geom), (g.p).path[1], g.h, g.o '...
% 'FROM ('...
% ' SELECT 1 AS edge_id, ST_DumpPoints(r.way) AS p, r.highway AS h, r.oneway as o '...
% ' FROM '...
% ' planet_osm_line AS r'...
% ' WHERE r.highway <> '''''...
% ') AS g'];
rootPath = ['./cache/highway/' DBase '/'];
if ~exist(rootPath,'file')
mkdir(rootPath);
end
filePath = [rootPath place '/'];
if ~exist(filePath,'file')
mkdir(filePath);
end
result = getFileOrQuery([filePath 'highwayQueryResult'], DBase, query,'highway');