public function setSpatial($data) { require_once 'geograph/conversions.class.php'; $conv = new Conversions(); list($e, $n, $reference_index) = $conv->internal_to_national($data['x'], $data['y'], 0); $e = floor($e / 1000); $n = floor($n / 1000); $grs = array(); list($gr2, $len) = $conv->national_to_gridref($e * 1000, $n * 1000, 4, $reference_index, false); if ($data['d'] == 1) { $this->filters['grid_reference'] = $gr2; } elseif ($data['d'] < 10) { #$grs[] = $gr2; for ($x = $e - $data['d']; $x <= $e + $data['d']; $x++) { for ($y = $n - $data['d']; $y <= $n + $data['d']; $y++) { list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 4, $reference_index, false); $grs[] = $gr2; } } $this->filters['grid_reference'] = "(" . join(" | ", $grs) . ")"; } else { #$this->filters['grid_reference'] = $gr2; $d = intval($data['d'] / 10) * 10; for ($x = $e - $d; $x <= $e + $d; $x += 10) { for ($y = $n - $d; $y <= $n + $d; $y += 10) { list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 2, $reference_index, false); $grs[] = $gr2; } } $this->filters['hectad'] = "(" . join(" | ", $grs) . ")"; } if ($data['d'] > 1) { list($lat, $long) = $conv->national_to_wgs84($e * 1000 + 500, $n * 1000 + 500, $reference_index); $cl = $this->_getClient(); $cl->SetGeoAnchor('wgs84_lat', 'wgs84_long', deg2rad($lat), deg2rad($long)); $cl->SetFilterFloatRange('@geodist', 0.0, floatval($data['d'] * 1000)); } else { $this->sort = preg_replace('/@geodist \\w+,?\\s*/', '', $this->sort); } }
function _plotPlacenames(&$img, $scanleft, $scanbottom, $scanright, $scantop, $bottom, $left) { $db =& $this->_getDB(); $black = imagecolorallocate($img, 0, 64, 0); require_once 'geograph/conversions.class.php'; $conv = new Conversions(); if (!$this->reference_index) { $this->getGridRef(-1, -1); if (!$this->reference_index) { $this->getGridRef(-1, -1); $this->reference_index = 1; } } $reference_index = $this->reference_index; $gridcol = imagecolorallocate($img, 109, 186, 178); list($natleft, $natbottom) = $conv->internal_to_national($scanleft, $scanbottom, $reference_index); list($natright, $nattop) = $conv->internal_to_national($scanright, $scantop, $reference_index); if ($this->pixels_per_km < 1) { $div = 500000; //1 per 500k square $crit = "s = '1' AND"; $cityfont = 3; } elseif ($this->pixels_per_km == 1) { $div = 100000; $crit = "(s = '1' OR s = '2') AND"; $cityfont = 3; } elseif ($this->pixels_per_km == 4) { $div = 30000; # $crit = "(s = '1' OR s = '2') AND"; $cityfont = 3; } else { $div = 10000; $cityfont = 3; } $intleft = $scanleft * 1000; $intright = $scanright * 1000; $intbottom = $scanbottom * 1000; $inttop = $scantop * 1000; $rectangle = "'POLYGON(({$natleft} {$natbottom},{$natright} {$natbottom},{$natright} {$nattop},{$natleft} {$nattop},{$natleft} {$natbottom}))'"; $rectanglexy = "'POLYGON(({$intleft} {$intbottom},{$intright} {$intbottom},{$intright} {$inttop},{$intleft} {$inttop},{$intleft} {$intbottom}))'"; if ($reference_index == 1 || $reference_index == 2 && $this->pixels_per_km == 1 || $reference_index >= 3) { //$countries = "'EN','WA','SC'"; $sql = <<<END SELECT name,e,n,s,quad,reference_index FROM loc_towns WHERE {$crit} CONTAINS( GeomFromText({$rectanglexy}),\tpoint_xy) ORDER BY s END; #GROUP BY FLOOR(e/$div),FLOOR(n/$div) } else { $countries = "'NI','RI'"; $div *= 1.5; //becuase the irish data is more dence $sql = <<<END SELECT e,n,full_name as name,reference_index FROM loc_placenames INNER JOIN `loc_wikipedia` ON ( full_name = text ) WHERE dsg = 'PPL' AND loc_wikipedia.country IN ({$countries}) AND CONTAINS( GeomFromText({$rectangle}),\tpoint_en) GROUP BY gns_ufi ORDER BY RAND() END; } $squares = array(); $recordSet =& $db->Execute($sql); while (!$recordSet->EOF) { $e = $recordSet->fields['e']; $n = $recordSet->fields['n']; $str = floor($e / $div) . ' ' . floor($n / $div * 1.4); if (!$squares[$str]) { // || $recordSet->fields['s'] ==1) { $squares[$str]++; list($x, $y) = $conv->national_to_internal($e, $n, $recordSet->fields['reference_index']); $imgx1 = ($x - $left) * $this->pixels_per_km; $imgy1 = $this->image_h - ($y - $bottom + 1) * $this->pixels_per_km; if ($this->pixels_per_km <= 4) { imagefilledrectangle($img, $imgx1 - 1, $imgy1 - 2, $imgx1 + 1, $imgy1 + 2, $black); imagefilledrectangle($img, $imgx1 - 2, $imgy1 - 1, $imgx1 + 2, $imgy1 + 1, $black); } $font = $recordSet->fields['s'] == 1 ? $cityfont : 2; $img1 = $this->_posText($imgx1, $imgy1, $font, $recordSet->fields['name'], $recordSet->fields['quad']); if (count($img1)) { imageGlowString($img, $font, $img1[0], $img1[1], $recordSet->fields['name'], $gridcol); } } $recordSet->MoveNext(); } if ($_GET['d']) { exit; } $recordSet->Close(); }
$smarty = new GeographPage(); if (isset($_REQUEST['centi'])) { $smarty->assign('centi', 1); $smarty->assign('extra', 'centi'); $cacheid .= '|centi'; } if (isset($_REQUEST['inner'])) { $template = 'mapper_iframe.tpl'; } else { $template = 'mapper.tpl'; } if (!$smarty->is_cached($template, $cacheid)) { require_once 'geograph/conversions.class.php'; $conv = new Conversions(); $mapw = $mosaic->image_w / $mosaic->pixels_per_km / 2; list($e, $n) = $conv->internal_to_national($mosaic->map_x + $mapw, $mosaic->map_y + $mapw, 1); $smarty->assign('e', $e - 500); //remove centering $smarty->assign('n', $n - 500); switch ($mosaic->pixels_per_km) { case 1: $z = 0; break; //there isnt a direct equiv //there isnt a direct equiv case 4: $z = 0; break; // case ??: $z = 1; break; // case ??: $z = 1; break; case 40: