
    (&h:                     $   d Z ddlZddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ g dZ ed	dd
ddd          Z edd
dd          Z	 	 	 	 ddZ	 	 	 	 	 ddZ ed          d d            Zd!dZd!dZ ed          d!d            ZdS )"z.Input/output functions for Shapely geometries.    N)geos_versionlib)	ParamEnum)from_ragged_arrayto_ragged_array)requires_geos)UnsupportedGEOSVersionError)from_geojsonr   from_wkbfrom_wkt
to_geojsonr   to_wkbto_wktDecodingErrorOptions         )ignorewarnraisefixWKBFlavorOptions)extendediso   TFc           	         t          j        |          st          d          t          j        |          st          d          |t          dk     rdnd}n#t          j        |          st          d          t          j        |          st          d          t	          j        | t          j        |          t          j        |          t          j        |          t          j        |          fi |S )	a  Convert to the Well-Known Text (WKT) representation of a Geometry.

    The Well-known Text format is defined in the `OGC Simple Features
    Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.

    The following limitations apply to WKT serialization:

    - only simple empty geometries can be 3D, empty collections are always 2D

    Parameters
    ----------
    geometry : Geometry or array_like
        Geometry or geometries to convert to WKT.
    rounding_precision : int, default 6
        The rounding precision when writing the WKT string. Set to a value of
        -1 to indicate the full precision.
    trim : bool, default True
        If True, trim unnecessary decimals (trailing zeros).
    output_dimension : int, default None
        The output dimension for the WKT string. Supported values are 2, 3 and
        4 for GEOS 3.12+. Default None will automatically choose 3 or 4,
        depending on the version of GEOS.
        Specifying 3 means that up to 3 dimensions will be written but 2D
        geometries will still be represented as 2D in the WKT string.
    old_3d : bool, default False
        Enable old style 3D/4D WKT generation. By default, new style 3D/4D WKT
        (ie. "POINT Z (10 20 30)") is returned, but with ``old_3d=True``
        the WKT will be formatted in the style "POINT (10 20 30)".
    **kwargs
        See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.

    Examples
    --------
    >>> import shapely
    >>> from shapely import Point
    >>> shapely.to_wkt(Point(0, 0))
    'POINT (0 0)'
    >>> shapely.to_wkt(Point(0, 0), rounding_precision=3, trim=False)
    'POINT (0.000 0.000)'
    >>> shapely.to_wkt(Point(0, 0), rounding_precision=-1, trim=False)
    'POINT (0.0000000000000000 0.0000000000000000)'
    >>> shapely.to_wkt(Point(1, 2, 3), trim=True)
    'POINT Z (1 2 3)'
    >>> shapely.to_wkt(Point(1, 2, 3), trim=True, output_dimension=2)
    'POINT (1 2)'
    >>> shapely.to_wkt(Point(1, 2, 3), trim=True, old_3d=True)
    'POINT (1 2 3)'

    Notes
    -----
    The defaults differ from the default of some GEOS versions. To mimic this for
    versions before GEOS 3.12, use::

        shapely.to_wkt(geometry, rounding_precision=-1, trim=False, output_dimension=2)

    z-rounding_precision only accepts scalar valuesztrim only accepts scalar valuesNr      r   r      +output_dimension only accepts scalar valuesz!old_3d only accepts scalar values)npisscalar	TypeErrorr   r   r   intcbool_)geometryrounding_precisiontrimoutput_dimensionold_3dkwargss         E/var/www/html/reinick/venv/lib/python3.11/site-packages/shapely/io.pyr   r   "   s   @ ;)** IGHHH;t ;9::: ,z 9 911q[)** GEFFF;v =;<<<:
"##

 !!
        r   c           
         t          j        |          st          d          |t          dk     rdnd}n#t          j        |          st          d          t          j        |          st          d          t          j        |          st          d          t          j        |          st          d	          t          j        d
k     r|dk    rt          d          |dk    r|rt          d          t                              |          }t	          j	        | t          j
        |          t          j        |          t          j        |          t          j
        |          t          j        |          fi |S )a	  Convert to the Well-Known Binary (WKB) representation of a Geometry.

    The Well-Known Binary format is defined in the `OGC Simple Features
    Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.

    The following limitations apply to WKB serialization:

    - linearrings will be converted to linestrings
    - a point with only NaN coordinates is converted to an empty point

    Parameters
    ----------
    geometry : Geometry or array_like
        Geometry or geometries to convert to WKB.
    hex : bool, default False
        If true, export the WKB as a hexadecimal string. The default is to
        return a binary bytes object.
    output_dimension : int, default None
        The output dimension for the WKB. Supported values are 2, 3 and 4 for
        GEOS 3.12+. Default None will automatically choose 3 or 4, depending on
        the version of GEOS.
        Specifying 3 means that up to 3 dimensions will be written but 2D
        geometries will still be represented as 2D in the WKB representation.
    byte_order : int, default -1
        Defaults to native machine byte order (-1). Use 0 to force big endian
        and 1 for little endian.
    include_srid : bool, default False
        If True, the SRID is be included in WKB (this is an extension
        to the OGC WKB specification). Not allowed when flavor is "iso".
    flavor : {"iso", "extended"}, default "extended"
        Which flavor of WKB will be returned. The flavor determines how
        extra dimensionality is encoded with the type number, and whether
        SRID can be included in the WKB. ISO flavor is "more standard" for
        3D output, and does not support SRID embedding.
        Both flavors are equivalent when ``output_dimension=2`` (or with 2D
        geometries) and ``include_srid=False``.
        The `from_wkb` function can read both flavors.
    **kwargs
        See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.

    Examples
    --------
    >>> import shapely
    >>> from shapely import Point
    >>> point = Point(1, 1)
    >>> shapely.to_wkb(point, byte_order=1)
    b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?'
    >>> shapely.to_wkb(point, hex=True, byte_order=1)
    '0101000000000000000000F03F000000000000F03F'

    zhex only accepts scalar valuesNr   r   r   r    z%byte_order only accepts scalar valuesz'include_srid only accepts scalar valuesz!flavor only accepts scalar values)r   
   r   r   z.The "iso" option requires at least GEOS 3.10.0z:flavor="iso" and include_srid=True cannot be used together)r!   r"   r#   r   r   r	   
ValueErrorr   	get_valuer   r%   r$   )r&   hexr)   
byte_orderinclude_sridflavorr+   s          r,   r   r   w   s   x ;s :8999 ,z 9 911q[)** GEFFF;z"" A?@@@;|$$ CABBB;v =;<<<
*$$5)<
 
 	
 <UVVV''//F:

 !!



    r-   z3.10.0c                     |d}n8t          j        |          st          d          |dk     rt          d          t	          j        | t          j        |          fi |S )a  Convert to the GeoJSON representation of a Geometry.

    The GeoJSON format is defined in the `RFC 7946 <https://geojson.org/>`__.
    NaN (not-a-number) coordinates will be written as 'null'.

    The following are currently unsupported:

    - Geometries of type LINEARRING: these are output as 'null'.
    - Three-dimensional geometries: the third dimension is ignored.

    Parameters
    ----------
    geometry : str, bytes or array_like
        Geometry or geometries to convert to GeoJSON.
    indent : int, optional
        If indent is a non-negative integer, then GeoJSON will be formatted.
        An indent level of 0 will only insert newlines. None (the default)
        selects the most compact representation.
    **kwargs
        See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.

    Examples
    --------
    >>> import shapely
    >>> from shapely import Point
    >>> point = Point(1, 1)
    >>> shapely.to_geojson(point)
    '{"type":"Point","coordinates":[1.0,1.0]}'
    >>> print(shapely.to_geojson(point, indent=2))
    {
      "type": "Point",
      "coordinates": [
          1.0,
          1.0
      ]
    }

    Nr.   z!indent only accepts scalar valuesr   zindent cannot be negative)r!   r"   r#   r1   r   r   r$   )r&   indentr+   s      r,   r   r      sl    V ~[   6;<<<	!4555>(BGFOO>>v>>>r-   r   c                     t          j        |          st          d          t          j        t                              |                    }t          j        | |fi |S )a  Create geometries from the Well-Known Text (WKT) representation.

    The Well-known Text format is defined in the `OGC Simple Features
    Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.

    Parameters
    ----------
    geometry : str or array_like
        The WKT string(s) to convert.
    on_invalid : {"raise", "warn", "ignore", "fix"}, default "raise"
        Indicates what to do when an invalid WKT string is encountered. Note
        that the validations involved are very basic, e.g. the minimum number of
        points for the geometry type. For a thorough check, use
        :func:`is_valid` after conversion to geometries. Valid options are:

        - raise: an exception will be raised if any input geometry is invalid.
        - warn: a warning will be raised and invalid WKT geometries will be
          returned as ``None``.
        - ignore: invalid geometries will be returned as ``None`` without a
          warning.
        - fix: an effort is made to fix invalid input geometries (currently just
          unclosed rings). If this is not possible, they are returned as
          ``None`` without a warning. Requires GEOS >= 3.11.

          .. versionadded:: 2.1.0
    **kwargs
        See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.

    Examples
    --------
    >>> import shapely
    >>> shapely.from_wkt('POINT (0 0)')
    <POINT (0 0)>

    %on_invalid only accepts scalar values)r!   r"   r#   uint8r   r2   r   r   r&   
on_invalidr+   invalid_handlers       r,   r   r     s_    H ;z"" A?@@@h3==jIIJJO</<<V<<<r-   c                     t          j        |          st          d          t          j        t                              |                    }t          j        | t                    } t          j	        | |fi |S )a  Create geometries from the Well-Known Binary (WKB) representation.

    The Well-Known Binary format is defined in the `OGC Simple Features
    Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.

    Parameters
    ----------
    geometry : str or array_like
        The WKB byte object(s) to convert.
    on_invalid : {"raise", "warn", "ignore", "fix"}, default "raise"
        Indicates what to do when an invalid WKB is encountered. Note that the
        validations involved are very basic, e.g. the minimum number of points
        for the geometry type. For a thorough check, use :func:`is_valid` after
        conversion to geometries. Valid options are:

        - raise: an exception will be raised if any input geometry is invalid.
        - warn: a warning will be raised and invalid WKT geometries will be
          returned as ``None``.
        - ignore: invalid geometries will be returned as ``None`` without a
          warning.
        - fix: an effort is made to fix invalid input geometries (currently just
          unclosed rings). If this is not possible, they are returned as
          ``None`` without a warning. Requires GEOS >= 3.11.

          .. versionadded:: 2.1.0
    **kwargs
        See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.

    Examples
    --------
    >>> import shapely
    >>> shapely.from_wkb(b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?')
    <POINT (1 1)>

    r:   dtype)
r!   r"   r#   r;   r   r2   asarrayobjectr   r   r<   s       r,   r   r   3  su    H ;z"" A?@@@h3==jIIJJO
 z(&111H</<<V<<<r-   z3.10.1c                     t          j        |          st          d          t          j        t                              |                    }t          j        | t                    } t          j	        | |fi |S )a  Create geometries from GeoJSON representations (strings).

    If a GeoJSON is a FeatureCollection, it is read as a single geometry
    (with type GEOMETRYCOLLECTION). This may be unpacked using
    :meth:`shapely.get_parts`. Properties are not read.

    The GeoJSON format is defined in `RFC 7946 <https://geojson.org/>`__.

    The following are currently unsupported:

    - Three-dimensional geometries: the third dimension is ignored.
    - Geometries having 'null' in the coordinates.

    Parameters
    ----------
    geometry : str, bytes or array_like
        The GeoJSON string or byte object(s) to convert.
    on_invalid : {"raise", "warn", "ignore"}, default "raise"
        - raise: an exception will be raised if an input GeoJSON is invalid.
        - warn: a warning will be raised and invalid input geometries will be
          returned as ``None``.
        - ignore: invalid input geometries will be returned as ``None`` without
          a warning.
    **kwargs
        See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.

    See Also
    --------
    get_parts

    Examples
    --------
    >>> import shapely
    >>> shapely.from_geojson('{"type": "Point","coordinates": [1, 2]}')
    <POINT (1 2)>

    r:   r@   )
r!   r"   r#   r;   r   r2   rB   rC   r   r
   r<   s       r,   r
   r
   c  sv    T ;z"" A?@@@h3==jIIJJO
 z(&111HHo@@@@@r-   )r   TNF)FNr.   Fr   )N)r   )__doc__numpyr!   shapelyr   r   shapely._enumr   shapely._ragged_arrayr   r   shapely.decoratorsr   shapely.errorsr	   __all__r   r   r   r   r   r   r   r
    r-   r,   <module>rN      s   4 4     % % % % % % % % # # # # # # E D D D D D D D , , , , , , 6 6 6 6 6 6	 	 	 !yq!aJJ   9/a1J1JKK 
 	R R R Rn 	X X X Xv x1? 1? 1? 1?h)= )= )= )=X-= -= -= -=` x3A 3A 3A 3A 3A 3Ar-   