Beispiel #1
0
    def _get_single_internal(self, index):
        """
        Return the ring at the specified index. The first index, 0, will
        always return the exterior ring.  Indices > 0 will return the
        interior ring at the given index (e.g., poly[1] and poly[2] would
   from ctypes import byref, c_uint

from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.geometry import GEOSGeometry
from django.contrib.gis.geos.libgeos import GEOM_PTR
from django.contrib.gis.geos.linestring import LinearRing


class Polygon(GEOSGeometry):
    _minlength = 1

    def __init__(self, *args, **kwargs):
        """
        Initialize on an exterior ring and a sequence of holes (both
        instances may be either LinearRing instances, or a tuple/list
        that may be constructed into a LinearRing).

        Examples of initialization, where shell, hole1, and hole2 are
        valid LinearRing geometries:
        >>> from django.contrib.gis.geos import LinearRing, Polygon
        >>> shell = hole1 = hole2 = LinearRing()
        >>> poly = Polygon(shell, hole1, hole2)
        >>> poly = Polygon(shell, (hole1, hole2))

        >>> # Example where a tuple parameters are used:
Beispiel #2
0
 def _construct_ring(self, param, msg='Parameter must be a sequence of LinearRings or objects that can initialize to LinearRings'):
     "Helper routine for trying to construct a ring from the given parameter."
     if isinstance(param, LinearRing):
         return param
     try:
         ring = LinearRing(param)
         return ring
     except TypeError:
         raise TypeError(msg)
Beispiel #3
0
 def _construct_ring(
     self,
     param,
     msg=("Parameter must be a sequence of LinearRings or objects that can "
          "initialize to LinearRings"),
 ):
     "Try to construct a ring from the given parameter."
     if isinstance(param, LinearRing):
         return param
     try:
         ring = LinearRing(param)
         return ring
     except TypeError:
         raise TypeError(msg)
Beispiel #4
0
        if isinstance(g, GEOM_PTR):
            return capi.geom_clone(g)
        else:
            return capi.geom_clone(g.ptr)

    def _construct_ring(self, param, msg=(
            'Parameter must be a sequence of LinearRings or objects that can initialize to LinearRings')):
<<<<<<< HEAD
        "Helper routine for trying to construct a ring from the given parameter."
=======
        "Try to construct a ring from the given parameter."
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
        if isinstance(param, LinearRing):
            return param
        try:
            ring = LinearRing(param)
            return ring
        except TypeError:
            raise TypeError(msg)

    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)

    def _get_single_internal(self, index):