{"id":539,"date":"2015-07-20T23:24:12","date_gmt":"2015-07-20T21:24:12","guid":{"rendered":"http:\/\/hannes.enjoys.it\/blog\/?p=539"},"modified":"2016-10-01T13:07:25","modified_gmt":"2016-10-01T11:07:25","slug":"converting-coordinates-with-cs2cs","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2015\/07\/converting-coordinates-with-cs2cs\/","title":{"rendered":"Converting coordinates with cs2cs"},"content":{"rendered":"<p>In the spirit of <a href=\"http:\/\/coffeecoder.net\/blog\/blog-little-things\/\">Blog Little Things<\/a> and after reading WEBKID&#8217;s <a href=\"http:\/\/blog.webkid.io\/you-might-not-need-qgis\/\">You Might Not Need QGIS<\/a> earlier, here you go:<\/p>\n<p>So you have thousands or millions of coordinates in &#8220;the wrong&#8221; or &#8220;that stupid&#8221; coordinate reference system and want to convert them to &#8220;the one you need&#8221;? Easily done with <a href=\"http:\/\/proj.osgeo.org\">proj<\/a>&#8216;s <strong>cs2cs<\/strong> tool. You feed it a list of coordinates and tell it how you want them transformed and put out.<\/p>\n<p>Let&#8217;s say you have these crazy accurate super coordinates in EPSG:4326 (WGS84) in a file called MyStupidCoordinates.txt (for example from copying columns out of Excel).<\/p>\n<blockquote><p>\n<code><br \/>\n9.92510775592794303 53.63833616755876932<br \/>\n9.89715616602172332 53.61639299685715798<br \/>\n9.91541274879985579 53.63589289755918799<br \/>\n9.91922922611725966 53.63415202989637010<br \/>\n9.92072211107566382 53.63179675033637750<br \/>\n9.89998015840083490 53.62284810375095390<br \/>\n9.90427723676020832 53.60740624866674153<br \/>\n9.95012889485460583 53.64563499608360075<br \/>\n9.89590860878436196 53.62979225409544171<br \/>\n9.92944379841924452 53.60061248161031955<br \/>\n<\/code>\n<\/p><\/blockquote>\n<p>and you want them in the much superior and wonderfully metric EPSG:25832 (ETRS89 \/ UTM zone 32N). You simply use <code>+init=sourceCRS +to +init=targetCRS<\/code>. if you have no idea what CRS your coordinates are in, enjoy 5 minutes with <a href=\"http:\/\/projfinder.com\/\">http:\/\/projfinder.com\/<\/a> and you will either know or you might want to take a walk (don&#8217;t forget to try them flipped though).<\/p>\n<pre lang=\"bash\">cs2cs +init=epsg:4326 +to +init=epsg:25832 MyStupidCoordinates.txt<\/pre>\n<p>and it will print<\/p>\n<blockquote><p>\n<code><br \/>\n561164.00 5943681.64 0.00<br \/>\n559346.79 5941216.81 0.00<br \/>\n560526.52 5943401.54 0.00<br \/>\n560781.36 5943211.12 0.00<br \/>\n560883.46 5942950.37 0.00<br \/>\n559524.51 5941937.29 0.00<br \/>\n559830.54 5940223.00 0.00<br \/>\n562807.40 5944515.43 0.00<br \/>\n559245.50 5942706.43 0.00<br \/>\n561505.49 5939488.65 0.00<br \/>\n<\/code>\n<\/p><\/blockquote>\n<p>You probably want more decimal places though, since your input coordinates were accurate down to the attodegree. For this, you can specify the output format with -f<\/p>\n<pre lang=\"bash\">cs2cs +init=epsg:4326 +to +init=epsg:25832 -f \"%.17f\" MyStupidCoordinates.txt<\/pre>\n<blockquote><p>\n<code><br \/>\n561164.00100000295788050 5943681.64279999211430550 0.00000000000000000<br \/>\n559346.79200000269338489 5941216.80899999570101500 0.00000000000000000<br \/>\n560526.52400000276975334 5943401.53899999428540468 0.00000000000000000<br \/>\n560781.36300000245682895 5943211.12199999392032623 0.00000000000000000<br \/>\n560883.46400000224821270 5942950.37499999348074198 0.00000000000000000<br \/>\n559524.51200000231619924 5941937.29399999510496855 0.00000000000000000<br \/>\n559830.54200000269338489 5940223.00299999490380287 0.00000000000000000<br \/>\n562807.39800000295508653 5944515.43399999290704727 0.00000000000000000<br \/>\n559245.50000000221189111 5942706.42899999395012856 0.00000000000000000<br \/>\n561505.48800000257324427 5939488.65499999187886715 0.00000000000000000<br \/>\n<\/code>\n<\/p><\/blockquote>\n<p>Perfect!<\/p>\n<p>You could direct these transformed coordinates into a new file called MyCoolCoordinates.txt by adding a redirection of its output:<\/p>\n<pre lang=\"bash\">cs2cs +init=epsg:4326 +to +init=epsg:25832 MyStupidCoordinates.txt > MyCoolCoordinates.txt<\/pre>\n<p>You can find out more about cs2cs by reading its manpage: <\/p>\n<pre lang=\"bash\">man cs2cs<\/pre>\n<p>PS: You can handle that Z coordinate, right?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the spirit of Blog Little Things and after reading WEBKID&#8217;s You Might Not Need QGIS earlier, here you go: So you have thousands or millions of coordinates in &#8220;the wrong&#8221; or &#8220;that stupid&#8221; coordinate reference system and want to convert them to &#8220;the one you need&#8221;? Easily done with proj&#8216;s cs2cs tool. You feed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,29,12,6],"tags":[],"class_list":["post-539","post","type-post","status-publish","format-standard","hentry","category-commandline","category-gis","category-linux","category-projections"],"_links":{"self":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":11,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":700,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions\/700"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}