-
Notifications
You must be signed in to change notification settings - Fork 1
/
fn.php
64 lines (55 loc) · 1.25 KB
/
fn.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
<?php
use Geo6\GDAL\ogr2ogr;
/**
*
*/
function export($source, $file, $format, $srs = 'EPSG:4326', $params = array())
{
global $warnings;
$dir = dirname($file);
$fname = basename($file);
switch ($format) {
case "ESRI Shapefile":
$file .= ".shp";
break;
case "GML":
$file .= ".gml";
break;
case "KML":
case "LIBKML":
$file .= ".kml";
break;
case "MapInfo File":
if (isset($params['dsco']) && in_array('FORMAT=MIF', $params['dsco'])) {
$file .= ".mif";
} else {
$file .= ".tab";
}
break;
default:
break;
}
try {
if (!file_exists($dir) || !is_dir($dir)) {
mkdir($dir, 0777, TRUE);
}
$ogr2ogr = new ogr2ogr($file, $source);
$ogr2ogr->setOption('f', $format === 'KML' ? 'LIBKML' : $format);
if ($srs !== 'EPSG:4326') {
$ogr2ogr->setOption('s_srs', 'EPSG:4326');
$ogr2ogr->setOption('t_srs', $srs);
}
foreach ($params as $key => $param) {
if (is_array($param)) {
foreach ($param as $p) {
$ogr2ogr->setOption($key, $p);
}
} else {
$ogr2ogr->setOption($key, $param);
}
}
$ogr2ogr->run();
} catch (Exception $e) {
$warnings[] = $e->getMessage();
}
}