forked from Ruogu7/HMM4MM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get_StartEnd_XY_of_line_by_line_ID.m
45 lines (37 loc) · 1.87 KB
/
Get_StartEnd_XY_of_line_by_line_ID.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
function [ StartEnd_XY_of_line ] = Get_StartEnd_XY_of_line_by_line_ID ( Line_ID )
%% Get_StartEnd_XY_of_line_by_line_ID function description:
% Imput: Line_ID
% Output:
% StartEnd_XY_of_line: Line ID, start_x, start_y, end_x, end_y
% Example
% [ StartEnd_XY_of_line ] = Get_StartEnd_XY_of_line_by_line_ID ( Line_ID )
% Revision Notes:
% (10/04/14)
% by shenghua chen
StartEnd_XY_of_line = zeros(1,5);
points_in_line = [];
%% get the points
timeoutA = logintimeout(100);
% Connect to a database.
connA = database('hmm_microsoft_data','root','mysql','com.mysql.jdbc.Driver','jdbc:mysql://127.0.0.1:3306/hmm_microsoft_data');
% Check the database status.
ping(connA);
sql_query_LinesByLineID_main = 'SELECT LINESTRING FROM hmm_microsoft_data.roadnetwork where ID = ';
sql_query_LinesByLineID_LineID = num2str(Line_ID); % PID = 5823 as test
sql_query_LinesByLineID = [sql_query_LinesByLineID_main, sql_query_LinesByLineID_LineID];
cursor_LinesByLineID = exec(connA,sql_query_LinesByLineID);
setdbprefs ('DataReturnFormat','cellarray');
result_LinesByLineID = fetch(cursor_LinesByLineID);
%% Display the data.
Line_Set = result_LinesByLineID.Data;
Line_geometry_field = Line_Set{1};
Coor_Pair_Line_geometry_field = strtok(strtok(Line_geometry_field, 'LINESTRING(('), '))');
Coor_Pair_Line_geometry = regexp( Coor_Pair_Line_geometry_field, ',', 'split');
StartEnd_XY_of_line(1) = Line_ID;
StartEnd_XY_of_line(2) = str2num(Coor_Pair_Line_geometry{1});
StartEnd_XY_of_line(3) = str2num(Coor_Pair_Line_geometry{2});
StartEnd_XY_of_line(4) = str2num(Coor_Pair_Line_geometry{end-1});
StartEnd_XY_of_line(5) = str2num(Coor_Pair_Line_geometry{end});
close(cursor_LinesByLineID);
close(connA);
end