Skip to content

Instantly share code, notes, and snippets.

@fredj
Created October 6, 2010 14:33
Show Gist options
  • Save fredj/613439 to your computer and use it in GitHub Desktop.
Save fredj/613439 to your computer and use it in GitHub Desktop.
-module(spatial).
-export([bounds/1]).
bounds({Atom, Coords}) when Atom == point; Atom == linestring; Atom == polygon ->
{lists:min([X || {X, _} <- Coords]),
lists:min([Y || {_, Y} <- Coords]),
lists:max([X || {X, _} <- Coords]),
lists:max([Y || {_, Y} <- Coords])};
bounds(_) ->
error.
%% c(spatial).
%% > spatial:bounds({point, [{1,2}]}).
%% {1,2,1,2}
%% > spatial:bounds({polygon, [{1,2}, {4,9}]}).
%% {1,2,4,9}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment