Created
November 17, 2015 13:18
-
-
Save noahwilliamsson/682b0946088945192751 to your computer and use it in GitHub Desktop.
Konvertera SWEREF99 och RT90 till WGS84
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Conversion between RT90 and WGS84 (lat/lon) using the | |
| * Debian package proj-bin (PROJ.4) | |
| * | |
| * http://trac.osgeo.org/proj/ | |
| * http://wiki.openstreetmap.org/wiki/Converting_to_WGS84#Sweden | |
| * | |
| * -- noah, dec 2013 | |
| */ | |
| ?> | |
| <!DOCTYPE html> | |
| <html lang="sv"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Konvertera RT 90 till WGS84 (latitud, longitud)</title> | |
| <style type="text/css"> | |
| #wrapper { width: 800px; margin: 0 auto } | |
| th { font-weight:bold } | |
| table { border-collapse:collapse; } | |
| th, td { border: 1px solid black; padding: 2px 10px; } | |
| input { padding: 20px; width: 280px; border: 1px solid grey; margin: 5px; } | |
| textarea { border: 1px solid grey; margin: 5px; width: 300px; height: 100px } | |
| #tbl, #txt { width: 250px; float: left; padding: 5px 40px; } | |
| hr { clear: both } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="wrapper"> | |
| <h1>Konvertera RT 90 koordinater till WGS84 (lat/lon)</h1> | |
| <?php | |
| $frontpage = true; | |
| if(isset($_POST['text']) && !empty($_POST['text'])) | |
| $frontpage = false; | |
| if(isset($_FILES['rt90']) && $_FILES['rt90']['error'] == UPLOAD_ERR_OK) | |
| $frontpage = false; | |
| ?> | |
| <?php if($frontpage): ?> | |
| <p> | |
| <p>Skapa en ren textfil (.txt) med <a href="https://sv.wikipedia.org/wiki/RT_90">RT 90</a> koordinater i två kolumner.<br /> | |
| Kolumnerna ska vara <em>X</em>- och <em>Y</em>-värden som är separerade med ett mellanslag eller en tabb.</p> | |
| <p> | |
| Ladda upp textfilen här så skrivs koordinaterna ut med latitud och longitud (<a href="https://sv.wikipedia.org/wiki/World_Geodetic_System_1984">WGS84</a>, krävs för Google Maps).<br /> | |
| Alternativt så kan koordinaterna klistras in i textrutan nedan.</p> | |
| <form method="post" action="/rt90/" enctype="multipart/form-data"> | |
| <input type="file" name="rt90" /><br /> | |
| <label for="text">Koordinater i textform (tabb- eller mellanslagsseparerade; en koordinat per rad)</label><br /> | |
| <textarea id="text" name="text"></textarea><br /> | |
| <button type="submit">Ladda upp</button> | |
| </form> | |
| <?php else: ?> | |
| <?php | |
| if(isset($_FILES['rt90']) && $_FILES['rt90']['error'] == UPLOAD_ERR_OK) { | |
| $f = $_FILES['rt90']; | |
| $filename = $f['tmp_name']; | |
| } | |
| else { | |
| $filename = tempnam('/tmp', 'rt90'); | |
| file_put_contents($filename, trim($_POST['text']) ."\n"); | |
| } | |
| /** | |
| * The decimal mark in Swedish locale is a comma whereas | |
| * proj4 always expects numbers to use a dot as decimal mark | |
| * Replace all occurences of comma with dot | |
| */ | |
| $data = file_get_contents($filename); | |
| $data = str_replace(',', '.', $data); | |
| file_put_contents($filename, $data); | |
| $args = array(); | |
| $args[] = 'invproj'; | |
| $args[] = '-r'; // interpret input in reverse order (?!!) | |
| $args[] = '-s'; // write output in reverse order | |
| $args[] = '-f'; // format string | |
| $args[] = '%.7f'; | |
| /** | |
| * These were taken from OSM: | |
| * http://wiki.openstreetmap.org/wiki/Converting_to_WGS84#Sweden | |
| */ | |
| $args[] = escapeshellarg('+ellps=WGS84'); | |
| $args[] = escapeshellarg('+proj=tmerc'); | |
| $args[] = escapeshellarg('+lat_0=0'); | |
| $args[] = escapeshellarg('+lon_0=015d48.377m'); | |
| $args[] = escapeshellarg('+k=1.0000056'); | |
| $args[] = escapeshellarg('+x_0=1500064.1'); | |
| $args[] = escapeshellarg('+y_0=-668.0'); | |
| $args[] = escapeshellarg($filename); | |
| $args[] = '2>&1'; | |
| $command = implode(' ', $args); | |
| $ret = exec($command, $output, $exitCode); | |
| if(!empty($output)): | |
| ?> | |
| <p>Konverterat data i latitud och longitud (WGS84) format. Kopiera och klistra till exempelvis Excel.<br /> | |
| Klicka här för att <a href="/rt90/">göra en ny konvertering</a>.</p> | |
| <div id="tbl"> | |
| <h2>I tabellform</h2> | |
| <table> | |
| <thead> | |
| <tr><th>Lat</th><th>Lon</th></tr> | |
| </thead> | |
| <tbody> | |
| <?php | |
| foreach($output as $line): | |
| list($lat, $lon) = explode("\t", trim($line)); | |
| ?> | |
| <tr> | |
| <td><?php echo htmlspecialchars($lat, ENT_NOQUOTES); ?></td> | |
| <td><?php echo htmlspecialchars($lon, ENT_NOQUOTES); ?></td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </tbody> | |
| </table> | |
| </div> | |
| <div id="txt"> | |
| <h2>Tabbseparerad text</h2> | |
| <pre><?php foreach($output as $line): echo htmlspecialchars($line ."\n", ENT_NOQUOTES); endforeach; ?></pre> | |
| </div> | |
| <?php endif; ?> | |
| <?php endif; ?> | |
| <hr /> | |
| <p>Se även konverteraren för <a href="/sweref99/">SWEREF 99 TM</a>. Koordinatsystemet används av bland annat Lantmäteriet.</p> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Conversion between SWEREF 99 TM and WGS84 (lat/lon) using the | |
| * Debian package proj-bin (PROJ.4) | |
| * | |
| * http://trac.osgeo.org/proj/ | |
| * | |
| * irc.oftc.net, #osm.se: | |
| * < vax> noah: testa: | |
| * < vax> echo "7082171 751438" | invproj -f '%.8f' -r +proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs | |
| * < noah> tack. det är relativt nära. med ett known target så verkar det dock diffa på ett par hundra meter. | |
| * < noah> fast det är kanske mina källkoordinater som är sunkiga. ett par andra tester gav bättre resultat. | |
| * < noah> (försöker konvertera koordinater på lagfarter från metria/lantmäteriet till något jag kan visa på en webbkarta) | |
| * < vax> du har några kontrollpunkter här: http://www.lantmateriet.se/Global/Kartor%20och%20geografisk%20information/GPS%20och%20m%C3%A4tning/Referenssystem/2D-system/kontrollpunkter_sweref99tm.pdf | |
| * | |
| * -- noah, dec 2013 | |
| */ | |
| ?> | |
| <!DOCTYPE html> | |
| <html lang="sv"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Konvertera SWEREF 99 TM till WGS84 (latitud, longitud)</title> | |
| <style type="text/css"> | |
| #wrapper { width: 800px; margin: 0 auto } | |
| th { font-weight:bold } | |
| table { border-collapse:collapse; } | |
| th, td { border: 1px solid black; padding: 2px 10px; } | |
| input { padding: 20px; width: 280px; border: 1px solid grey; margin: 5px; } | |
| textarea { border: 1px solid grey; margin: 5px; width: 300px; height: 100px } | |
| #tbl, #txt { width: 250px; float: left; padding: 5px 40px; } | |
| hr { clear: both } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="wrapper"> | |
| <h1>Konvertera SWEREF 99 TM koordinater till WGS84 (lat/lon)</h1> | |
| <?php | |
| $frontpage = true; | |
| if(isset($_POST['text']) && !empty($_POST['text'])) | |
| $frontpage = false; | |
| if(isset($_FILES['sweref99']) && $_FILES['sweref99']['error'] == UPLOAD_ERR_OK) | |
| $frontpage = false; | |
| ?> | |
| <?php if($frontpage): ?> | |
| <p> | |
| <p>Skapa en ren textfil (.txt) med <a href"=https://sv.wikipedia.org/wiki/SWEREF_99_TM">SWEREF 99 TM</a> koordinater i två kolumner.<br /> | |
| Kolumnerna ska vara <em>N</em>- och <em>E</em>-värden som är separerade med ett mellanslag eller en tabb.</p> | |
| <p> | |
| Ladda upp textfilen här så skrivs koordinaterna ut med latitud och longitud (<a href="https://sv.wikipedia.org/wiki/World_Geodetic_System_1984">WGS84</a>, krävs för Google Maps).<br /> | |
| Alternativt så kan koordinaterna klistras in i textrutan nedan.</p> | |
| <form method="post" action="/sweref99/" enctype="multipart/form-data"> | |
| <input type="file" name="sweref99" /><br /> | |
| <label for="text">Koordinater i textform (tabb- eller mellanslagsseparerade; en koordinat per rad)</label><br /> | |
| <textarea id="text" name="text"></textarea><br /> | |
| <button type="submit">Ladda upp</button> | |
| </form> | |
| <?php else: ?> | |
| <?php | |
| if(isset($_FILES['sweref99']) && $_FILES['sweref99']['error'] == UPLOAD_ERR_OK) { | |
| $f = $_FILES['sweref99']; | |
| $filename = $f['tmp_name']; | |
| } | |
| else { | |
| $filename = tempnam('/tmp', 'sweref99'); | |
| file_put_contents($filename, trim($_POST['text']) ."\n"); | |
| } | |
| /** | |
| * The decimal mark in Swedish locale is a comma whereas | |
| * proj4 always expects numbers to use a dot as decimal mark | |
| * Replace all occurences of comma with dot | |
| */ | |
| $data = file_get_contents($filename); | |
| $data = str_replace(',', '.', $data); | |
| file_put_contents($filename, $data); | |
| $args = array(); | |
| $args[] = 'invproj'; | |
| $args[] = '-r'; // interpret input in reverse order (?!!) | |
| $args[] = '-s'; // write output in reverse order | |
| $args[] = '-f'; // format string | |
| $args[] = '%.7f'; | |
| /** | |
| * These were taken from OSM: | |
| * http://wiki.openstreetmap.org/wiki/Converting_to_WGS84#Sweden | |
| */ | |
| $args[] = escapeshellarg('+proj=utm'); | |
| $args[] = escapeshellarg('+zone=33'); | |
| $args[] = escapeshellarg('+ellps=GRS80'); | |
| $args[] = escapeshellarg('+towgs84=0,0,0,0,0,0,0'); | |
| $args[] = escapeshellarg('+units=m'); | |
| $args[] = escapeshellarg('+no_defs'); | |
| $args[] = escapeshellarg($filename); | |
| $args[] = '2>&1'; | |
| $command = implode(' ', $args); | |
| $ret = exec($command, $output, $exitCode); | |
| if(!empty($output)): | |
| ?> | |
| <p>Konverterat data i latitud och longitud (WGS84) format. Kopiera och klistra till exempelvis Excel.<br /> | |
| Klicka här för att <a href="/sweref99/">göra en ny konvertering</a>.</p> | |
| <div id="tbl"> | |
| <h2>I tabellform</h2> | |
| <table> | |
| <thead> | |
| <tr><th>Lat</th><th>Lon</th></tr> | |
| </thead> | |
| <tbody> | |
| <?php | |
| foreach($output as $line): | |
| list($lat, $lon) = explode("\t", trim($line)); | |
| ?> | |
| <tr> | |
| <td><?php echo htmlspecialchars($lat, ENT_NOQUOTES); ?></td> | |
| <td><?php echo htmlspecialchars($lon, ENT_NOQUOTES); ?></td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </tbody> | |
| </table> | |
| </div> | |
| <div id="txt"> | |
| <h2>Tabbseparerad text</h2> | |
| <pre><?php foreach($output as $line): echo htmlspecialchars($line ."\n", ENT_NOQUOTES); endforeach; ?></pre> | |
| </div> | |
| <?php endif; ?> | |
| <?php endif; ?> | |
| <hr /> | |
| <p>Se även konverteraren för <a href="/rt90/">RT 90</a>.</p> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment