
    iDL              	          d dl Z d dlZd dlZd dlZd dlmZ dZd Zd Zd$dZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZeeeeeeedZeeeeeeedZ edddd d!d"d#          ZdS )%    N)utilzInvalid WKT: `%s`c                 J    |                     t          |                      dS )a  
    Dump GeoJSON-like `dict` to WKT and write it to the `dest_file`.

    :param dict obj:
        A GeoJSON-like dictionary. It must at least the keys 'type' and
        'coordinates'.
    :param dest_file:
        Open and writable file-like object.
    N)writedumps)obj	dest_files     \/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/geomet/wkt.pydumpr
      s"     OOE#JJ    c                 D    t          |                                           S )z
    Load a GeoJSON `dict` object from a ``source_file`` containing WKT.

    :param source_file:
        Open and readable file-like object.

    :returns:
        A GeoJSON `dict` representing the geometry read from the file.
    )loadsread)source_files    r	   loadr   &   s     !!##$$$r      c                 >   	 | d         }t                               |          }|t          |           |dk    rt          | d                   dk    rdS nOt          t	          t          j        | d                                       dk    rd|                                z  S n%# t          $ r t          j
        d	| z            w xY w || |          }|                     d
i                               d          }|                     di                               di                               d          }||                    dd          }|7|5t          |          t          |          k    rt          d|d|          |p|}|d|d|}|S )z5
    Dump a GeoJSON-like `dict` to a WKT string.
    typeNGeometryCollection
geometriesr   zGEOMETRYCOLLECTION EMPTYcoordinatesz%s EMPTYzInvalid GeoJSON: %smetasridcrs
propertiesnameEPSG zAmbiguous CRS/SRID values: z and zSRID=;)_dumps_registryget_unsupported_geom_typelenlistr   flatten_multi_dimupperKeyErrorgeometInvalidGeoJSONExceptionreplacestr
ValueError)r   decimals	geom_typeexporterresult	meta_sridcrs_sridr   s           r	   r   r   3   s   JK	"&&y11"9--- ,,,3|$%%**11 + 4.s=/ABBCCDDII!IOO$5$555 J J J,-BS-HIIIJ Xc8$$F##''//Iwwub!!%%lB77;;FCCH##FB// 	NNc(mm++j6?iiJ
 
 	
  D !%vv.Ms   AB' AB' '"C	c                 \    t          |           }||k    st          d|d|d          d S )Nz
Expected "z" but found "")nextr+   )sequenceexpected
next_tokens      r	   _assert_next_tokenr8   a   sD    hJ!!j.6hh


C
 
 	
 "!r   c                 F   t          |           }t          |          }d}|}|dk    rLt          |d           t          t          |                    }t          |d           t          |          }n|}t                              |          }|t          |           t          |          }|dk    r3|dk    rt          dg           S t          t          |         g 	          S t          j
        |g|          } |||           }|t          |
          |d<   |S )z9
    Construct a GeoJSON `dict` from WKT (`string`).
    NSRID=r   EMPTYGEOMETRYCOLLECTIONr   r   r   r   r   )r   r   )_tokenize_wktr4   r8   int_loads_registryr    r!   dict_type_map_caps_to_mixed	itertoolschain)stringtokensgeom_type_or_sridr   r-   importerpeekr/   s           r	   r   r   i   s6    6""FVD!IF""63'''4<<  63'''LL		%	""9--Hy)))<<Dw,,,1bAAAA4Y?$&( ( ( ( _dVV,,FXff%%F4vMr   c              #      K   t          j        |           }d t          j        |j                  D             }d}|D ]"}|dk    rd}|dk    r|rd|z  V  n|V  d}#dS )z
    Since the tokenizer treats "-" and numeric strings as separate values,
    combine them and yield them as a single token. This utility encapsulates
    parsing of negative numeric values from WKT can be used generically in all
    parsers.
    c              3   &   K   | ]}|d          V  dS )   N ).0xs     r	   	<genexpr>z _tokenize_wkt.<locals>.<genexpr>   s&      CCqadCCCCCCr   F-Tr   z-%sN)ioStringIOtokenizegenerate_tokensreadline)rG   siorH   negativets        r	   r@   r@      s       +f

CCCH4S\BBCCCFH  88H"WW  aiHH r   c                 &    t          d| z            )NzUnsupported geometry type '%s')r+   )r-   s    r	   r!   r!      s    
5	A
B
BBr   c                    t          | t                    r|dk    rt          |           } n0|dk    r*t          t          t	          | |                              S t	          | |          }dt          |          v r$t          |d                    |                    }nt          |          }|d|t          |                    d          d                   z
  z  z  }|S )a;  
    Round the input value to `decimals` places, and pad with 0's
    if the resulting value is less than `decimals`.

    :param value:
        The value to round
    :param decimals:
        Number of decimals places which should be displayed after the rounding.
    :return:
        str of the rounded value
    r   ez.{}f0.rN   )
isinstancerA   floatreprroundformatr"   split)valuer,   roundeds      r	   _round_and_padri      s     % 1(a-- e	QCeX..//000E8$$G
d7mm&--"9"9::w--shW]]3%7%7%:!;!;;<<GNr   c                 p    | d         }|sd}n$dd                     fd|D                       z  }d|z  S )a\  
    Dump a GeoJSON-like Point object to WKT.

    :param dict obj:
        A GeoJSON-like `dict` representing a Point.
    :param int decimals:
        int which indicates the number of digits to display after the
        decimal point when formatting coordinates.

    :returns:
        WKT representation of the input GeoJSON Point ``obj``.
    r   r<   (%s) c              3   8   K   | ]}t          |          V  d S Nri   rP   cr,   s     r	   rR   z_dump_point.<locals>.<genexpr>   s-      AAQ^Ax00AAAAAAr   zPOINT %sjoinr   r,   coordsfmts    `  r	   _dump_pointrw      sY     F 
HHAAAA&AAAAA
 r   c                 p    | d         }|sd}n$dd                     fd|D                       z  }d|z  S )z
    Dump a GeoJSON-like LineString object to WKT.

    Input parameters and return value are the LINESTRING equivalent to
    :func:`_dump_point`.
    r   r<   rk   , c              3   Z   K   | ]%}d                      fd|D                       V  &dS )rl   c              3   8   K   | ]}t          |          V  d S rn   ro   rp   s     r	   rR   z-_dump_linestring.<locals>.<genexpr>.<genexpr>   s-      AA844AAAAAAr   Nrr   rP   ptr,   s     r	   rR   z#_dump_linestring.<locals>.<genexpr>   sX         AAAAbAAAAA     r   zLINESTRING %srr   rt   s    `  r	   _dump_linestringr~      sl     F 
II         
 S  r   c                     | d         }|sd}n0fd|D             }dd                     d |D                       z  }d|z  S )z
    Dump a GeoJSON-like Polygon object to WKT.

    Input parameters and return value are the POLYGON equivalent to
    :func:`_dump_point`.
    r   r<   c              3   Z   K   | ]%}d                      fd|D                       V  &dS )ry   c              3   Z   K   | ]%}d                      fd|D                       V  &dS )rl   c              3   8   K   | ]}t          |          V  d S rn   ro   rp   s     r	   rR   z4_dump_polygon.<locals>.<genexpr>.<genexpr>.<genexpr>
  sA       $1 $1() %31h$?$? $1 $1 $1 $1 $1 $1r   Nrr   r|   s     r	   rR   z*_dump_polygon.<locals>.<genexpr>.<genexpr>
  ss       A A57 88 $1 $1 $1 $1-/$1 $1 $1 1 1 A A A A A Ar   Nrr   rP   ringr,   s     r	   rR   z _dump_polygon.<locals>.<genexpr>
  st       % %  A A A A;?A A A A A % % % % % %r   rk   ry   c              3       K   | ]	}d |z  V  
dS rk   NrO   )rP   rs     r	   rR   z _dump_polygon.<locals>.<genexpr>  s&       ; ;! ; ; ; ; ; ;r   z
POLYGON %srr   )r   r,   ru   rv   ringss    `   r	   _dump_polygonr      sx     F <% % % %#% % % tyy ; ;U ; ; ;;;;#r   c                     | d         }|sd}n0fd|D             }dd                     d |D                       z  }d|z  S )z
    Dump a GeoJSON-like MultiPoint object to WKT.

    Input parameters and return value are the MULTIPOINT equivalent to
    :func:`_dump_point`.
    r   r<   c              3   Z   K   | ]%}d                      fd|D                       V  &dS )rl   c              3   8   K   | ]}t          |          V  d S rn   ro   rp   s     r	   rR   z-_dump_multipoint.<locals>.<genexpr>.<genexpr>  sA       ( (  *!X66 ( ( ( ( ( (r   Nrr   r|   s     r	   rR   z#_dump_multipoint.<locals>.<genexpr>  sk       : :,. (( ( ( ( ($&( ( ( ( ( : : : : : :r   rk   ry   c              3       K   | ]	}d |z  V  
dS r   rO   )rP   r}   s     r	   rR   z#_dump_multipoint.<locals>.<genexpr>"  s&       > >" > > > > > >r   zMULTIPOINT %srr   )r   r,   ru   rv   pointss    `   r	   _dump_multipointr     sx     F ?: : : :28: : : tyy > >v > > >>>>S  r   c                     | d         }|sd}n0fd|D             }dd                     d |D                       z  }d|z  S )z
    Dump a GeoJSON-like MultiLineString object to WKT.

    Input parameters and return value are the MULTILINESTRING equivalent to
    :func:`_dump_point`.
    r   r<   c              3   `   K   | ](}d d                     fd|D                       z  V  )dS )rk   ry   c              3   Z   K   | ]%}d                      fd|D                       V  &dS )rl   c              3   8   K   | ]}t          |          V  d S rn   ro   rp   s     r	   rR   z<_dump_multilinestring.<locals>.<genexpr>.<genexpr>.<genexpr>6  sI         '( # " "     r   Nrr   r|   s     r	   rR   z2_dump_multilinestring.<locals>.<genexpr>.<genexpr>5  so       % %
 	      ,.    % % % % % %r   Nrr   )rP   linestrr,   s     r	   rR   z(_dump_multilinestring.<locals>.<genexpr>3  sw       < < *1 II % % % %
 $% % % % %%< < < < < <r   rk   ry   c              3      K   | ]}|V  d S rn   rO   )rP   lss     r	   rR   z(_dump_multilinestring.<locals>.<genexpr><  s"       7 7 7 7 7 7 7 7r   zMULTILINESTRING %srr   )r   r,   ru   rv   linestrss    `   r	   _dump_multilinestringr   '  sz     F 8< < < < 5;< < < tyy 7 7h 7 7 7777#%%r   c                 p    | d         }|sd}n$dd                     fd|D                       z  }d|z  S )z
    Dump a GeoJSON-like MultiPolygon object to WKT.

    Input parameters and return value are the MULTIPOLYGON equivalent to
    :func:`_dump_point`.
    r   r<   rk   ry   c              3   `   K   | ](}d d                     fd|D                       z  V  )dS )rk   ry   c              3   `   K   | ](}d d                     fd|D                       z  V  )dS )rk   ry   c              3   Z   K   | ]%}d                      fd|D                       V  &dS )rl   c              3   8   K   | ]}t          |          V  d S rn   ro   rp   s     r	   rR   zC_dump_multipolygon.<locals>.<genexpr>.<genexpr>.<genexpr>.<genexpr>V  s-       I I8!<!< I I I I I Ir   Nrr   r|   s     r	   rR   z9_dump_multipolygon.<locals>.<genexpr>.<genexpr>.<genexpr>T  sZ       '( '(   I I I Ib I I III'( '( '( '( '( '(r   Nrr   r   s     r	   rR   z/_dump_multipolygon.<locals>.<genexpr>.<genexpr>Q  sv       #& #& 	 TYY '( '( '( '( #''( '( '( ( ( (#& #& #& #& #& #&r   Nrr   )rP   polyr,   s     r	   rR   z%_dump_multipolygon.<locals>.<genexpr>N  sv       $ $   #& #& #& #& !%#& #& #& & & &$ $ $ $ $ $r   zMULTIPOLYGON %srr   rt   s    `  r	   _dump_multipolygonr   A  sn     F 
II $ $ $ $ #$ $ $ $ $
  s""r   c                     | d         }|sd}n]g }|D ]@}|d         }|                     t                              |          ||                     Add                    |          z  }d|z  S )a  
    Dump a GeoJSON-like GeometryCollection object to WKT.

    Input parameters and return value are the GEOMETRYCOLLECTION equivalent to
    :func:`_dump_point`.

    The WKT conversions for each geometry in the collection are delegated to
    their respective functions.
    r   r<   r   rk   ,zGEOMETRYCOLLECTION %s)appendr   r    rs   )r   r,   geomsrv   	geoms_wktgeomr-   s          r	   _dump_geometrycollectionr   _  s     E +	 	M 	MDVI_00;;D(KKLLLLsxx	***"S((r   c                 d   t          |           }|dk    rt          dg           S |dk    st          t          |z            g }	 | D ],}|dk    r n#|                    t          |                     -n*# t          j        $ r t          t          |z            w xY wt          d|          S )a  
    :param tokens:
        A generator of string tokens for the input WKT, beginning just after
        the geometry type. The geometry type is consumed before we get to
        here. For example, if :func:`loads` is called with the input
        'POINT(0.0 1.0)', ``tokens`` would generate the following values:

        .. code-block:: python
            ['(', '0.0', '1.0', ')']
    :param str string:
        The original WKT string.

    :returns:
        A GeoJSON `dict` Point representation of the WKT ``string``.
    r<   Pointr?   ()r4   rC   r+   INVALID_WKT_FMTr   rb   rV   
TokenError)rH   rG   r7   ru   r[   s        r	   _load_pointr   u  s      fJWb1111361222F3 	( 	(ACxxeAhh'''' 3 3 3612223 W&1111s   /A7 7'Bc                    t          |           }|dk    rt          dg           S |dk    st          t          |z            g }	 g }| D ]_}|dk    r|                    |            nA|dk    r|                    |           g }=|                    t          |                     `n*# t          j        $ r t          t          |z            w xY wt          d|          S )z
    Has similar inputs and return value to to :func:`_load_point`, except is
    for handling LINESTRING geometry.

    :returns:
        A GeoJSON `dict` LineString representation of the WKT ``string``.
    r<   
LineStringr?   r   r   r   r   )rH   rG   r7   ru   r}   r[   s         r	   _load_linestringr     s    fJW26666361222 F3 		$ 		$ACxxb!!!cb!!!		%((#### 3 3 3612223 \v6666s   A$B, ,'Cc                 l   t          |           }|dk    rt          dg           S t          |           |f}|dk    st          t          |z            g }g }d}	 g }| D ]}|dk    r/|r-|                    |           |                    |           d}7|dk    r|s nY|dk    rg }g }d}N|d	k    r|r|                    |           g }n|d	k    r|sw|                    t          |                     n*# t          j        $ r t          t          |z            w xY wt          d|          S )
z
    Has similar inputs and return value to to :func:`_load_point`, except is
    for handling POLYGON geometry.

    :returns:
        A GeoJSON `dict` Polygon representation of the WKT ``string``.
    r<   Polygonr?   )r   r   Tr   Fr   r   r   )	rH   rG   r7   open_parensru   r   on_ringr}   r[   s	            r	   _load_polygonr     s}    fJW3333v,,
*K*$$61222
 FDG3 	$ 	$ACxxGxBd###c'ccgBc' 		%((#### 3 3 3612223 YF3333s   BC; ;'D"c                 (   t          |           }|dk    rt          dg           S |dk    st          t          |z            g }g }d}	 | D ]b}|dk    r|dz  }|dk    r|dz  }|dk    r nB"|dk    r|                    |           g }@|                    t          |                     cn*# t          j        $ r t          t          |z            w xY wt          |          dk    r|                    |           t          d|          S )	z
    Has similar inputs and return value to to :func:`_load_point`, except is
    for handling MULTIPOINT geometry.

    :returns:
        A GeoJSON `dict` MultiPoint representation of the WKT ``string``.
    r<   
MultiPointr?   r   rN   r   r   r   )	r4   rC   r+   r   r   rb   rV   r   r"   )rH   rG   r7   ru   r}   paren_depthr[   s          r	   _load_multipointr     sP    fJW26666361222F	BK3 	$ 	$ACxxq cq !##E $cb!!!		%((#### 3 3 3612223
 2ww{{b\v6666s   A%B1 1'Cc                    t          |           }|dk    rt          dg           S |dk    st          t          |z            g }	 	 t	          | |          }|                    |d                    t          |           }|dk    rn3n1# t          t          j        f$ r t          t          |z            w xY wut          d|          S )z
    Has similar inputs and return value to to :func:`_load_point`, except is
    for handling MULTIPOLYGON geometry.

    :returns:
        A GeoJSON `dict` MultiPolygon representation of the WKT ``string``.
    r<   MultiPolygonr?   r   Tr   r   )	r4   rC   r+   r   r   r   StopIterationrV   r   )rH   rG   r7   polygonsr   r[   s         r	   _load_multipolygonr      s     fJWR8888361222H
7		7 00DOOD/000VACxx  x23 	7 	7 	7_v5666	7
7 ^::::   A B
 
.B8c                    t          |           }|dk    rt          dg           S |dk    st          t          |z            g }	 	 t	          | |          }|                    |d                    t          |           }|dk    rn3n1# t          t          j        f$ r t          t          |z            w xY wut          d|          S )z
    Has similar inputs and return value to to :func:`_load_point`, except is
    for handling MULTILINESTRING geometry.

    :returns:
        A GeoJSON `dict` MultiLineString representation of the WKT ``string``.
    r<   MultiLineStringr?   r   Tr   r   )	r4   rC   r+   r   r   r   r   rV   r   )rH   rG   r7   r   r   r[   s         r	   _load_multilinestringr   ?  s     fJW*;;;;361222H
7		7&vv66GOOGM2333VACxx  x23 	7 	7 	7_v5666	7
7 &H====r   c                    t          |           }|dk    rt          dg           S |dk    st          t          |z            g }t          d|          }	 	 t          |           }|dk    rnw|dk    r|}t                              |          } || |          }|                    |           n1# t          t          j	        f$ r t          t          |z            w xY w|S )a*  
    Has similar inputs and return value to to :func:`_load_point`, except is
    for handling GEOMETRYCOLLECTIONs.

    Delegates parsing to the parsers for the individual geometry types.

    :returns:
        A GeoJSON `dict` GeometryCollection representation of the WKT
        ``string``.
    r<   r   r>   r   Tr   r   )
r4   rC   r+   r   rB   r    r   r   rV   r   )	rH   rG   r7   r   r/   r[   r-   	load_funcr   s	            r	   _load_geometrycollectionr   ^  s    fJW-"====361222E+>>>F7	7VACxxc	+//	::	 y00T""""x23 	7 	7 	7_v5666	77 Ms   B4 /B4 6=B4 4.C")r   r   r   r   r   r   r   )POINT
LINESTRINGPOLYGON
MULTIPOINTMULTILINESTRINGMULTIPOLYGONr=   r   r   r   r   r   r   r   )r   ) rT   rE   rV   r'   r   r   r
   r   r   r8   r   r@   r!   ri   rw   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   rB   rC   rD   rO   r   r	   <module>r      s   
			             &
  
  
 
% 
% 
%+ + + +\
 
 
$ $ $N  8C C C  >  2! ! !,  *! ! !(& & &4# # #<) ) ),!2 !2 !2H!7 !7 !7H44 44 44n)7 )7 )7X; ; ;>> > >># # #N "",&2  "",&2  $
%+     r   