コード例 #1
0
ファイル: collections.py プロジェクト: AloneRoad/Inforlearn
    def __init__(self, *args, **kwargs):
        "Initializes a Geometry Collection from a sequence of Geometry objects."

        # Checking the arguments
        if not args:
            raise TypeError, 'Must provide at least one Geometry to initialize %s.' % self.__class__.__name__

        if len(args) == 1: 
            # If only one geometry provided or a list of geometries is provided
            #  in the first argument.
            if isinstance(args[0], (TupleType, ListType)):
                init_geoms = args[0]
            else:
                init_geoms = args
        else:
            init_geoms = args

        # Ensuring that only the permitted geometries are allowed in this collection
        if False in [isinstance(geom, self._allowed) for geom in init_geoms]:
            raise TypeError('Invalid Geometry type encountered in the arguments.')

        # Creating the geometry pointer array.
        ngeoms = len(init_geoms)
        geoms = get_pointer_arr(ngeoms)
        for i in xrange(ngeoms): geoms[i] = geom_clone(init_geoms[i].ptr)
        super(GeometryCollection, self).__init__(create_collection(c_int(self._typeid), byref(geoms), c_uint(ngeoms)), **kwargs)
コード例 #2
0
    def __init__(self, *args, **kwargs):
        "Initializes a Geometry Collection from a sequence of Geometry objects."

        # Checking the arguments
        if not args:
            raise TypeError, 'Must provide at least one Geometry to initialize %s.' % self.__class__.__name__

        if len(args) == 1:
            # If only one geometry provided or a list of geometries is provided
            #  in the first argument.
            if isinstance(args[0], (TupleType, ListType)):
                init_geoms = args[0]
            else:
                init_geoms = args
        else:
            init_geoms = args

        # Ensuring that only the permitted geometries are allowed in this collection
        if False in [isinstance(geom, self._allowed) for geom in init_geoms]:
            raise TypeError(
                'Invalid Geometry type encountered in the arguments.')

        # Creating the geometry pointer array.
        ngeoms = len(init_geoms)
        geoms = get_pointer_arr(ngeoms)
        for i in xrange(ngeoms):
            geoms[i] = geom_clone(init_geoms[i].ptr)
        super(GeometryCollection, self).__init__(
            create_collection(c_int(self._typeid), byref(geoms),
                              c_uint(ngeoms)), **kwargs)
コード例 #3
0
ファイル: collections.py プロジェクト: Chrescht/django
 def _create_collection(self, length, items):
     # Creating the geometry pointer array.
     geoms = (GEOM_PTR * length)(*[
         # this is a little sloppy, but makes life easier
         # allow GEOSGeometry types (python wrappers) or pointer types
         capi.geom_clone(getattr(g, 'ptr', g)) for g in items
     ])
     return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length))
コード例 #4
0
 def _create_collection(self, length, items):
     # Creating the geometry pointer array.
     geoms = (GEOM_PTR * length)(*[
         # this is a little sloppy, but makes life easier
         # allow GEOSGeometry types (python wrappers) or pointer types
         capi.geom_clone(getattr(g, 'ptr', g)) for g in items
     ])
     return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length))
コード例 #5
0
    def _create_collection(self, length, items):
        # Creating the geometry pointer array.
        geoms = get_pointer_arr(length)
        for i, g in enumerate(items):
            # this is a little sloppy, but makes life easier
            # allow GEOSGeometry types (python wrappers) or pointer types
            geoms[i] = capi.geom_clone(getattr(g, 'ptr', g))

        return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length))
コード例 #6
0
    def _create_collection(self, length, items):
        # Creating the geometry pointer array.
        geoms = get_pointer_arr(length)
        for i, g in enumerate(items):
            # this is a little sloppy, but makes life easier
            # allow GEOSGeometry types (python wrappers) or pointer types
            geoms[i] = capi.geom_clone(getattr(g, 'ptr', g))

        return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length))
コード例 #7
0
ファイル: collections.py プロジェクト: AloneRoad/Inforlearn
 def __setitem__(self, index, geom):
     "Sets the Geometry at the specified index."
     self._checkindex(index)
     if not isinstance(geom, self._allowed):
         raise TypeError('Incompatible Geometry for collection.')
     
     ngeoms = len(self)
     geoms = get_pointer_arr(ngeoms)
     for i in xrange(ngeoms):
         if i == index:
             geoms[i] = geom_clone(geom.ptr)
         else:
             geoms[i] = geom_clone(get_geomn(self.ptr, i))
     
     # Creating a new collection, and destroying the contents of the previous poiner.
     prev_ptr = self.ptr
     srid = self.srid
     self._ptr = create_collection(c_int(self._typeid), byref(geoms), c_uint(ngeoms))
     if srid: self.srid = srid
     destroy_geom(prev_ptr)
コード例 #8
0
    def __setitem__(self, index, geom):
        "Sets the Geometry at the specified index."
        self._checkindex(index)
        if not isinstance(geom, self._allowed):
            raise TypeError('Incompatible Geometry for collection.')

        ngeoms = len(self)
        geoms = get_pointer_arr(ngeoms)
        for i in xrange(ngeoms):
            if i == index:
                geoms[i] = geom_clone(geom.ptr)
            else:
                geoms[i] = geom_clone(get_geomn(self.ptr, i))

        # Creating a new collection, and destroying the contents of the previous poiner.
        prev_ptr = self.ptr
        srid = self.srid
        self._ptr = create_collection(c_int(self._typeid), byref(geoms),
                                      c_uint(ngeoms))
        if srid: self.srid = srid
        destroy_geom(prev_ptr)
コード例 #9
0
        # Creating the geometry pointer array.
<<<<<<< HEAD
        geoms = get_pointer_arr(length)
        for i, g in enumerate(items):
            # this is a little sloppy, but makes life easier
            # allow GEOSGeometry types (python wrappers) or pointer types
            geoms[i] = capi.geom_clone(getattr(g, 'ptr', g))

=======
        geoms = (GEOM_PTR * length)(*[
            # this is a little sloppy, but makes life easier
            # allow GEOSGeometry types (python wrappers) or pointer types
            capi.geom_clone(getattr(g, 'ptr', g)) for g in items
        ])
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
        return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length))

    def _get_single_internal(self, index):
        return capi.get_geomn(self.ptr, index)

    def _get_single_external(self, index):
<<<<<<< HEAD
        "Returns the Geometry from this Collection at the given index (0-based)."
=======
        "Return the Geometry from this Collection at the given index (0-based)."
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
        # Checking the index and returning the corresponding GEOS geometry.
        return GEOSGeometry(capi.geom_clone(self._get_single_internal(index)), srid=self.srid)

    def _set_list(self, length, items):
        "Create a new collection, and destroy the contents of the previous pointer."
コード例 #10
0
"""