# Copyright (c) 2007-2011 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: GeomPoint.pm,v 1.5 2011/12/21 18:34:18 nagler Exp $ package Bivio::Type::GeomPoint; use strict; use Bivio::Base 'Type.Geom'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.5 $ =~ /\d+/g); my($_TE) = b_use('Bivio::TypeError'); my($_GN) = b_use('Type.GeomNumber'); my($_DD) = b_use('Type.DecimalDegree'); sub TYPE { return 'POINT'; } sub from_long_lat { my($proto, $long, $lat) = @_; return $proto->new( join(' ', map($_DD->from_literal_or_die($_), $long, $lat)), undef, $proto->SRID_WGS84, ); } sub validate_wkt { my($proto, $value) = @_; my($i) = 0; foreach my $d (split(' ', $value)) { my(undef, $e) = $_GN->from_literal($d); return $e if $e; $i++; } return $i < 2 ? $_TE->TOO_FEW : $i > 2 ? $_TE->TOO_MANY : (); } 1;