180 likes | 302 Views
Information and Mapping in the Public Interest www.greeninfo.org www.mapsportal.org . Roadmap. 1. About GreenInfo Network Web maps, GIS, and the take-away message Examples Techniques and program code Greg Allensworth , Senior Web GIS Developer gregor@greeninfo.org.
E N D
Information and Mapping in the Public Interest www.greeninfo.org www.mapsportal.org
Roadmap 1 • About GreenInfo Network • Web maps, GIS, and the take-away message • Examples • Techniques and program code Greg Allensworth, Senior Web GIS Developer gregor@greeninfo.org
GreenInfo Network 2 • Largest dedicated nonprofit GIS support group in U.S. • 16 years, 500 organizations • 14 staff, 20-30 projects at a time • Wide range of geospatial capacities • Extensive experience with foundations and mapping
1 Web maps, GIS, And the take-away message
Web Maps, GIS, and the take-away message 2 • The growth of the web. More interactive and engaging websites. Mobile devices. This means maps in the hands and eyes of billions. • Your map educates and it advocates, but…
It helps to be able to take something away, for analysis or for presentation 1
1 Some examples
1 Looks great! How do I do it?
TCPDF 1 • Library for producing PDFs in PHP. • Can generate sophisticated PDFs: pictures, borders, fills. • Can be tedious to adjust every pixel.
TCPDF 2 require_once('tcpdf/config/lang/eng.php'); require_once('tcpdf/tcpdf.php'); class MYPDF extends TCPDF { public function Header() { $this->Image(K_PATH_IMAGES.'legend.jpg', 5, 100); $this->Image(K_PATH_IMAGES.'report_header.png', 5, 5); $arial = $this->addTTFfont('Arial.ttf', '', 'TrueType'); $this->SetFont($arial, '', 24, '', false); $this->SetX(90); $this->SetY(10); $this->Cell(642, 55, "Duck Populations by Parcel, 2012", 0, 0, 'C'); } public function Footer() { $footfont = $this->addTTFfont('impact.ttf', '', 'TrueType'); $this->SetFont($footfont, '', 10, '', false); $date = date("F j, Y"); $this->Cell(762, 10, "Map created on $date. Disclaimer and so forth.", 0, 0, 'C'); } } $pdf = new MYPDF(L, 'px', LETTER, true, 'UTF-8', false); $pdf->AddPage(); $pdf->Image("/var/www/tmp/images.201209281107.jpg", 155, 70, 632, 507);
wkhtmltopdf / wkhtmltoimage 1 • Command-line utilities for Linux, using a real browser engine to draw pictures. Feed it a HTML file, it generates a PDF or JPEG file. • Supports JavaScript, including Google Maps, OpenLayers, et cetera. • Develop your PDF layouts in HTML, JavaScript, and CSS! • Command-line tool means saving HTML to a file, reading PDF as a file or capturing filename, …
wkhtmltopdf / wkhtmltoimage 2 $html .= <<<ENDOFPDF <html> <head> <style type="text/css"> @font-face { font-family:Calibri; src:url("file:/var/www/fonts/calibri.ttf"); format(TrueType); } body { font-size:12pt; font-family: Calibri; color:black; } @page { margin:0.25in 0.25in 0.25in0.25in; width:8.5in; height:11.0in; } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript" src="http://openlayers.org/dev/OpenLayers.js"></script> <script type="text/javascript"> $(document).ready(function () { var MAP = new OpenLayers.Map(‘map_canvas’, { other map setup options … }); var BBOX = new OpenLayers.Bounds({$_GET['west']},{$_GET['south']},{$_GET['east']},{$_GET['north']}); MAP.addLayer(new OpenLayers.Layer.Google("Streets", { } )); MAP.zoomToExtent(BBOX); }); </script> </head> <body> <div id="map_canvas"></div> </body> </html> ENDOFPDF ?>
wkhtmltopdf / wkhtmltoimage 3 // define a random directory name, and filenames under it // this allows a nice filename based on the County, without two people colliding if they ask for the same report $tempdir = md5(microtime() . mt_rand()); mkdir("/var/www/tmp/$tempdir"); $htmfile = sprintf("%s/ManagementOpportunitiesReport_%s.html", $tempdir, $county ); $pdffile = sprintf("%s/ManagementOpportunitiesReport_%s.pdf" , $tempdir, $county ); // using a simple require() we can load our variables into the template easily // with a template engine like Smarty or CodeIgniter, this is even better require 'report.pdf.php'; // save the HTML to a file // debugging is easy: simply print out the resulting HTML and see how it looks in our browser file_put_contents($htmfile, $html); //print $html; exit; // done, tell the browser where they can find the finished PDF // alternately, we could print Content-disposition headers to make the browser download the resulting PDF $command = escapeshellcmd("wkhtmltopdf --quiet --page-size letter $htmfile $pdffile"); header(sprintf("Location: /tmp/%s", basename($pdffile) ));
PHPExcel 1 • PHP library for reading and generating Excel spreadsheets. • Supports modern XLSX format, advanced spreadsheet options: formulas, embedding of links, images, etc.
PHPExcel 2 // load up PHPExcel require '/usr/lib/php/PHPExcel/Classes/PHPExcel.php'; require '/usr/lib/php/PHPExcel/Classes/PHPExcel/Writer/Excel2007.php'; $xls = new PHPExcel(); // set auto-sizing and bold for all columns, then the column titles in row 1 $xls->getActiveSheet()->setTitle('Species of Concern'); $xls->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); $xls->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); $xls->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); $xls->getActiveSheet()->getColumnDimension('D')->setAutoSize(true); $xls->getActiveSheet()->getStyle("A1")->getFont()->setBold(true); $xls->getActiveSheet()->getStyle("B1")->getFont()->setBold(true); $xls->getActiveSheet()->getStyle("C1")->getFont()->setBold(true); $xls->getActiveSheet()->getStyle("D1")->getFont()->setBold(true); $xls->getActiveSheet()->SetCellValue("A1", "COUNTY"); $xls->getActiveSheet()->SetCellValue("B1", "SPECIES"); $xls->getActiveSheet()->SetCellValue("C1", "PRIORITY"); $xls->getActiveSheet()->SetCellValue("D1", "COMMENTS"); $row = 1; foreach ($allspecies as $spec) { $row++; $sheet->SetCellValue("A$row", $spec['location_name']); $sheet->SetCellValue("B$row", $spec['species_binominal']); $sheet->SetCellValue("C$row", $spec['priority_rating']); $sheet->SetCellValue("D$row", $spec['editornote']); } // done! save it to disk, spit it out to the browser $tempfile = sprintf("/var/www/tmp/%s.xlsx", md5(mt_rand() . microtime() ) ); $xls = new PHPExcel_Writer_Excel2007($xls); $xls->save($tempfile); header("Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml"); header("Content-disposition: attachment; filename=\"SpeciesReport.xlsx\""); readfile($tempfile);
1 The take-away message