|
From: <il...@pr...> - 2004-11-17 12:01:44
|
Update of /cvsroot/meshdb/www/db2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25765 Added Files: ipv6-pi-addr.php Log Message: A handy page for looking up IPv6 provider independent geographic address prefixes (as specified in draft-hain-ipv6-pi-addr-07.txt) from coordinates. --- NEW FILE: ipv6-pi-addr.php --- <?php include "config.php"; include "util.php"; $lat = doubleval($_POST["lat"]); $lon = doubleval($_POST["lon"]); $e = doubleval($_POST["e"]); $n = doubleval($_POST["n"]); $zone = intval($_POST["zone"]); if (empty($zone)) $zone = 56; $usegrid = $_POST["usegrid"]; $USECURV = "Obtain from curvilinear"; $USEGRID = "Obtain from UTM"; $EQUATORIAL_SCALE = 0.000057220458984375; $POLAR_SCALE = 0.00017166137695312500; $FP = "1000"; /* Do we have anything to compute? */ if (!empty($usegrid)) { /************************************** * Compute the prefix for this point. */ /* Convert to WGS 84 curvilinear coordinates. */ if ($usegrid == $USEGRID) { list($lat, $lon) = cvtlatlon($e, $n, $zone); } else { list($e, $n, $zone) = cvteastnorth($lat, $lon, $findzone=1); } /* Shift origin to south pole at 90 degrees east. */ if ($lon < 90) $seclon = $lon + 270; else $seclon = $lon - 90; $seclat = $lat + 90; /* Shift origin to southwest of section. */ if ($seclat < 30) { /* Antarctica. */ $section = 6; } elseif ($seclat >= 150) { /* Arctic. */ $section = 7; $seclat -= 150; } else { /* Equatorial band. */ $seclat -= 30; if ($seclon < 120) { /* Asia. */ $section = 0; } else if ($seclon < 240) { /* America. */ $section = 1; $seclon -= 120; } else { /* Europe. */ $section = 2; $seclon -= 240; } } /* Scale to [0..2^21). */ if ($section < 3) { /* Equatorial band. */ $scaledlon = intval($seclon / $EQUATORIAL_SCALE); $scaledlat = intval($seclat / $EQUATORIAL_SCALE); } else { /* Polar bands. */ $scaledlon = intval($seclon / $POLAR_SCALE); $scaledlat = intval($seclat / $POLAR_SCALE); } /* Convert to binary. */ $binlon = sprintf("%021b", $scaledlon); $binlat = sprintf("%021b", $scaledlat); if ($section > 3) { $binsec = sprintf("%03b", $section); } else { $binsec = sprintf("%02b", $section); } /* Construct the address as a binary string. */ $addr = $FP.$binsec; for ($i = 0; $i < 21; $i++) { if ($section <= 3 || $i > 0) $addr .= $binlat{$i}; $addr .= $binlon{$i}; } /* Format it as colon-separated hex. */ $hexaddr = ""; for ($i = 0; $i < 3; $i++) { if ($i > 0) $hexaddr .= ":"; $word = substr($addr, $i * 16, 16); $hexaddr .= dechex(bindec($word)); } $hexaddr{0} = "x"; /************************************** * Compute the area for this prefix. */ /* Convert the range back to a scaled decimal number. */ $scaledlon1 = bindec($binlon); $scaledlat1 = bindec($binlat); $scaledlon2 = $scaledlon + 1; $scaledlat2 = $scaledlat + 1; /* Scale it back up to degrees within the section. */ if ($section < 3) { $seclon1 = $scaledlon1 * $EQUATORIAL_SCALE; $seclat1 = $scaledlat1 * $EQUATORIAL_SCALE; $seclon2 = $scaledlon2 * $EQUATORIAL_SCALE; $seclat2 = $scaledlat2 * $EQUATORIAL_SCALE; } else { $seclon1 = $scaledlon1 * $POLAR_SCALE; $seclat1 = $scaledlat1 * $POLAR_SCALE; $seclon2 = $scaledlon2 * $POLAR_SCALE; $seclat2 = $scaledlat2 * $POLAR_SCALE; } /* Convert them to ordinary degrees. */ $lon1 = $seclon1; $lon2 = $seclon2; if ($section < 3) { $lat1 = $seclat1 - 60; $lat2 = $seclat2 - 60; $lon1 = $seclon1 + 90 + (120 * $section); $lon2 = $seclon2 + 90 + (120 * $section); } else { if ($section = 6) { /* Antarctica. */ $lat1 = $seclat1 - 90; $lat2 = $seclat2 - 90; } else { /* Arctic. */ $lat1 = $lat1 + 60; $lat2 = $lat2 + 60; } } if ($lon1 > 180) $lon1 -=360; if ($lon2 > 180) $lon2 -= 360; /* Convert to UTM. */ list($e1, $n1, $zone1) = cvteastnorth($lat1, $lon1, $findzone=1); list($e2, $n2, $zone2) = cvteastnorth($lat2, $lon2, $findzone=1); } ?> <html> <head> <link rel="stylesheet" href="<?=$PREF["stylesheet"]?>" type="text/css"> <link rel="icon" href="favicon.ico"> <title>IPv6 geographic provider independent addressing</title> <body> <h1>IPv6 geographic provider independent addressing</h1> <p> IPv6 geographic provider independent addressing is proposed in <a href="http://www.ietf.org/internet-drafts/draft-hain-ipv6-pi-addr-07.txt">draft-hain-ipv6-pi-addr</a> and provides a way to obtain unique IPv6 address from one's physical location on the earth's surface. It provides a 48 bit prefix for each area of a few square metres. </p> <?php if ($e && $n && $zone == $ZONE) { ?> <img align="right" width="200" height="200" src="map2b.php?s=0.1&w=200&h=200&n=<?=$n?>&e=<?=$e?>&markcentre=1&shownonodes=0" alt="location"> <?php } ?> <form method="post"> <table> <tr> <th width="50%" colspan="2" style="text-align: center">Curvilinear</th> <th width="50%" colspan="2" style="text-align: center">UTM</th> </tr> <tr> <td style="text-align: right"> Latitude: </td> <td> <input name="lat" value="<?=htmlspecialchars(printf("%.5f", $lat))?>" size="10">°N </td> <td style="text-align: right"> Northing: </td> <td> <input name="n" value="<?=htmlspecialchars(printf("%.1f", $n))?>" size="10">m </td> </tr> <tr> <td style="text-align: right"> Longitude: </td> <td> <input name="lon" value="<?=htmlspecialchars(printf("%.5f", $lon))?>" size="10">°E </td> <td style="text-align: right"> Easting: </td> <td> <input name="e" value="<?=htmlspecialchars(printf("%.1f", $e))?>" size="10">m </td> </tr> <tr> <td></td> <td></td> <td style="text-align: right"> Zone: </td> <td> <input name="zone" value="<?=htmlspecialchars($zone)?>" size="4"> </td> </tr> <tr> <td style="text-align: right">System:</td> <td>WGS84</td> <td style="text-align: right">System:</td> <td>AGD66</td> </tr> <tr> <td colspan="2" style="text-align: center"> <input type="submit" name="usegrid" value="<?=$USECURV?>"> </td> <td colspan="2" style="text-align: center"> <input type="submit" name="usegrid" value="<?=$USEGRID?>"> </td> </tr> <?php /* Did we compute anything? */ if (isset($hexaddr)) { ?> <tr> <td colspan="4"> <br> <font size="+1">Prefix for this site is: <b><tt><?=$hexaddr?>::/48</tt><b></font>. <br><br> </td> </tr> <tr> <td style="text-align: right"> Latitude: </td> <td> <?=printf("%.5f", abs($lat1))?>°<?=$lat1 >= 0 ? "N" : "S"?> </td> <td style="text-align: right"> Northing: </td> <td> <?=printf("%.1f", $n1)?>m </td> </tr> <tr> <td style="text-align: right"> to: </td> <td> <?=printf("%.5f", abs($lat2))?>°<?=$lat2 >= 0 ? "N" : "S"?> </td> <td style="text-align: right"> to: </td> <td> <?=printf("%.1f", $n2)?>m (<?=printf("%.1f", abs($n2 - $n1))?>m) </td> </tr> <tr> <td style="text-align: right"> Longitude: </td> <td> <?=printf("%.5f", abs($lon1))?>°<?=$lon1 >= 0 ? "E" : "W"?> </td> <td style="text-align: right"> Easting: </td> <td> <?=printf("%.1f", $e1)?>m </td> </tr> <tr> <td style="text-align: right"> to: </td> <td> <?=printf("%.5f", abs($lon2))?>°<?=$lon2 >= 0 ? "E" : "W"?> </td> <td style="text-align: right"> to: </td> <td> <?=printf("%.1f", $e2)?>m (<?=printf("%.1f", abs($e2 - $e1))?>m) </td> </tr> <?php } ?> </table> </form> <?php if ($hexaddr && False) { print $section." ".$seclat." ".$seclon."<br>"; print $scaledlon." ".$scaledlat."<br>"; print $binsec." ".$binlat." ".$binlon."<br>"; print $addr." (".strlen($addr).")<br>"; //print $binlat1." ".$binlon1."<br>"; //print $binlat2." ".$binlon2."<br>"; print $scaledlat1." ".$scaledlon1."<br>"; print $scaledlat2." ".$scaledlon2."<br>"; print $seclat1." ".$seclon1."<br>"; print $seclat2." ".$seclon2."<br>"; print $lat1."° ".$lon1."°<br>"; print $lat2."° ".$lon2."°<br>"; print "Z".$zone1." ".$n1."N ".$e1."E<br>"; print "Z".$zone2." ".$n2."N ".$e2."E<br>"; } if ($zone != $ZONE) { print "<p><font size=\"+1\"><b>Note:</b> UTM coordinates on this page are accurate only within Queensland.</font></p>"; } ?> <hr> <a href="..">Brisbane Mesh</a> | <a href=".">Node database</a> </body> </html> |