source: TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/GeoTypes/_Polygon.py @ 2194

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/GeoTypes/_Polygon.py@2194
Revision 2194, 1.6 KB checked in by lawrence, 13 years ago (diff)

Adding various specs and 3rd party code of interest for the CSML
services development.

Line 
1
2################################################################################
3# Copyright (c) QinetiQ Plc 2003
4#
5# Licensed under the LGPL. For full license details see the LICENSE file.
6################################################################################
7
8"""
9Implementation of Polygon.
10"""
11import types, string
12
13from _Path import Path
14from _Point import Point, pointFromSequence
15
16class Polygon(Path):
17    """
18    Point provides an interface for a closed path in 2d space.
19
20    It is a sub class of the Path class with the enforced limitation
21    that the Path can not be set to 'open'.
22
23    It implements most of the methods of a container class and should be usable as if
24    it were a list of Points.
25
26    The Polygon class is provided in addition to the closed Path class because
27    Postgres has distinct types for these two objects.
28
29    """
30
31    def __init__(self,s=None):
32        Path.__init__(self,s)
33
34    def setOpen(self):
35        raise RuntimeError, "Path cannot be open for a polygon"
36
37    def isClosed(self):
38        return 1
39
40    def isOpen(self):
41        return 0
42       
43
44
45# factory methods
46
47def polygonFromPoints(*points):
48    """
49    Return a Polygon.
50
51    (arg *points) any number of Points that make up the Polygon.
52    """
53    poly = Polygon()
54    for point in points:
55        poly.append(point)
56       
57    return poly
58
59def polygonFromSequence(seq):
60    """
61    Return a Polygon.
62
63    (arg *seq) a sequence of the form ((x,y),...,(x,y)) that make up the Polygon,
64    where x and y are floats.
65    """
66    poly = Polygon()
67    for point in seq:
68        poly.append(pointFromSequence(point))
69       
70    return poly
71               
Note: See TracBrowser for help on using the repository browser.