Created
December 31, 2014 22:15
-
-
Save cbachich/d50708834a63014a7b76 to your computer and use it in GitHub Desktop.
Convert the Geometry hash from a Geojson Feature to WKT
This file contains 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
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