Skip to content

Instantly share code, notes, and snippets.

@nofxx
Created March 14, 2009 17:52
Show Gist options
  • Save nofxx/79136 to your computer and use it in GitHub Desktop.
Save nofxx/79136 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.class.to_s
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