예제 #1
0
 def _set_list(self, length, items):
     "Create a new collection, and destroy the contents of the previous pointer."
     prev_ptr = self.ptr
     srid = self.srid
     self.ptr = self._create_collection(length, items)
     if srid: self.srid = srid
     capi.destroy_geom(prev_ptr)
예제 #2
0
 def transform(self, ct, clone=False):
     """
     Requires GDAL. Transforms the geometry according to the given
     transformation object, which may be an integer SRID, and WKT or
     PROJ.4 string. By default, the geometry is transformed in-place and
     nothing is returned. However if the `clone` keyword is set, then this
     geometry will not be modified and a transformed clone will be returned
     instead.
     """
     srid = self.srid
     if gdal.HAS_GDAL and srid:
         # Creating an OGR Geometry, which is then transformed.
         g = gdal.OGRGeometry(self.wkb, srid)
         g.transform(ct)
         # Getting a new GEOS pointer
         ptr = wkb_r().read(g.wkb)
         if clone:
             # User wants a cloned transformed geometry returned.
             return GEOSGeometry(ptr, srid=g.srid)
         if ptr:
             # Reassigning pointer, and performing post-initialization setup
             # again due to the reassignment.
             capi.destroy_geom(self.ptr)
             self.ptr = ptr
             self._post_init(g.srid)
         else:
             raise GEOSException('Transformed WKB was invalid.')
예제 #3
0
 def __del__(self):
     """
     Destroys this Geometry; in other words, frees the memory used by the
     GEOS C++ object.
     """
     if self._ptr and capi:
         capi.destroy_geom(self._ptr)
예제 #4
0
파일: polygon.py 프로젝트: 15580056814/hue
 def _set_list(self, length, items):
     # Getting the current pointer, replacing with the newly constructed
     # geometry, and destroying the old geometry.
     prev_ptr = self.ptr
     srid = self.srid
     self.ptr = self._create_polygon(length, items)
     if srid: self.srid = srid
     capi.destroy_geom(prev_ptr)
예제 #5
0
 def _set_collection(self, length, items):
     ptr = self._create_point(length, items)
     if ptr:
         capi.destroy_geom(self.ptr)
         self._ptr = ptr
         self._set_cs()
     else:
         # can this happen?
         raise GEOSException('Geometry resulting from slice deletion was invalid.')
예제 #6
0
파일: geometry.py 프로젝트: AMontagu/django
 def __del__(self):
     """
     Destroys this Geometry; in other words, frees the memory used by the
     GEOS C++ object.
     """
     try:
         capi.destroy_geom(self._ptr)
     except (AttributeError, TypeError):
         pass  # Some part might already have been garbage collected
예제 #7
0
 def __del__(self):
     """
     Destroys this Geometry; in other words, frees the memory used by the
     GEOS C++ object.
     """
     try:
         capi.destroy_geom(self._ptr)
     except (AttributeError, TypeError):
         pass  # Some part might already have been garbage collected
예제 #8
0
 def _set_list(self, length, items):
     # Getting the current pointer, replacing with the newly constructed
     # geometry, and destroying the old geometry.
     prev_ptr = self.ptr
     srid = self.srid
     self.ptr = self._create_polygon(length, items)
     if srid:
         self.srid = srid
     capi.destroy_geom(prev_ptr)
예제 #9
0
 def _set_list(self, length, items):
     ptr = self._create_point(length, items)
     if ptr:
         capi.destroy_geom(self.ptr)
         self._ptr = ptr
         self._post_init()
     else:
         # can this happen?
         raise GEOSException('Geometry resulting from slice deletion was invalid.')
예제 #10
0
    def _set_list(self, length, items):
        ndim = self._cs.dims
        hasz = self._cs.hasz  # I don't understand why these are different

        # create a new coordinate sequence and populate accordingly
        cs = GEOSCoordSeq(capi.create_cs(length, ndim), z=hasz)
        for i, c in enumerate(items):
            cs[i] = c

        ptr = self._init_func(cs.ptr)
        if ptr:
            capi.destroy_geom(self.ptr)
            self.ptr = ptr
예제 #11
0
    def _set_list(self, length, items):
        ndim = self._cs.dims
        hasz = self._cs.hasz  # I don't understand why these are different

        # create a new coordinate sequence and populate accordingly
        cs = GEOSCoordSeq(capi.create_cs(length, ndim), z=hasz)
        for i, c in enumerate(items):
            cs[i] = c

        ptr = self._init_func(cs.ptr)
        if ptr:
            capi.destroy_geom(self.ptr)
            self.ptr = ptr
            self._post_init(self.srid)
        else:
            # can this happen?
            raise GEOSException('Geometry resulting from slice deletion was invalid.')
예제 #12
0
    def transform(self, ct, clone=False):
        """
        Requires GDAL. Transforms the geometry according to the given
        transformation object, which may be an integer SRID, and WKT or
        PROJ.4 string. By default, the geometry is transformed in-place and
        nothing is returned. However if the `clone` keyword is set, then this
        geometry will not be modified and a transformed clone will be returned
        instead.
        """
        srid = self.srid

        if ct == srid:
            # short-circuit where source & dest SRIDs match
            if clone:
                return self.clone()
            else:
                return

        if not gdal.HAS_GDAL:
            raise GEOSException(
                "GDAL library is not available to transform() geometry.")

        if isinstance(ct, gdal.CoordTransform):
            # We don't care about SRID because CoordTransform presupposes
            # source SRS.
            srid = None
        elif srid is None or srid < 0:
            raise GEOSException(
                "Calling transform() with no SRID set is not supported")

        # Creating an OGR Geometry, which is then transformed.
        g = gdal.OGRGeometry(self.wkb, srid)
        g.transform(ct)
        # Getting a new GEOS pointer
        ptr = wkb_r().read(g.wkb)
        if clone:
            # User wants a cloned transformed geometry returned.
            return GEOSGeometry(ptr, srid=g.srid)
        if ptr:
            # Reassigning pointer, and performing post-initialization setup
            # again due to the reassignment.
            capi.destroy_geom(self.ptr)
            self.ptr = ptr
            self._post_init(g.srid)
        else:
            raise GEOSException('Transformed WKB was invalid.')
예제 #13
0
    def transform(self, ct, clone=False):
        """
        Requires GDAL. Transforms the geometry according to the given
        transformation object, which may be an integer SRID, and WKT or
        PROJ.4 string. By default, the geometry is transformed in-place and
        nothing is returned. However if the `clone` keyword is set, then this
        geometry will not be modified and a transformed clone will be returned
        instead.
        """
        srid = self.srid

        if ct == srid:
            # short-circuit where source & dest SRIDs match
            if clone:
                return self.clone()
            else:
                return

        if not gdal.HAS_GDAL:
            raise GEOSException("GDAL library is not available to transform() geometry.")

        if isinstance(ct, gdal.CoordTransform):
            # We don't care about SRID because CoordTransform presupposes
            # source SRS.
            srid = None
        elif srid is None or srid < 0:
            raise GEOSException("Calling transform() with no SRID set is not supported")

        # Creating an OGR Geometry, which is then transformed.
        g = gdal.OGRGeometry(self.wkb, srid)
        g.transform(ct)
        # Getting a new GEOS pointer
        ptr = wkb_r().read(g.wkb)
        if clone:
            # User wants a cloned transformed geometry returned.
            return GEOSGeometry(ptr, srid=g.srid)
        if ptr:
            # Reassigning pointer, and performing post-initialization setup
            # again due to the reassignment.
            capi.destroy_geom(self.ptr)
            self.ptr = ptr
            self._post_init(g.srid)
        else:
            raise GEOSException('Transformed WKB was invalid.')
예제 #14
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)
예제 #15
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)
예제 #16
0
from django.contrib.gis.geos import prototypes as capi
예제 #17
0
from ctypes import c_uint
예제 #18
0
 def __del__(self):
     """
     Destroys this Geometry; in other words, frees the memory used by the
     GEOS C++ object.
     """
     if self._ptr: capi.destroy_geom(self._ptr)
예제 #19
0
"""
예제 #20
0
from ctypes import byref, c_uint