Пример #1
0
 def srid(self):
     "Gets the SRID for the geometry, returns None if no SRID is set."
     s = capi.geos_get_srid(self.ptr)
     if s == 0:
         return None
     else:
         return s
Пример #2
0
 def get_srid(self):
     "Gets the SRID for the geometry, returns None if no SRID is set."
     s = capi.geos_get_srid(self.ptr)
     if s == 0:
         return None
     else:
         return s
Пример #3
0
    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.
        """
        input_srid = None
        if isinstance(geo_input, bytes):
            geo_input = force_text(geo_input)
        if isinstance(geo_input, str):
            wkt_m = wkt_regex.match(geo_input)
            if wkt_m:
                # Handling WKT input.
                if wkt_m.group('srid'):
                    input_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 json_regex.match(geo_input):
                # Handling GeoJSON input.
                g = wkb_r().read(gdal.OGRGeometry(geo_input).wkb)
            else:
                raise ValueError(
                    'String 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' %
                            type(geo_input))

        if not g:
            raise GEOSException(
                'Could not initialize GEOS Geometry with given input.')

        input_srid = input_srid or capi.geos_get_srid(g) or None
        if input_srid and srid and input_srid != srid:
            raise ValueError('Input geometry already has SRID: %d.' %
                             input_srid)

        # Setting the pointer object with a valid pointer.
        self.ptr = g
        # Post-initialization setup.
        self._post_init(input_srid or srid)
Пример #4
0
    def __init__(self, geo_input, srid=None):
        """
        The base constructor for GEOS geometry objects. It may take the
        following inputs:

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

        The `srid` keyword specifies the Source Reference Identifier (SRID)
        number for this Geometry. If not provided, it defaults to None.
        """
        input_srid = None
        if isinstance(geo_input, bytes):
            geo_input = force_text(geo_input)
        if isinstance(geo_input, str):
            wkt_m = wkt_regex.match(geo_input)
            if wkt_m:
                # Handle WKT input.
                if wkt_m.group('srid'):
                    input_srid = int(wkt_m.group('srid'))
                g = self._from_wkt(force_bytes(wkt_m.group('wkt')))
            elif hex_regex.match(geo_input):
                # Handle HEXEWKB input.
                g = wkb_r().read(force_bytes(geo_input))
            elif json_regex.match(geo_input):
                # Handle GeoJSON input.
                ogr = gdal.OGRGeometry.from_json(geo_input)
                g = ogr._geos_ptr()
                input_srid = ogr.srid
            else:
                raise ValueError('String 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:
            raise TypeError('Improper geometry input type: %s' % type(geo_input))

        if not g:
            raise GEOSException('Could not initialize GEOS Geometry with given input.')

        input_srid = input_srid or capi.geos_get_srid(g) or None
        if input_srid and srid and input_srid != srid:
            raise ValueError('Input geometry already has SRID: %d.' % input_srid)

        super().__init__(g, None)
        # Set the SRID, if given.
        srid = input_srid or srid
        if srid and isinstance(srid, int):
            self.srid = srid
Пример #5
0
=======
        Return true if the DE-9IM intersection matrix for the two Geometries
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
        is T*F**F***.
        """
        return capi.geos_within(self.ptr, other.ptr)

    # #### SRID Routines ####
    @property
    def srid(self):
<<<<<<< HEAD
        "Gets the SRID for the geometry, returns None if no SRID is set."
=======
        "Get the SRID for the geometry. Return None if no SRID is set."
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
        s = capi.geos_get_srid(self.ptr)
        if s == 0:
            return None
        else:
            return s

    @srid.setter
    def srid(self, srid):
<<<<<<< HEAD
        "Sets the SRID for the geometry."
        capi.geos_set_srid(self.ptr, 0 if srid is None else srid)

    def get_srid(self):
        warnings.warn(
            "`get_srid()` is deprecated, use the `srid` property instead.",
            RemovedInDjango20Warning, 2