Skip to content

Instantly share code, notes, and snippets.

@cbachich
Created December 31, 2014 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbachich/d50708834a63014a7b76 to your computer and use it in GitHub Desktop.
Save cbachich/d50708834a63014a7b76 to your computer and use it in GitHub Desktop.
Convert the Geometry hash from a Geojson Feature to WKT
def convert_to_wkt_string geometry
if geometry['type'] == "Polygon"
wkt_string [geometry["coordinates"]]
else
wkt_string geometry["coordinates"]
end
end
def wkt_string coordinates
"MULTIPOLYGON #{format_outer_polygons coordinates}"
end
def format_outer_polygons coordinates
"(#{coordinates.map { |outer_poly| format_inner_polygons outer_poly }.join ", "})"
end
def format_inner_polygons polys
"(#{polys.map { |poly| format_point_pairs poly}.join ", "})"
end
def format_point_pairs pairs
"(#{pairs.map { |pair| pair.join " " }.join ", "})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment