Skip to content

Instantly share code, notes, and snippets.

@snuxoll
Forked from nofxx/gist:79136
Created March 14, 2009 17:53
Show Gist options
  • Save snuxoll/79137 to your computer and use it in GitHub Desktop.
Save snuxoll/79137 to your computer and use it in GitHub Desktop.
#
# Return UTM Zone for a geom
#
# Return Integer
def utm_zone
geomgeog = srid == 4326 ? self[get_column_name] : transform(4326)
puts geomgeog.class
geom = case geomgeog
when Point then geomgeog
when LineString then geomgeog.first
else
geomgeog.first.first
end
pref = geom.y > 0 ? 32700 : 32600
zone = ((geom.x + 180) / 6 + 1).to_i
zone + pref
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment