function filter($res, &$dd) { $data = $res['data']; header('Content-Description: File Transfer'); header('Content-Type: ' . 'application/vnd.google-earth.kmz'); header('Content-Disposition: attachment; filename=' . preg_replace('/\\W/', '_', $dd['title']) . '.kmz'); $kml = ''; $kml .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $kml .= '<kml xmlns="http://earth.google.com/kml/2.2">'; $kml .= '<Document>'; $kml .= '<name>' . $dd['title'] . '</name>'; $kml .= '<description><![CDATA[' . $dd['title'] . ']]></description>'; $kml .= '<Style id="style0">'; $kml .= '<IconStyle><Icon><href>http://maps.gstatic.com/intl/en_us/mapfiles/ms/micons/blue-dot.png</href></Icon></IconStyle></Style>'; if (!isset($dd['maps'])) { return; } while ($rec = mysql_fetch_assoc($data)) { if ($rec[$dd['maps'][0]['lat']] == NULL || $rec[$dd['maps'][0]['lng']] == NULL) { continue; } $lat = $rec[$dd['maps'][0]['lat']]; $lng = $rec[$dd['maps'][0]['lng']]; $cood = ''; if (!isset($dd['maps'][0]['cood_type']) || $dd['maps'][0]['cood_type'] != 'dms') { $cood = "{$lng},{$lat},0.000000"; } else { $cood = dms2dc($lng) . ',' . dms2dc($lat) . ',0.000000'; } $pm = '<Placemark>'; $pm .= '<name>' . $rec[$dd['maps'][0]['title']] . '</name>'; $pm .= '<description><![CDATA[<div dir="ltr">' . $rec[$dd['maps'][0]['title']]; if (isset($dd['maps'][0]['info'])) { $info_str = $dd['maps'][0]['info']; foreach ($rec as $key => $val) { $info_str = str_replace('{' . $key . '}', $rec[$key], $info_str); $info_str = str_replace('{' . $key . '|html}', $rec[$key], $info_str); } $pm .= "<br />{$info_str}"; } $pm .= '</div>]]></description>'; $pm .= '<styleUrl>#style0</styleUrl>'; $pm .= '<Point>'; $pm .= '<coordinates>' . $cood . '</coordinates>'; $pm .= '</Point>'; $pm .= '</Placemark>'; $kml .= $pm; } $kml .= '</Document>'; $kml .= '</kml>'; $tmp = tempnam("/tmp", "kmz"); $z = new ZipArchive(); $z->open($tmp, ZIPARCHIVE::OVERWRITE); $z->addFromString('doc.kml', $kml); $z->close(); ob_end_flush(); readfile($tmp); unlink($tmp); exit; }
function filter($res, &$dd) { $data = $res['data']; if (!isset($dd['maps'])) { return; } $uid = uniqid('dv_shp_' . session_id()); $path = '/tmp/' . $uid; mkdir($path); $file_name = $path . '/data'; $vrt = ''; $vrt .= '<OGRVRTDataSource>' . "\n\t"; $vrt .= '<OGRVRTLayer name="data">' . "\n\t\t"; $vrt .= '<SrcDataSource relativeToVRT="1">data.csv</SrcDataSource>' . "\n\t\t"; $vrt .= '<GeometryType>wkbPoint</GeometryType>' . "\n\t\t"; $vrt .= '<GeometryField encoding="PointFromColumns" x="lng" y="lat"/>' . "\n\t"; $vrt .= '</OGRVRTLayer>' . "\n"; $vrt .= '</OGRVRTDataSource>'; $w = '"'; $s = ","; $nl = "\r\n"; $csv = $w . 'lng' . $w . $s; $csv .= $w . 'lat' . $w . $s; $csv .= $w . 'name' . $w; $csv .= $nl; while ($rec = mysql_fetch_assoc($data)) { if ($rec[$dd['maps'][0]['lat']] == NULL || $rec[$dd['maps'][0]['lng']] == NULL) { continue; } $lat = $rec[$dd['maps'][0]['lat']]; $lng = $rec[$dd['maps'][0]['lng']]; $cood = ''; if (!isset($dd['maps'][0]['cood_type']) || $dd['maps'][0]['cood_type'] != 'dms') { $cood = $w . $lng . $w . $s . $w . $lat . $w; } else { $cood = $w . dms2dc($lng) . $w . $s . $w . dms2dc($lat) . $w; } $csv .= $cood . $s; $csv .= $w . $rec[$dd['maps'][0]['title']] . $w . $nl; } file_put_contents("{$file_name}.vrt", $vrt); file_put_contents("{$file_name}.csv", $csv); system("ogr2ogr {$path} {$file_name}.vrt"); header('Content-Description: File Transfer'); header('Content-Type: ' . 'application/zip'); header('Content-Disposition: attachment; filename=' . preg_replace('/\\W/', '_', $dd['title']) . '.zip'); $tmp = tempnam("/tmp", "shp"); $z = new ZipArchive(); $z->open($tmp, ZIPARCHIVE::OVERWRITE); $z->addFile("{$file_name}.csv", 'data.csv'); $z->addFile("{$file_name}.vrt", 'data.vrt'); $z->addFile("{$file_name}.shp", 'data.shp'); $z->addFile("{$file_name}.shx", 'data.shx'); $z->addFile("{$file_name}.dbf", 'data.dbf'); $z->close(); unlink("{$file_name}.csv"); unlink("{$file_name}.vrt"); unlink("{$file_name}.shp"); unlink("{$file_name}.shx"); unlink("{$file_name}.dbf"); rmdir($path); ob_end_flush(); readfile($tmp); unlink($tmp); exit; }
function filter($res, &$dd) { $data = $res['data']; header('Content-Description: File Transfer'); header('Content-Type: ' . 'application/vnd.google-earth.kml+xml'); header('Content-Disposition: attachment; filename=' . preg_replace('/\\W/', '_', $dd['title']) . '.kml'); print '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; ?> <kml xmlns="http://earth.google.com/kml/2.2"> <Document> <name><?php echo $dd['title']; ?> </name> <description><![CDATA[<?php echo $dd['title']; ?> ]]></description> <Style id="style0"> <IconStyle> <Icon> <href>http://maps.gstatic.com/intl/en_us/mapfiles/ms/micons/blue-dot.png</href> </Icon> </IconStyle> </Style> <?php if (!isset($dd['maps'])) { return; } while ($rec = mysql_fetch_assoc($data)) { if ($rec[$dd['maps'][0]['lat']] == NULL || $rec[$dd['maps'][0]['lng']] == NULL) { continue; } $lat = $rec[$dd['maps'][0]['lat']]; $lng = $rec[$dd['maps'][0]['lng']]; $cood = ''; if (!isset($dd['maps'][0]['cood_type']) || $dd['maps'][0]['cood_type'] != 'dms') { $cood = "{$lng},{$lat},0.000000"; } else { $cood = dms2dc($lng) . ',' . dms2dc($lat) . ',0.000000'; } $pm = '<Placemark>'; $pm .= '<name>' . htmlentities($rec[$dd['maps'][0]['title']]) . '</name>'; $pm .= '<description><![CDATA[<div dir="ltr">' . htmlentities($rec[$dd['maps'][0]['title']]); if (isset($dd['maps'][0]['info'])) { $info_str = $dd['maps'][0]['info']; foreach ($rec as $key => $val) { $info_str = str_replace('{' . $key . '}', $rec[$key], $info_str); $info_str = str_replace('{' . $key . '|html}', $rec[$key], $info_str); } $pm .= "<br />{$info_str}"; } $pm .= '</div>]]></description>'; $pm .= '<styleUrl>#style0</styleUrl>'; $pm .= '<Point>'; $pm .= '<coordinates>' . $cood . '</coordinates>'; $pm .= '</Point>'; $pm .= '</Placemark>'; print $pm; } ?> </Document> </kml> <?php }