# Copyright (c) 2007 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: GeomPolygon.pm,v 1.2 2007/12/13 23:36:46 nagler Exp $ package Bivio::Type::GeomPolygon; use strict; use Bivio::Base 'Type.Geom'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.2 $ =~ /\d+/g); my($_TE) = __PACKAGE__->use('Bivio::TypeError'); my($_GN) = __PACKAGE__->use('Type.GeomNumber'); my($_DD) = __PACKAGE__->use('Type.DecimalDegree'); sub TYPE { return 'POLYGON'; } sub from_shape { my($proto, $shape) = @_; my($seen) = {}; my($done); return $proto->new( '(' . join(',', map( join(' ', map($_DD->from_literal_or_die($_), $_->X, $_->Y)), $shape->points, )) . ')', undef, $proto->SRID_WGS84, ); } sub validate_wkt { my($proto, $value) = @_; return $_TE->SYNTAX_ERROR unless $value =~ /^\((.+)\)$/s; my($i) = 0; foreach my $pair (split(/\s*,\s*/, $1)) { foreach my $d (split(' ', $pair, 2)) { my(undef, $e) = $_GN->from_literal($d); return $e if $e; } $i++; } #TODO: Assumes syntax of WKT is a closed polygon. Only can # really come from the database; return $i < 3 ? $_TE->TOO_FEW : (); } 1;