-
Notifications
You must be signed in to change notification settings - Fork 0
/
shp_dnload.php
41 lines (35 loc) · 1.2 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
34
35
36
37
38
39
40
41
<?php
/**
* File creates shapefile for AJAX request of curr_user_aois.php
* returns JSON array with success, and filename of shapefile zip file
*
* @package ncgap
*/
//$mspath from nc_config.php
require('nc_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);
}
$gdal_cmd = "/usr/local/bin/ogr2ogr -f 'ESRI Shapefile' -nln {$file_name} -where \"name='{$aoi_name_saved}'\" {$mspath}{$file_name} PG:'dbname=ncgap user=postgres host=localhost' aoi &>/dev/null";
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, "gdalcmd"=>$gdal_cmd));die();
?>