Skip to content

Instantly share code, notes, and snippets.

@slezica
Last active August 29, 2015 14:19
Show Gist options
  • Save slezica/118c25ae4b876c7b1904 to your computer and use it in GitHub Desktop.
Save slezica/118c25ae4b876c7b1904 to your computer and use it in GitHub Desktop.
DT db serialized polygon to geoJSON
# Convert from SQL serialized format:
parsePolygon = (polygon_s) ->
for point_s in polygon_s.split('|')
point_s.split(',').map(parseFloat)
toGeoJSON = (polygon) ->
# `polygon` is an array of [lat, lng]
polygon = (point.reverse() for point in polygon)
polygon.push(polygon[0])
type : 'Polygon'
coordinates: [ polygon ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment