django.contrib.gis.geos.error.GEOSException

Here are the examples of the python api django.contrib.gis.geos.error.GEOSException taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

59 Examples 7

Page 1 Selected Page 2

Example 1

Project: django Source File: geometry.py
    def __setstate__(self, state):
        # Instantiating from the tuple state that was pickled.
        wkb, srid = state
        ptr = wkb_r().read(six.memoryview(wkb))
        if not ptr:
            raise GEOSException('Invalid Geometry loaded from pickled state.')
        self.ptr = ptr
        self._post_init(srid)

Example 2

Project: feedsanitizer Source File: geometry.py
    @property
    def json(self):
        """
        Returns GeoJSON representation of this Geometry if GDAL 1.5+
        is installed.
        """
        if gdal.GEOJSON:
            return self.ogr.json
        else:
            raise GEOSException('GeoJSON output only supported on GDAL 1.5+.')

Example 3

Project: splunk-webframework Source File: errcheck.py
Function: check_predicate
def check_predicate(result, func, cargs):
    "Error checking for unary/binary predicate functions."
    val = ord(result) # getting the ordinal from the character
    if val == 1: return True
    elif val == 0: return False
    else:
        raise GEOSException('Error encountered on GEOS C predicate function "%s".' % func.__name__)

Example 4

Project: django-compositepks Source File: coordseq.py
Function: ptr
    @property
    def ptr(self):
        """
        Property for controlling access to coordinate sequence pointer,
        preventing attempted access to a NULL memory location.
        """
        if self._ptr: return self._ptr
        else: raise GEOSException('NULL coordinate sequence pointer encountered.')

Example 5

Project: hue Source File: geometry.py
    @property
    def valid_reason(self):
        """
        Returns a string containing the reason for any invalidity.
        """
        if not GEOS_PREPARE:
            raise GEOSException('Upgrade GEOS to 3.1 to get validity reason.')
        return capi.geos_isvalidreason(self.ptr).decode()

Example 6

Project: splunk-webframework Source File: collections.py
Function: cascaded_union
    @property
    def cascaded_union(self):
        "Returns a cascaded union of this MultiPolygon."
        if GEOS_PREPARE:
            return GEOSGeometry(capi.geos_cascaded_union(self.ptr), self.srid)
        else:
            raise GEOSException('The cascaded union operation requires GEOS 3.1+.')

Example 7

Project: lettuce Source File: geometry.py
    @property
    def ewkb(self):
        """
        Return the EWKB representation of this Geometry as a Python buffer.
        This is an extension of the WKB specification that includes any SRID
        and Z values that are a part of this geometry.
        """
        if self.hasz:
            if not GEOS_PREPARE:
                # See: http://trac.osgeo.org/geos/ticket/216
                raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.')
            return ewkb_w3d().write(self)
        else:
            return ewkb_w().write(self)

Example 8

Project: Django--an-app-at-a-time Source File: libgeos.py
Function: geos_version_info
def geos_version_info():
    """
    Returns a dictionary containing the various version metadata parsed from
    the GEOS version string, including the version number, whether the version
    is a release candidate (and what number release candidate), and the C API
    version.
    """
    ver = geos_version().decode()
    m = version_regex.match(ver)
    if not m:
        raise GEOSException('Could not parse version info string "%s"' % ver)
    return {key: m.group(key) for key in (
        'version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor')}

Example 9

Project: theyworkforyou Source File: libgeos.py
Function: geos_version_info
def geos_version_info():
    """
    Returns a dictionary containing the various version metadata parsed from
    the GEOS version string, including the version number, whether the version
    is a release candidate (and what number release candidate), and the C API
    version.
    """
    ver = geos_version()
    m = version_regex.match(ver)
    if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
    return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version', 'major', 'minor'))

Example 10

Project: Django--an-app-at-a-time Source File: errcheck.py
def check_minus_one(result, func, cargs):
    "Error checking on routines that should not return -1."
    if result == -1:
        raise GEOSException('Error encountered in GEOS C function "%s".' % func.__name__)
    else:
        return result

Example 11

Project: django-compositepks Source File: base.py
Function: set_state
    def __setstate__(self, state):
        # Instantiating from the tuple state that was pickled.
        wkb, srid = state
        ptr = from_wkb(wkb, len(wkb))
        if not ptr: raise GEOSException('Invalid Geometry loaded from pickled state.')
        self._ptr = ptr
        self._post_init(srid)

Example 12

Project: hue Source File: geometry.py
Function: ewkb
    @property
    def ewkb(self):
        """
        Return the EWKB representation of this Geometry as a Python buffer.
        This is an extension of the WKB specification that includes any SRID
        value that are a part of this geometry.
        """
        if self.hasz and not GEOS_PREPARE:
            # See: http://trac.osgeo.org/geos/ticket/216
            raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.')
        return ewkb_w(3 if self.hasz else 2).write(self)

Example 13

Project: Django--an-app-at-a-time Source File: errcheck.py
def check_zero(result, func, cargs):
    "Error checking on routines that should not return 0."
    if result == 0:
        raise GEOSException('Error encountered in GEOS C function "%s".' % func.__name__)
    else:
        return result

Example 14

Project: django-compositepks Source File: errcheck.py
Function: check_sized_string
def check_sized_string(result, func, cargs):
    "Error checking for routines that return explicitly sized strings."
    if not result:
        raise GEOSException('Invalid string pointer returned by GEOS C function "%s"' % func.__name__)
    # A c_size_t object is passed in by reference for the second
    # argument on these routines, and its needed to determine the
    # correct size.
    s = string_at(result, last_arg_byref(cargs))
    libc.free(result)
    return s

Example 15

Project: PyClassLessons Source File: linestring.py
Function: set_list
    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.')

Example 16

Project: HealthStarter Source File: geometry.py
    @property
    def srs(self):
        "Returns the OSR SpatialReference for SRID of this Geometry."
        if not gdal.HAS_GDAL:
            raise GEOSException('GDAL required to return a SpatialReference object.')
        if self.srid:
            try:
                return gdal.SpatialReference(self.srid)
            except gdal.SRSException:
                pass
        return None

Example 17

Project: splunk-webframework Source File: geometry.py
Function: prepared
    @property
    def prepared(self):
        """
        Returns a PreparedGeometry corresponding to this geometry -- it is
        optimized for the contains, intersects, and covers operations.
        """
        if GEOS_PREPARE:
            return PreparedGeometry(self)
        else:
            raise GEOSException('GEOS 3.1+ required for prepared geometry support.')

Example 18

Project: feedsanitizer Source File: geometry.py
    def relate_pattern(self, other, pattern):
        """
        Returns true if the elements in the DE-9IM intersection matrix for the
        two Geometries match the elements in pattern.
        """
        if not isinstance(pattern, basestring) or len(pattern) > 9:
            raise GEOSException('invalid intersection matrix pattern')
        return capi.geos_relatepattern(self.ptr, other.ptr, pattern)

Example 19

Project: PyClassLessons Source File: geometry.py
Function: json
    @property
    def json(self):
        """
        Returns GeoJSON representation of this Geometry if GDAL is installed.
        """
        if gdal.HAS_GDAL:
            return self.ogr.json
        else:
            raise GEOSException('GeoJSON output only supported when GDAL is installed.')

Example 20

Project: hortonworks-sandbox Source File: geometry.py
    @property
    def srs(self):
        "Returns the OSR SpatialReference for SRID of this Geometry."
        if gdal.HAS_GDAL:
            if self.srid:
                return gdal.SpatialReference(self.srid)
            else:
                return None
        else:
            raise GEOSException('GDAL required to return a SpatialReference object.')

Example 21

Project: django-nonrel Source File: libgeos.py
Function: geos_version_info
def geos_version_info():
    """
    Returns a dictionary containing the various version metadata parsed from
    the GEOS version string, including the version number, whether the version
    is a release candidate (and what number release candidate), and the C API
    version.
    """
    ver = geos_version()
    m = version_regex.match(ver)
    if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
    return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))

Example 22

Project: django-nonrel Source File: linestring.py
    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.')

Example 23

Project: PyClassLessons Source File: geometry.py
Function: ogr
    @property
    def ogr(self):
        "Returns the OGR Geometry for this Geometry."
        if not gdal.HAS_GDAL:
            raise GEOSException('GDAL required to convert to an OGRGeometry.')
        if self.srid:
            try:
                return gdal.OGRGeometry(self.wkb, self.srid)
            except SRSException:
                pass
        return gdal.OGRGeometry(self.wkb)

Example 24

Project: hue Source File: geometry.py
Function: hexewkb
    @property
    def hexewkb(self):
        """
        Returns the EWKB of this Geometry in hexadecimal form.  This is an
        extension of the WKB specification that includes SRID value that are
        a part of this geometry.
        """
        if self.hasz and not GEOS_PREPARE:
            # See: http://trac.osgeo.org/geos/ticket/216
            raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.')
        return ewkb_w(3 if self.hasz else 2).write_hex(self)

Example 25

Project: Django--an-app-at-a-time Source File: errcheck.py
Function: check_predicate
def check_predicate(result, func, cargs):
    "Error checking for unary/binary predicate functions."
    val = ord(result)  # getting the ordinal from the character
    if val == 1:
        return True
    elif val == 0:
        return False
    else:
        raise GEOSException('Error encountered on GEOS C predicate function "%s".' % func.__name__)

Example 26

Project: django-compositepks Source File: base.py
Function: ptr
    @property
    def ptr(self):
        """
        Property for controlling access to the GEOS geometry pointer.  Using
        this raises an exception when the pointer is NULL, thus preventing
        the C library from attempting to access an invalid memory location.
        """
        if self._ptr: 
            return self._ptr
        else:
            raise GEOSException('NULL GEOS pointer encountered; was this geometry modified?')

Example 27

Project: decode-Django Source File: geometry.py
    def __setstate__(self, state):
        # Instantiating from the tuple state that was pickled.
        wkb, srid = state
        ptr = wkb_r().read(memoryview(wkb))
        if not ptr: raise GEOSException('Invalid Geometry loaded from pickled state.')
        self.ptr = ptr
        self._post_init(srid)

Example 28

Project: Django--an-app-at-a-time Source File: errcheck.py
def check_string(result, func, cargs):
    """
    Error checking for routines that return strings.

    This frees the memory allocated by GEOS at the result pointer.
    """
    if not result:
        raise GEOSException('Error encountered checking string return value in GEOS C function "%s".' % func.__name__)
    # Getting the string value at the pointer address.
    s = string_at(result)
    # Freeing the memory allocated within GEOS
    free(result)
    return s

Example 29

Project: django-compositepks Source File: base.py
Function: relate_pattern
    def relate_pattern(self, other, pattern):
        """
        Returns true if the elements in the DE-9IM intersection matrix for the
        two Geometries match the elements in pattern.
        """
        if not isinstance(pattern, str) or len(pattern) > 9:
            raise GEOSException('invalid intersection matrix pattern')
        return geos_relatepattern(self.ptr, other.ptr, pattern)

Example 30

Project: PyClassLessons Source File: libgeos.py
Function: geos_version_info
def geos_version_info():
    """
    Returns a dictionary containing the various version metadata parsed from
    the GEOS version string, including the version number, whether the version
    is a release candidate (and what number release candidate), and the C API
    version.
    """
    ver = geos_version().decode()
    m = version_regex.match(ver)
    if not m:
        raise GEOSException('Could not parse version info string "%s"' % ver)
    return dict((key, m.group(key)) for key in (
        'version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))

Example 31

Project: django-compositepks Source File: libgeos.py
Function: geos_version_info
def geos_version_info():
    """
    Returns a dictionary containing the various version metadata parsed from
    the GEOS version string, including the version number, whether the version
    is a release candidate (and what number release candidate), and the C API
    version.
    """
    ver = geos_version()
    m = version_regex.match(ver)
    if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
    return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version'))

Example 32

Project: splunk-webframework Source File: base.py
Function: get_ptr
    def _get_ptr(self):
        # Raise an exception if the pointer isn't valid don't
        # want to be passing NULL pointers to routines --
        # that's very bad.
        if self._ptr: return self._ptr
        else: raise GEOSException('NULL GEOS %s pointer encountered.' % self.__class__.__name__)

Example 33

Project: django-compositepks Source File: errcheck.py
Function: check_string
def check_string(result, func, cargs):
    "Error checking for routines that return strings."
    if not result: raise GEOSException('Error encountered checking string return value in GEOS C function "%s".' % func.__name__)
    # Getting the string value at the pointer address.
    s = string_at(result)
    # Freeing the memory allocated by the GEOS library.
    libc.free(result)
    return s

Example 34

Project: PyClassLessons Source File: geometry.py
Function: relate_pattern
    def relate_pattern(self, other, pattern):
        """
        Returns true if the elements in the DE-9IM intersection matrix for the
        two Geometries match the elements in pattern.
        """
        if not isinstance(pattern, six.string_types) or len(pattern) > 9:
            raise GEOSException('invalid intersection matrix pattern')
        return capi.geos_relatepattern(self.ptr, other.ptr, force_bytes(pattern))

Example 35

Project: HealthStarter Source File: geometry.py
    @property
    def ogr(self):
        "Returns the OGR Geometry for this Geometry."
        if not gdal.HAS_GDAL:
            raise GEOSException('GDAL required to convert to an OGRGeometry.')
        if self.srid:
            try:
                return gdal.OGRGeometry(self.wkb, self.srid)
            except gdal.SRSException:
                pass
        return gdal.OGRGeometry(self.wkb)

Example 36

Project: splunk-webframework Source File: geometry.py
Function: ewkb
    @property
    def ewkb(self):
        """
        Return the EWKB representation of this Geometry as a Python buffer.
        This is an extension of the WKB specification that includes any SRID
        value that are a part of this geometry.
        """
        if self.hasz and not GEOS_PREPARE:
            # See: http://trac.osgeo.org/geos/ticket/216
            raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.')
        return ewkb_w(self.hasz and 3 or 2).write(self)

Example 37

Project: lettuce Source File: geometry.py
    def __setstate__(self, state):
        # Instantiating from the tuple state that was pickled.
        wkb, srid = state
        ptr = wkb_r().read(buffer(wkb))
        if not ptr: raise GEOSException('Invalid Geometry loaded from pickled state.')
        self.ptr = ptr
        self._post_init(srid)

Example 38

Project: PyClassLessons Source File: point.py
Function: set_list
    def _set_list(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.')

Example 39

Project: feedsanitizer Source File: geometry.py
    @property
    def valid_reason(self):
        """
        Returns a string containing the reason for any invalidity.
        """
        if not GEOS_PREPARE:
            raise GEOSException('Upgrade GEOS to 3.1 to get validity reason.')
        return capi.geos_isvalidreason(self.ptr)

Example 40

Project: splunk-webframework Source File: geometry.py
Function: ogr
    @property
    def ogr(self):
        "Returns the OGR Geometry for this Geometry."
        if gdal.HAS_GDAL:
            if self.srid:
                return gdal.OGRGeometry(self.wkb, self.srid)
            else:
                return gdal.OGRGeometry(self.wkb)
        else:
            raise GEOSException('GDAL required to convert to an OGRGeometry.')

Example 41

Project: feedsanitizer Source File: geometry.py
    @property
    def hexewkb(self):
        """
        Returns the EWKB of this Geometry in hexadecimal form.  This is an
        extension of the WKB specification that includes SRID and Z values
        that are a part of this geometry.
        """
        if self.hasz:
            if not GEOS_PREPARE:
                # See: http://trac.osgeo.org/geos/ticket/216
                raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.')
            return ewkb_w3d().write_hex(self)
        else:
            return ewkb_w().write_hex(self)

Example 42

Project: PyClassLessons Source File: base.py
Function: get_ptr
    def _get_ptr(self):
        # Raise an exception if the pointer isn't valid don't
        # want to be passing NULL pointers to routines --
        # that's very bad.
        if self._ptr:
            return self._ptr
        else:
            raise GEOSException('NULL GEOS %s pointer encountered.' % self.__class__.__name__)

Example 43

Project: hortonworks-sandbox Source File: geometry.py
    @property
    def hexewkb(self):
        """
        Returns the EWKB of this Geometry in hexadecimal form.  This is an 
        extension of the WKB specification that includes SRID and Z values 
        that are a part of this geometry.
        """
        if self.hasz:
            if not GEOS_PREPARE:
                # See: http://trac.osgeo.org/geos/ticket/216
                raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.')               
            return ewkb_w3d().write_hex(self)
        else:
            return ewkb_w().write_hex(self)

Example 44

Project: splunk-webframework Source File: errcheck.py
Function: check_string
def check_string(result, func, cargs):
    """
    Error checking for routines that return strings.

    This frees the memory allocated by GEOS at the result pointer.
    """
    if not result: raise GEOSException('Error encountered checking string return value in GEOS C function "%s".' % func.__name__)
    # Getting the string value at the pointer address.
    s = string_at(result)
    # Freeing the memory allocated within GEOS
    free(result)
    return s

Example 45

Project: Django--an-app-at-a-time Source File: point.py
Function: set_z
    def set_z(self, value):
        "Sets the Z component of the Point."
        if self.hasz:
            self._cs.setOrdinate(2, 0, value)
        else:
            raise GEOSException('Cannot set Z on 2D Point.')

Example 46

Project: PyClassLessons Source File: geometry.py
    def __setstate__(self, state):
        # Instantiating from the tuple state that was pickled.
        wkb, srid = state
        ptr = wkb_r().read(memoryview(wkb))
        if not ptr:
            raise GEOSException('Invalid Geometry loaded from pickled state.')
        self.ptr = ptr
        self._post_init(srid)

Example 47

Project: PyClassLessons Source File: geometry.py
Function: srs
    @property
    def srs(self):
        "Returns the OSR SpatialReference for SRID of this Geometry."
        if not gdal.HAS_GDAL:
            raise GEOSException('GDAL required to return a SpatialReference object.')
        if self.srid:
            try:
                return gdal.SpatialReference(self.srid)
            except SRSException:
                pass
        return None

Example 48

Project: Django--an-app-at-a-time Source File: errcheck.py
def check_sized_string(result, func, cargs):
    """
    Error checking for routines that return explicitly sized strings.

    This frees the memory allocated by GEOS at the result pointer.
    """
    if not result:
        raise GEOSException('Invalid string pointer returned by GEOS C function "%s"' % func.__name__)
    # A c_size_t object is passed in by reference for the second
    # argument on these routines, and its needed to determine the
    # correct size.
    s = string_at(result, last_arg_byref(cargs))
    # Freeing the memory allocated within GEOS
    free(result)
    return s

Example 49

Project: decode-Django Source File: geometry.py
    @property
    def hexewkb(self):
        """
        Returns the EWKB of this Geometry in hexadecimal form.  This is an
        extension of the WKB specification that includes SRID value that are
        a part of this geometry.
        """
        if self.hasz and not GEOS_PREPARE:
            # See: http://trac.osgeo.org/geos/ticket/216
            raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.')
        return ewkb_w(self.hasz and 3 or 2).write_hex(self)

Example 50

Project: PyClassLessons Source File: geometry.py
    def __init__(self, geo_input, srid=None):
        """
        The base constructor for GEOS geometry objects, and may take the
        following inputs:

         * strings:
            - WKT
            - HEXEWKB (a PostGIS-specific canonical form)
            - GeoJSON (requires GDAL)
         * buffer:
            - WKB

        The `srid` keyword is used to specify the Source Reference Identifier
        (SRID) number for this Geometry.  If not set, the SRID will be None.
        """
        if isinstance(geo_input, bytes):
            geo_input = force_text(geo_input)
        if isinstance(geo_input, six.string_types):
            wkt_m = wkt_regex.match(geo_input)
            if wkt_m:
                # Handling WKT input.
                if wkt_m.group('srid'):
                    srid = int(wkt_m.group('srid'))
                g = wkt_r().read(force_bytes(wkt_m.group('wkt')))
            elif hex_regex.match(geo_input):
                # Handling HEXEWKB input.
                g = wkb_r().read(force_bytes(geo_input))
            elif gdal.HAS_GDAL and json_regex.match(geo_input):
                # Handling GeoJSON input.
                g = wkb_r().read(gdal.OGRGeometry(geo_input).wkb)
            else:
                raise ValueError('String or unicode input unrecognized as WKT EWKT, and HEXEWKB.')
        elif isinstance(geo_input, GEOM_PTR):
            # When the input is a pointer to a geometry (GEOM_PTR).
            g = geo_input
        elif isinstance(geo_input, memoryview):
            # When the input is a buffer (WKB).
            g = wkb_r().read(geo_input)
        elif isinstance(geo_input, GEOSGeometry):
            g = capi.geom_clone(geo_input.ptr)
        else:
            # Invalid geometry type.
            raise TypeError('Improper geometry input type: %s' % str(type(geo_input)))

        if g:
            # Setting the pointer object with a valid pointer.
            self.ptr = g
        else:
            raise GEOSException('Could not initialize GEOS Geometry with given input.')

        # Post-initialization setup.
        self._post_init(srid)
See More Examples - Go to Next Page
Page 1 Selected Page 2