-
Notifications
You must be signed in to change notification settings - Fork 0
/
shp_dnload.php
33 lines (30 loc) · 1.08 KB
/
shp_dnload.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
<?php
require("sw_config.php");
pg_connect($pg_connect);
$aoi_name_saved = $_POST['aoi_name_saved'];
$query = "select name, username, description from aoi where name = '{$aoi_name_saved}'";
$result = pg_query($query);
$row = pg_fetch_array($result);
$desc_arr = str_split($row['description']);
$file_name = "";
foreach ($desc_arr as $k){
if (ctype_space($k)) {
$k = '_';
}elseif (!ctype_alnum($k)){
$k = '';
}
$file_name = $file_name.$k;
}
$file_name_ln = 15;
$file_name = substr($file_name, 0, $file_name_ln);
while(preg_match("/.*_$/", $file_name)){
$file_name = substr($file_name, 0, --$file_name_ln);
}
//$prj_file = "/var/www/html/data/swgap/sw_proj_32769";-a_srs $prj_file
$gdal_cmd = "/usr/local/bin/ogr2ogr -f 'ESRI Shapefile' -nln {$file_name} -where \"name='{$aoi_name_saved}'\" {$mspath}{$file_name} PG:'dbname=swgap user=postgres host=localhost' aoi &>/dev/null";
//echo $gdal_cmd; die();
exec($gdal_cmd);
$zip_cmd = "zip -r -j {$mspath}{$file_name} {$mspath}{$file_name} &>/dev/null";
exec($zip_cmd);
echo json_encode(array("success"=>true, "filename"=>$file_name));die();
?>