Beispiel #1
0
 public function addProblem($problem, $category, $name, $email, $x, $y)
 {
     if ($this->isValid()) {
         $xy = reproject($x, $y, "4326", "3857");
         $q = "INSERT INTO hampshire_problems(row_gid,problem,category,x,y," . "subdate) VALUES (" . $this->the_data["properties"]["gid"] . ",'{$problem}','{$category}'," . $xy[0] . "," . $xy[1] . ",NOW()) ";
         pg_query($q);
         $msg = "Parish: " . $this->the_data["properties"]["parish"] . "\n" . "ROW number: " . $this->the_data["properties"]["routeno"] . "\nROW type: " . $this->the_data["properties"]["row_type"] . "\n\nCategory: {$category}\n\nProblem: {$problem}\n\n";
         $c = new ConversionsLatLong();
         $osgb = $c->wgs84_to_osgb36($y, $x);
         //$gr = $c->osgb36_to_gridref($osgb[0],$osgb[1]);
         $msg .= "Grid ref: easting " . round($osgb[0]) . " northing " . round($osgb[1]) . "\n\n";
         $msg .= "Reported By: {$name} (email {$email})";
         if ($this->the_data["properties"]["county"] == "Hampshire") {
             mail(HANTS_EMAIL, "Right Of Way problem reported via FixMyPaths", $msg);
         }
     }
 }
 function wgs84_to_national($lat, $long, $usehermert = true)
 {
     require_once 'geograph/conversionslatlong.class.php';
     $conv = new ConversionsLatLong();
     $ire = $lat > 51.2 && $lat < 55.73 && $long > -12.2 && $long < -4.8;
     $uk = $lat > 49 && $lat < 62 && $long > -9.5 && $long < 2.3;
     if ($uk && $ire) {
         //rough border for ireland
         $ireland = array(array(-12.19, 50.38), array(-6.39, 50.94), array(-5.07, 53.71), array(-5.25, 54.71), array(-6.13, 55.42), array(-10.65, 56.15), array(-12.19, 50.38));
         $ire = $this->pointInside(array($long, $lat), $ireland);
         $uk = 1 - $ire;
     }
     if ($ire) {
         return array_merge($conv->wgs84_to_irish($lat, $long, $usehermert), array(2));
     } else {
         if ($uk) {
             return array_merge($conv->wgs84_to_osgb36($lat, $long), array(1));
         }
     }
 }
Beispiel #3
0
function reproject($x, $y, $inProj, $outProj)
{
    // Project to wgs84 latlon
    $inProj = strtoupper($inProj);
    $outProj = strtoupper($outProj);
    switch ($inProj) {
        case 'GOOGLE':
        case 'EPSG:900913':
        case '900913':
        case '3785':
        case 'EPSG:3785':
        case '3857':
        case 'EPSG:3857':
            $ll = sphmerc_to_ll($x, $y);
            break;
        case 'OSGB':
        case '27700':
        case 'EPSG:27700':
            /*
            $ll = gr_to_wgs84_ll($x,$y);
            $ref = new OSRef($x,$y);
            $latlng = OSRefToLatLng($ref);
            $ll = array("lon"=>$latlng->lng,"lat"=>$latlng->lat);
            */
            // 17/4/13 now use Barry Hunter's geograph code, seems to be
            // most accurate of these
            $c = new ConversionsLatLong();
            $ll0 = $c->osgb36_to_wgs84($x, $y);
            $ll = array("lon" => $ll0[1], "lat" => $ll0[0]);
            break;
        default:
            $ll = array("lon" => $x, "lat" => $y);
    }
    // Project from wgs84 latlon to output format
    switch ($outProj) {
        case 'GOOGLE':
        case 'EPSG:900913':
        case '900913':
        case '3785':
        case 'EPSG:3785':
        case '3857':
        case 'EPSG:3857':
            $sm = ll_to_sphmerc($ll['lon'], $ll['lat']);
            $x = $sm['e'];
            $y = $sm['n'];
            break;
        case 'OSGB':
        case '27700':
        case 'EPSG:27700':
            /*
            $gr = wgs84_ll_to_gr($ll['lon'],$ll['lat']);
            $x = $gr['e'];
            $y = $gr['n'];
            $ll = new LatLng($ll['lat'],$ll['lon']);
            $gr = LatLngToOSRef($ll);
            $x = $gr->easting;
            $y = $gr->northing;
            */
            // 17/4/13 now use Barry Hunter's geograph code, seems to be
            // most accurate of these
            $c = new ConversionsLatLong();
            $gr = $c->wgs84_to_osgb36($ll['lat'], $ll['lon']);
            $x = $gr[0];
            $y = $gr[1];
            break;
        default:
            $x = $ll['lon'];
            $y = $ll['lat'];
            break;
    }
    return array($x, $y);
}
            $smarty->assign('querytime', "200 conversions took " . number_format($querytime_after - $querytime_before, 4) . " Seconds");
        } else {
            //todo: make an educated guess - basically if could be irish then use that otherwise gb ?!? - probably not...
        }
    }
    if (count($latlong)) {
        $smarty->assign('lat', $latlong[0]);
        $smarty->assign('long', $latlong[1]);
        $smarty->assign('e', $_GET['e']);
        $smarty->assign('n', $_GET['n']);
    }
} else {
    if ($_GET['From']) {
        //from lat/long
        if ($_GET['datum'] == 'osgb36') {
            $en = $conv->wgs84_to_osgb36($_GET['lat'], $_GET['long']);
        } else {
            if ($_GET['datum'] == 'irish') {
                list($usec, $sec) = explode(' ', microtime());
                $querytime_before = (double) $usec + (double) $sec;
                for ($q = 0; $q < 200; $q++) {
                    $en = $conv->wgs84_to_irish($_GET['lat'], $_GET['long'], $_GET['usehermert']);
                }
                $en = $conv->wgs84_to_irish($_GET['lat'], $_GET['long'], $_GET['usehermert']);
                list($usec, $sec) = explode(' ', microtime());
                $querytime_after = (double) $usec + (double) $sec;
                $smarty->assign('querytime', "200 conversions took " . number_format($querytime_after - $querytime_before, 4) . " Seconds");
            } else {
                list($e, $n, $reference_index) = $conv->wgs84_to_national($_GET['lat'], $_GET['long'], $_GET['usehermert']);
                if ($reference_index == 1) {
                    $en = array($e, $n);