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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/GeoTypes/_OGGeometryCollection.py@2194
Revision 2194, 3.7 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
8import string
9
10from _OGGeometry import OGGeometry
11
12class OGGeometryCollection(OGGeometry):
13
14    """
15    OGGeometryCollection.
16
17    It implements most of the methods of a container class so that any
18    OpenGIS Collection class should be usable as if it were a list of
19    OGGeometry objects.
20    """
21   
22    def __init__(self,srid=None):
23        OGGeometry.__init__(self,srid)
24        self.emptyGeomList()
25
26    def emptyGeomList(self):
27        """
28        Reset the Collection to have no Points.
29        """
30        self._geoms = []
31
32    def getGeometries(self):
33        """
34        Return a list of all the Geometries in the Collection.
35        """
36        return self._geoms
37
38    def append(self, p):
39        self.getGeometries().append(p)
40       
41    def count(self, p):
42        return self.getGeometries().count(p)
43       
44    def index(self, p):
45        return self.getGeometries().index(p)
46       
47    def extend(self, path):
48        self.getGeometries().extend(path._geoms)
49       
50    def insert(self,pos,p):
51        self.getGeometries().insert(pos,p)
52       
53    def pop(self):
54        return self.getGeometries().pop()
55   
56    def remove(self,p):
57        self.getGeometries().remove(p)
58
59    def __len__(self):
60        return len(self.getGeometries())
61   
62    def __getitem__(self, key):
63        return self.getGeometries()[key]
64   
65    def __setitem__(self, key, value):
66        # check that value is a Geometry!
67        self.getGeometries()[key] = value
68       
69    def __delitem__(self, key):
70        del self.getGeometries()[key]
71   
72    def __iter__(self):
73
74        class __iter__:
75            def __init__(self,geoms):
76                self._geoms = geoms
77                self.pos = 0
78
79            def __iter__(self): return self
80
81            def next(self):
82                if self.pos == len(self._geoms):
83                    raise StopIteration
84               
85                geom = self._geoms[self.pos]
86                self.pos = self.pos + 1
87                return geom
88
89        return __iter__(self.getGeometries())
90       
91    def __contains__(self, p):
92        return p in self.getGeometries()
93
94    def _og_str(self):
95        s = string.join([ geom._og_str() for geom in self.getGeometries() ],',')
96
97        return 'GEOMETRYCOLLECTION (%s)' % (s,)
98       
99    def __repr__(self):
100        s = string.join([ geom.__repr__() for geom in self.getGeometries() ],',')
101           
102        return "(%s)" % (s,)
103
104    def __eq__(self,other):
105        """
106        Equality for GeometryCollections means that:
107             both Collections have the same number of geoms
108             all geoms are equal
109       
110        """
111        if (type(self) != type(other)):
112            return False
113
114        if not len(self) == len(other):
115            return False
116
117        count = 0
118        while count < len(self):
119            if self[count] != other[count]: return False
120            count = count + 1
121
122        return True
123           
124    def __ne__(self,other):
125        return not self.__eq__(other)
126
127    # Methods defined by the OpenGIS standard
128    def NumGeometries(self):
129        return len(self)
130
131    def GeometryN(self,index):
132        return self[index]
133
134def OGgeometryCollectionFromOGGeometries(*geometries):
135    """
136    Return a OGGeometryCollection.
137
138    (arg *geometries) any number of OGGeometries that make up the OGGeometryCollection.
139
140    """
141    geomcollection = OGGeometryCollection()
142    for geom in geometries:
143        geomcollection.append(geom)
144       
145    return geomcollection
Note: See TracBrowser for help on using the repository browser.