コード例 #1
0
 $qo = $q;
 if (strlen($qo) > 64) {
     $qo = '--complex query--';
 }
 if ($r) {
     //Handle Error
 } elseif (!empty($e)) {
     //Location search
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     $e = floor($e / 1000);
     $n = floor($n / 1000);
     $grs = array();
     for ($x = $e - 2; $x <= $e + 2; $x++) {
         for ($y = $n - 2; $y <= $n + 2; $y++) {
             list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 4, $square->reference_index, false);
             $grs[] = $gr2;
         }
     }
     if (strpos($q, '~') === 0) {
         $q = preg_replace('/^\\~/', '', $q);
         $q = "(" . str_replace(" ", " | ", $q) . ") (" . join(" | ", $grs) . ")";
     } else {
         $q .= " (" . join(" | ", $grs) . ")";
     }
     $qo .= " near {$gr}";
 }
 if (1) {
     //text query
     // --------------
     require "3rdparty/sphinxapi.php";
コード例 #2
0
 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);
     }
 }
コード例 #3
0
ファイル: submit.php プロジェクト: s-a-r-id/geograph-project
     $lat *= -1;
 }
 if (is_array($exif['GPS']['GPSLongitude'])) {
     $deg = FractionToDecimal($exif['GPS']['GPSLongitude'][0]);
     $min = FractionToDecimal($exif['GPS']['GPSLongitude'][1]);
     $sec = FractionToDecimal($exif['GPS']['GPSLongitude'][2]);
     $long = ExifConvertDegMinSecToDD($deg, $min, $sec);
 } else {
     //not sure if this will ever happen but it could?
     $long = $exif['GPS']['GPSLongitude'];
 }
 if ($exif['GPS']['GPSLongitudeRef'] == 'W') {
     $long *= -1;
 }
 list($e, $n, $reference_index) = $conv->wgs84_to_national($lat, $long);
 list($_POST['photographer_gridref'], $len) = $conv->national_to_gridref(intval($e), intval($n), 0, $reference_index);
 if (isset($exif['GPS']['GPSDestLatitude'])) {
     if (is_array($exif['GPS']['GPSDestLatitude'])) {
         $deg = FractionToDecimal($exif['GPS']['GPSDestLatitude'][0]);
         $min = FractionToDecimal($exif['GPS']['GPSDestLatitude'][1]);
         $sec = FractionToDecimal($exif['GPS']['GPSDestLatitude'][2]);
         $lat = ExifConvertDegMinSecToDD($deg, $min, $sec);
     } else {
         //not sure if this will ever happen but it could?
         $lat = $exif['GPS']['GPSDestLatitude'];
     }
     if ($exif['GPS']['GPSDestLatitudeRef'] == 'S') {
         $lat *= -1;
     }
     if (is_array($exif['GPS']['GPSDestLongitude'])) {
         $deg = FractionToDecimal($exif['GPS']['GPSDestLongitude'][0]);
コード例 #4
0
ファイル: browse.php プロジェクト: s-a-r-id/geograph-project
         $square->assignDiscussionToSmarty($smarty);
     }
     if (!empty($CONF['sphinx_host'])) {
         //look for images from here...
         $sphinx = new sphinxwrapper();
         if (!isset($viewpoint_count) && ($viewpoint_count = $sphinx->countImagesViewpoint($square->nateastings, $square->natnorthings, $square->reference_index, $square->grid_reference))) {
             $smarty->assign('viewpoint_count', $viewpoint_count);
             #$smarty->assign('viewpoint_query', $sphinx->q);
         }
         if (!isset($mention_count) && ($mention_count = $sphinx->countQuery("{$square->grid_reference} -grid_reference:{$square->grid_reference}", "_images"))) {
             $smarty->assign('mention_count', $mention_count);
         }
     }
     if ($square->natspecified && $square->natgrlen >= 6) {
         $conv = new Conversions('');
         list($gr6, $len) = $conv->national_to_gridref($square->getNatEastings(), $square->getNatNorthings(), 6, $square->reference_index, false);
         $smarty->assign('gridref6', $gr6);
     }
 } else {
     $smarty->assign('errormsg', $square->errormsg);
     //includes a closest match?
     if (is_object($square->nearest)) {
         $smarty->assign('nearest_distance', $square->nearest->distance);
         $smarty->assign('nearest_gridref', $square->nearest->grid_reference);
         if (!empty($square->x) && !empty($square->y) && $square->nearest->distance < 15) {
             //we where still able to work out the location, so
             //get a token to show a suroudding geograph map
             $mosaic = new GeographMapMosaic();
             $smarty->assign('map_token', $mosaic->getGridSquareToken($square));
         }
     }
コード例 #5
0
 function findPlacename($placename)
 {
     global $places;
     //only way to get the array into the compare functions
     global $USER;
     global $CONF, $memcache;
     $mkey = strtolower(trim($placename)) . '.v5';
     //need to invalidate the whole cache.
     //fails quickly if not using memcached!
     $places =& $memcache->name_get('g', $mkey);
     if ($places) {
         return $places;
     }
     $db = $this->_getDB();
     $ismore = 0;
     $placename = str_replace('?', '', $placename, $ismore);
     $places = array();
     if (is_numeric($placename)) {
         if ($placename > 10000000) {
             $places = $db->GetAll("select name as full_name,'PPL' as dsg, e, n, reference_index,'' as adm1_name from loc_towns where id=" . $db->Quote($placename - 10000000));
         } elseif ($placename > 1000000) {
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name from os_gaz where seq=" . $db->Quote($placename - 1000000));
         } else {
             $places = $db->GetAll("select full_name,dsg,e,n,loc_placenames.reference_index,loc_adm1.name as adm1_name from loc_placenames left join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country) where id=" . $db->Quote($placename));
         }
     } elseif (!$ismore) {
         list($placename, $county) = preg_split('/\\s*,\\s*/', $placename);
         if (!empty($county)) {
             $qcount = $db->Quote($county);
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name,code_name as dsg_name,(seq + 1000000) as id,km_ref as gridref from os_gaz inner join os_gaz_code using (f_code) where def_nam=" . $db->Quote($placename) . " and (full_county = {$qcount} OR hcounty = {$qcount})");
         } else {
             $qplacename = $db->Quote($placename);
             $sql_where = "def_nam={$qplacename}";
             $sql_where2 = "full_name={$qplacename}";
             if (strpos($placename, ' ') !== FALSE) {
                 $county = $db->getOne("select `name` from os_gaz_county where {$qplacename} LIKE CONCAT('%',name)");
                 if (!empty($county)) {
                     $qcount = $db->Quote($county);
                     $placename = preg_replace("/\\s+{$county}/i", '', $placename);
                     $qplacename = $db->Quote($placename);
                     $sql_where .= " or (def_nam={$qplacename} and full_county = {$qcount})";
                     $sql_where2 .= " or full_name={$qplacename}";
                     //we cant search easily on county here!
                 }
             }
             //todo need to 'union'  with other gazetterr! (as if one match in each then will no work!)
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name,code_name as dsg_name,(seq + 1000000) as id,km_ref as gridref from os_gaz inner join os_gaz_code using (f_code) where {$sql_where}");
             if (count($places) == 0) {
                 $places = $db->GetAll("select full_name,dsg,e,n,reference_index,id,loc_dsg.name as dsg_name from loc_placenames inner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) where full_name={$qplacename}");
                 if ($c = count($places)) {
                     require_once 'geograph/conversions.class.php';
                     $conv = new Conversions();
                     foreach ($places as $id => $row) {
                         if (empty($row['gridref'])) {
                             list($places[$id]['gridref'], ) = $conv->national_to_gridref($row['e'], $row['n'], 4, $row['reference_index']);
                         }
                         $places[$id]['full_name'] = _utf8_decode($row['full_name']);
                     }
                 }
             }
         }
     }
     if (count($places) == 1) {
         #we done!
     } else {
         $limit = strlen($placename) > 3 ? 60 : 20;
         $limi2 = 40;
         if ($USER->registered) {
             $limit *= 2;
             $limi2 *= 2;
         }
         //starts with (both gaz's)
         $places = $db->GetAll($sql = "\r\n\t\t\t(select\r\n\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t1 as reference_index,\r\n\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\tkm_ref as gridref\r\n\t\t\tfrom \r\n\t\t\t\tos_gaz\r\n\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\twhere\r\n\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t`def_nam` LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\tlimit {$limit}) UNION\r\n\t\t\t(select \r\n\t\t\t\tid, \r\n\t\t\t\tfull_name,\r\n\t\t\t\tdsg,e,n,\r\n\t\t\t\tloc_dsg.name as dsg_name,\r\n\t\t\t\tloc_placenames.reference_index,\r\n\t\t\t\tloc_adm1.name as adm1_name,\r\n\t\t\t\t'' as hist_county,\r\n\t\t\t\t'' as gridref\r\n\t\t\tfrom \r\n\t\t\t\tloc_placenames\r\n\t\t\t\tinner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) \r\n\t\t\t\tleft join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country)\r\n\t\t\twhere\r\n\t\t\t\tdsg LIKE 'PPL%' AND loc_placenames.reference_index != 1 AND\r\n\t\t\t\tfull_name LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\tgroup by gns_ufi\r\n\t\t\tLIMIT {$limit})");
         if (isset($_GET['debug'])) {
             print "<pre>{$sql}</pre>count = " . count($places) . "<hr>";
         }
         if (count($places) < 10 || $ismore) {
             //sounds like (OS)
             $places = array_merge($places, $db->GetAll("\r\n\t\t\t\tselect\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t\tdef_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") AND\r\n\t\t\t\t\tdef_nam NOT LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\t\tlimit {$limi2}"));
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count = " . count($places) . "<hr>";
             }
         }
         if (count($places) < 10 || $ismore) {
             //contains (OS)
             $places = array_merge($places, $db->GetAll($sql = "\r\n\t\t\t\tselect\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t\t`def_nam` LIKE " . $db->Quote('%' . $placename . '%') . " AND\r\n\t\t\t\t\t`def_nam` NOT LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\t\tlimit {$limi2}"));
             if (isset($_GET['debug'])) {
                 print "{$limi2}<pre>{$sql}</pre>count = " . count($places) . "<hr>";
             }
         }
         if (count($places) < 10 || $ismore) {
             //search the widest possible
             $places2 = $db->GetAll($sql = "\r\n\t\t\t\t(select\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code NOT IN ('C','T','O') AND\r\n\t\t\t\t\t( `def_nam` LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR def_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") )\r\n\t\t\t\torder by \r\n\t\t\t\t\tdef_nam = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tdef_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") desc\r\n\t\t\t\tlimit {$limi2}) UNION\r\n\t\t\t\t(select \r\n\t\t\t\t\tid, \r\n\t\t\t\t\tfull_name,\r\n\t\t\t\t\tdsg,e,n,\r\n\t\t\t\t\tloc_dsg.name as dsg_name,\r\n\t\t\t\t\tloc_placenames.reference_index,\r\n\t\t\t\t\tloc_adm1.name as adm1_name,\r\n\t\t\t\t\t'' as hist_county,\r\n\t\t\t\t\t'' as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tloc_placenames\r\n\t\t\t\t\tinner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) \r\n\t\t\t\t\tleft join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country)\r\n\t\t\t\twhere\r\n\t\t\t\t\tfull_name LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR full_name_soundex = SOUNDEX(" . $db->Quote($placename) . ")\r\n\t\t\t\tgroup by gns_ufi\r\n\t\t\t\torder by \r\n\t\t\t\t\tfull_name = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tfull_name_soundex = SOUNDEX(" . $db->Quote($placename) . ") desc\r\n\t\t\t\tLIMIT {$limi2})");
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count2 = " . count($places2) . "<hr>";
             }
             if (count($places2)) {
                 if (count($places)) {
                     foreach ($places2 as $i2 => $place2) {
                         $found = 0;
                         $look = str_replace("-", ' ', $place2['full_name']);
                         foreach ($places as $i => $place) {
                             if ($place['full_name'] == $look && $place['reference_index'] == $place2['reference_index'] && ($d = pow($place['e'] - $place2['e'], 2) + pow($place['n'] - $place2['n'], 2)) && $d < 5000 * 5000) {
                                 $found = 1;
                                 break;
                             }
                         }
                         if (!$found) {
                             array_push($places, $place2);
                         }
                     }
                 } else {
                     $places =& $places2;
                 }
             }
         }
         # loc_towns
         if (count($places) < 10 || $ismore) {
             //search the widest possible
             //km_ref as gridref
             //county from loc_hier?
             //	`full_county` as adm1_name,
             $places2 = $db->GetAll($sql = "\r\n\t\t\t\tselect\r\n\t\t\t\t\t(id + 10000000) as id,\r\n\t\t\t\t\tname as full_name,\r\n\t\t\t\t\t'PPL' as dsg, e, n,\r\n\t\t\t\t\t'' as dsg_name,\r\n\t\t\t\t\treference_index,\r\n\t\t\t\t\t'' as adm1_name,\r\n\t\t\t\t\t'' as hist_county,\r\n\t\t\t\t\t'' as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tloc_towns\r\n\t\t\t\twhere\r\n\t\t\t\t\t( name LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR name SOUNDS LIKE " . $db->Quote($placename) . ")\r\n\t\t\t\torder by \r\n\t\t\t\t\tname = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tname SOUNDS LIKE " . $db->Quote($placename) . " desc\r\n\t\t\t\tlimit {$limi2}");
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count2 = " . count($places2) . "<hr>";
             }
             if (count($places2)) {
                 if (count($places)) {
                     foreach ($places2 as $i2 => $place2) {
                         $found = 0;
                         $look = str_replace("-", ' ', $place2['full_name']);
                         foreach ($places as $i => $place) {
                             if ($place['full_name'] == $look && $place['reference_index'] == $place2['reference_index'] && ($d = pow($place['e'] - $place2['e'], 2) + pow($place['n'] - $place2['n'], 2)) && $d < 5000 * 5000) {
                                 $found = 1;
                                 break;
                             }
                         }
                         if (!$found) {
                             array_push($places, $place2);
                         }
                     }
                 } else {
                     $places =& $places2;
                 }
             }
         }
         if ($c = count($places)) {
             require_once 'geograph/conversions.class.php';
             $conv = new Conversions();
             foreach ($places as $id => $row) {
                 if (empty($row['gridref'])) {
                     list($places[$id]['gridref'], ) = $conv->national_to_gridref($row['e'], $row['n'], 4, $row['reference_index']);
                 }
                 $places[$id]['full_name'] = _utf8_decode($row['full_name']);
             }
             if ($c > 14) {
                 $placename = strtolower($placename);
                 foreach ($places as $id => $row) {
                     $p1 = strtolower($row['full_name']);
                     if (strpos($p1, $placename) === FALSE && levenshtein(strtolower($p1), $placename) > strlen($row['full_name']) / 2) {
                         unset($places[$id]);
                     }
                 }
             }
         }
     }
     //fails quickly if not using memcached!
     $memcache->name_set('g', $mkey, $places, $memcache->compress, $memcache->period_long);
     return $places;
 }
コード例 #6
0
ファイル: submit2.php プロジェクト: s-a-r-id/geograph-project
     $lat *= -1;
 }
 if (is_array($exif['GPS']['GPSLongitude'])) {
     $deg = FractionToDecimal($exif['GPS']['GPSLongitude'][0]);
     $min = FractionToDecimal($exif['GPS']['GPSLongitude'][1]);
     $sec = FractionToDecimal($exif['GPS']['GPSLongitude'][2]);
     $long = ExifConvertDegMinSecToDD($deg, $min, $sec);
 } else {
     //not sure if this will ever happen but it could?
     $long = $exif['GPS']['GPSLongitude'];
 }
 if ($exif['GPS']['GPSLongitudeRef'] == 'W') {
     $long *= -1;
 }
 list($e, $n, $reference_index) = $conv->wgs84_to_national($lat, $long);
 list($photographer_gridref, $len) = $conv->national_to_gridref(intval($e), intval($n), 0, $reference_index);
 $smarty->assign('photographer_gridref', $photographer_gridref);
 if (isset($exif['GPS']['GPSDestLatitude'])) {
     if (is_array($exif['GPS']['GPSDestLatitude'])) {
         $deg = FractionToDecimal($exif['GPS']['GPSDestLatitude'][0]);
         $min = FractionToDecimal($exif['GPS']['GPSDestLatitude'][1]);
         $sec = FractionToDecimal($exif['GPS']['GPSDestLatitude'][2]);
         $lat = ExifConvertDegMinSecToDD($deg, $min, $sec);
     } else {
         //not sure if this will ever happen but it could?
         $lat = $exif['GPS']['GPSDestLatitude'];
     }
     if ($exif['GPS']['GPSDestLatitudeRef'] == 'S') {
         $lat *= -1;
     }
     if (is_array($exif['GPS']['GPSDestLongitude'])) {
コード例 #7
0
 function getSubjectGridref($spaced = false)
 {
     //already calculated?
     if (!$spaced && strlen($this->subject_gridref)) {
         return $this->subject_gridref;
     }
     if ($spaced && strlen($this->subject_gridref_spaced)) {
         return $this->subject_gridref_spaced;
     }
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     if (empty($this->grid_square) && $this->gridsquare_id) {
         $this->grid_square = new GridSquare();
         if (is_object($this->db)) {
             $this->grid_square->_setDB($this->db);
         }
         $this->grid_square->loadFromId($this->gridsquare_id);
         $this->grid_reference = $this->grid_square->grid_reference;
         if ($this->nateastings) {
             $this->natspecified = 1;
             $this->grid_square->natspecified = 1;
             $this->grid_square->natgrlen = $this->natgrlen;
             $this->grid_square->nateastings = $this->nateastings;
             $this->grid_square->natnorthings = $this->natnorthings;
         }
     }
     //if this image doesnt have an exact position then we need to remove
     //the move to the center of the square
     //must be before getNatEastings is called
     $correction = $this->natgrlen > 4 ? 0 : 500;
     list($gr, $len) = $conv->national_to_gridref($this->grid_square->getNatEastings() - $correction, $this->grid_square->getNatNorthings() - $correction, max(4, $this->natgrlen), $this->grid_square->reference_index, false);
     list($grsp, $lensp) = $conv->national_to_gridref($this->grid_square->getNatEastings() - $correction, $this->grid_square->getNatNorthings() - $correction, $this->use6fig ? min(6, $this->natgrlen) : max(4, $this->natgrlen), $this->grid_square->reference_index, true);
     $this->subject_gridref = $gr;
     $this->subject_gridref_spaced = $grsp;
     $this->subject_gridref_precision = pow(10, 6 - $len) / 10;
     return $spaced ? $grsp : $gr;
 }