Last active
August 29, 2015 14:12
-
-
Save cbachich/2422a1f02a4ffc4dcb23 to your computer and use it in GitHub Desktop.
Converting an array to a Multipolygon String for RGeo
This file contains hidden or 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
test = [[[-70, 30],[-71, 31]],[[0,0],[-180,90],[-179,75]]]=> [[[-70, 30], [-71, 31]], [[0, 0], [-180, 90], [-179, 75]]] | |
converted = "MULTIPOLYGON ((#{test.map { |coord| "(#{coord.map { |pair| pair.join(" ") }.join ", "})" }.join ", "}))" |
This file contains hidden or 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
MULTIPOLYGON (((-70 30, -71 31), (0 0, -180 90, -179 75))) |
Yeah that is probably best. I'm still trying to figure out if there is a way to optimize this. Thanks for the feedback.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of having one line do everything (all the maps, joins, etc), use multiple lines. You could likely factor out methods at that point, which would increase readability for one thing, and make it easier to understand what's going on.
Still seems like performance is going to be an issue when you're traversing so many nested arrays, but I'm not immediately sure of a way around that.