Created
May 24, 2010 14:17
-
-
Save tokumine/411915 to your computer and use it in GitHub Desktop.
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
module GeomHelper | |
def self.geojson_to_wkt geojson | |
#PARSE GEOJSON INTO NICE RING STRINGS | |
json = JSON.parse geojson | |
polys = json["coordinates"] | |
polygons = [] | |
polys.each do |poly| | |
rings = [] | |
poly.each do |ring| | |
r = ring.inject([]){|acc,x| acc << x.join(" ")}.join(",") | |
rings << "(#{r})" | |
end | |
polygons << rings | |
end | |
#WRITE OUT TO WKT | |
wkt = polygons.inject([]){|acc,x| acc << "(#{x.join(",")})"} | |
"MULTIPOLYGON(#{wkt.join(",")})" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment