This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvillage.php
89 lines (64 loc) · 2.25 KB
/
village.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
// Database connection settings
define("PG_DB" , "dorm");
define("PG_HOST", "localhost");
define("PG_USER", "user");
define("PG_PORT", "5432");
define("PG_PASS", "user");
define("TABLE", "_village_sel");
// Retrieve start point
// FUNCTION findNearestEdge
// Connect to database
$con = pg_connect("dbname=".PG_DB." host=".PG_HOST." port=".PG_PORT." password=".PG_PASS." user=".PG_USER);
//$sql = "select * from ".TABLE." where e_date <= c_date";
$sql = "select gid,dolacode,vill_name, ST_AsGeoJSON(geom) AS geojson from ".TABLE." ";
/* $sql = "SELECT gid, source, target, geom,
ST_Distance(geom, ST_GeometryFromText(
'POINT(".$lonlat[0]." ".$lonlat[1].")', 3857)) AS dist
FROM ".TABLE."
ORDER BY dist LIMIT 1"; */
// echo "<br>";
// echo $sql;
$query = pg_query($con,$sql);
/*
$edge['gid'] = pg_fetch_result($query, 0, 0);
$edge['source'] = pg_fetch_result($query, 0, 1);
$edge['target'] = pg_fetch_result($query, 0, 2);
$edge['geom'] = pg_fetch_result($query, 0, 3);
*/
// Close database connection
pg_close($con);
// Connect to database
$con = pg_connect("dbname=".PG_DB." host=".PG_HOST." port=".PG_PORT." password=".PG_PASS." user=".PG_USER);
// Perform database query
$query = pg_query($con,$sql);
//echo $sql;
// Return route as GeoJSON
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
// Add geom to GeoJSON array
while($edge=pg_fetch_assoc($query)) {
$feature = array(
'type' => 'Feature',
'geometry' => json_decode($edge['geojson'], true),
'crs' => array(
'type' => 'EPSG',
'properties' => array('code' => '3857')
),
'properties' => array(
'gid' => $edge['gid'],
'dolacode' => $edge['dolacode'],
'vill_name' => $edge['vill_name']
)
);
// Add feature array to feature collection array
array_push($geojson['features'], $feature);
}
// Close database connection
pg_close($con);
// Return routing result
header('Content-type: application/json',true);
echo json_encode($geojson);
?>