/
lib_whosonfirst_uri.php
59 lines (35 loc) · 1.38 KB
/
lib_whosonfirst_uri.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
<?php
# this file was cloned from https://github.com/whosonfirst/flamework-whosonfirst/
########################################################################
function whosonfirst_uri_id2relpath($id, $more=array()){
$fname = whosonfirst_uri_id2fname($id, $more);
$tree = whosonfirst_uri_id2tree($id);
return implode(DIRECTORY_SEPARATOR, array($tree, $fname));
}
########################################################################
function whosonfirst_uri_id2abspath($root, $id, $more=array()){
$rel = whosonfirst_uri_id2relpath($id, $more);
# Check $root for a trailing slash, so we don't get two slashes
if (substr($root, -1, 1) == DIRECTORY_SEPARATOR) {
$root = substr($root, 0, -1);
}
return implode(DIRECTORY_SEPARATOR, array($root, $rel));
}
########################################################################
function whosonfirst_uri_id2fname($id, $more=array()){
# PLEASE WRITE: all the alt/display name stuff
return "{$id}.geojson";
}
########################################################################
function whosonfirst_uri_id2tree($id){
$tree = array();
$tmp = $id;
while (strlen($tmp)){
$slice = substr($tmp, 0, 3);
array_push($tree, $slice);
$tmp = substr($tmp, 3);
}
return implode(DIRECTORY_SEPARATOR, $tree);
}
########################################################################
# the end