Skip to content

Instantly share code, notes, and snippets.

@jqtrde
Last active July 29, 2018 01:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jqtrde/ba32c3304bbe7d8e85b5 to your computer and use it in GitHub Desktop.
Save jqtrde/ba32c3304bbe7d8e85b5 to your computer and use it in GitHub Desktop.
A (shitty) way to transform a list of coordinates in UTM to Long/Lat, using gdaltransform.

Reprojecting a list of coordinates to a web-friendly GeoJSON file

First of all, why?

The regulatory community in Maine uses and projects it's data as UTM Zone 19. That's fine, except that it can be painful to get that data into WGS84, which seems to be far and away the preferred format for mapping applications on the web. The process I'm describing is certainly not beautiful, but so far it's the best I've come up with. If you have any suggestions, email me please!

We'll be using 2 tools to get this done. The first, gdaltransform is a part of... GDAL! Install that however is best for your OS. The second, csv2geojson is a nice way to transform csvs to, you guessed it, geojson. Install it with npm install -g csv2geojson.

  • Start with your initial dataset. It needs to be a textfile to play nicely with gdaltransform.
  • gdaltransform -s_srs EPSG:26919 -t_srs EPSG:4326 <initial.txt> converted.txt will convert a list of coordinates projected in UTM Zone 19 to long, lats in WGS84.
  • Using Vim, strip last 2 characters per line with :%s/.\{2}$//, and convert spaces to comma's with :%s/ /,.
  • Add longitude and latitude headers
  • csv2geojson converted.csv > converted.geojson will process your csv (projected in WGS 84 with appropriate headers) to a beautiful little GeoJSON which you can push to Github, load into Leaflet, or whatever else you think is fancy.

Before you tell me this would be easier in ArcMap or whatever gui solution you typically use, yes, it might be for a one off conversion. But I'd rather stay out of gui's, click less, and automate more. Keeping it cli helps me do that :)

longitude latitude
-67.5667647785632 44.9266200808726
-67.5743171887273 44.9225196819941
-67.4990497512917 44.9318714003755
-67.5030556021784 44.9347506234824
-67.5786140266091 44.9183512942229
-67.6303354677011 44.9853731325686
-67.5162499184765 44.9661867740563
-67.5100731884277 44.9701572281092
-68.069497177844 44.8405511153813
-68.1089759831664 44.947855796687
-67.5667647785632 44.9266200808726 0
-67.5743171887273 44.9225196819941 0
-67.4990497512917 44.9318714003755 0
-67.5030556021784 44.9347506234824 0
-67.5786140266091 44.9183512942229 0
-67.6303354677011 44.9853731325686 0
-67.5162499184765 44.9661867740563 0
-67.5100731884277 44.9701572281092 0
-68.069497177844 44.8405511153813 0
-68.1089759831664 44.947855796687 0
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
613105 4975798
612517 4975332
618438 4976478
618116 4976792
612186 4974863
607978 4982238
617011 4980265
617490 4980715
573541 4965659
570290 4977544
@dnomadb
Copy link

dnomadb commented Oct 4, 2017

Hmm I found a problem in your code:

in Maine

I don't think Maine actually exists, this is why your data won't line up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment