-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.php
More file actions
92 lines (78 loc) · 2.44 KB
/
tutorial.php
File metadata and controls
92 lines (78 loc) · 2.44 KB
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
90
91
<?php
function dump($var, $echo=true,$label=null, $strict=true)
{
$label = ($label===null) ? '' : rtrim($label) . ' ';
if(!$strict) {
if (ini_get('html_errors')) {
$output = print_r($var, true);
$output = '<pre>'.$label.htmlspecialchars($output,ENT_QUOTES).'</pre>';
} else {
$output = $label . print_r($var, true);
}
}else {
ob_start();
var_dump($var);
$output = ob_get_clean();
if(!extension_loaded('xdebug')) {
$output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
$output = '<pre>'. $label. htmlspecialchars($output, ENT_QUOTES). '</pre>';
}
}
if ($echo) {
echo($output);
return null;
}else
return $output;
}
require 'ShapeFile.inc.php';
$options = array('noparts' => false);
$shp = new ShapeFile('map/bou2_4p.shp', $options); // along this file the class will use file.shx and file.dbf
file_put_contents("china.json", '');
$result = array(
'type' => 'FeatureCollection',
'features' => array(),
'bbox' => array(114.32, 30.52, 114.34, 30.54)
);
$i=0;
while ($record = $shp->getNext()) {
$record = $shp->getNext();
// read meta data
if(empty($record)) continue;
$dbf_data = $record->getDbfData();
$data = array(
//trim($dbf_data['ISO_3_CODE']),
//trim($dbf_data['ISO_2_CODE']),
trim($dbf_data['NAME'])
);
// read shape data
$shp_data = $record->getShpData();
// store number of parts
//$data[] = $shp_data['numparts'];
$result['features'][] = array(
'geometry' => array(
'type' => 'Polygon',
'coordinates' => array()
),
'type' => 'Feature',
'name' => trim($dbf_data['NAME'])
);
foreach ($shp_data['parts'] as $part) {
$coords = array();
foreach ($part['points'] as $point) {
//$result['features'][$i]['geometry']['coordinates'] = array($point['x'], $point['y']);
$coords[] = array($point['x'], $point['y']);
}
$result['features'][$i]['geometry']['coordinates'] = $coords;
// dump($result['features'][$i]);
file_put_contents("china.json", json_encode($result['features'][$i]).'', FILE_APPEND);
}
$i++;
}
//dump($result);
//$content = json_encode($result);
// file_put_contents("china.json", $content, FILE_APPEND);
// file_put_contents("china.json", '12', FILE_APPEND);
// file_put_contents("china.json", '34', FILE_APPEND);
// file_put_contents("china.json", '56', FILE_APPEND);
// file_put_contents("china.json", '78', FILE_APPEND);
?>