o
    hDD                     @   sl  d dl Zd dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
mZmZmZmZ ejdZee
ee
 ee
ejjk@  ZejejejejfZejejfejejfejejffZ ejejffZ!ej"dkrzeej#f7 Ze ej$ej#ff7 Z e%d d dde%ddd	d	e%d
d
dde%ddddgZ&ee
ee
 e'e
dk@  Z(ej)de
ej)dedd Z*ej)dedd Z+ej)deej)deej)dg ddd Z,ej)de-ddej)de dd Z.ej)de dd Z/ej)de dd Z0ej)de d d! Z1ej)d"e-d#ej)de d$d% Z2ej)d"e-d#ej)de d&d' Z3ej)de d(d) Z4ej)de-dd#ej)de d*d+ Z5ej)de-dd#ej)de d,d- Z6ej)de!d.d/ Z7ej)de!d0d1 Z8ej)de-ddej)de!ej)dd dgd2d3 Z9ej)de!d4d5 Z:ej)d"e-d#ej)de!d6d7 Z;ej)d"e-d#ej)de!d8d9 Z<ej)de-dd#ej)de!d:d; Z=ej)de-dd
d<d= Z>d>d? Z?d@dA Z@ej)dBdCdD e(D dEdD e(D  dFdG ZAej)dHe%dIdIdde%d dJdKdgd edLfe%dIdIdde%d dJdKdgdIedLfe%dIdIdde%d dJdKdgdeg dMfe%dIdIdde%d dJdKdgdeg dNfe%dIdIdde%d dJdKdgdOe fgdPdQ ZBdRdS ZCdTdU ZDdVdW ZEdXdY ZFdZd[ ZGd\d] ZHd^d_ ZId`da ZJdbdc ZKdS )d    N)GeometryGeometryCollectionPolygon)assert_geometries_equal)	all_typesemptyignore_invalidpointpolygonz?ignore:The symmetric_difference_all function:DeprecationWarning      r               	   
   afuncc                 C   s   |t ju r| jdkrt | dkrt jdkrtd || t}t|t	s'J || | gt}|j
dks5J t|d t	s>J d S )Nr   r   )r   r   r   z(GEOS 3.9.5 crashes with mixed collectionr   r   )shapely
difference	geom_typeget_num_geometriesgeos_versionpytestxfailr	   
isinstancer   shape)r   r   actual r!   \/var/www/html/scripts/venv/lib/python3.10/site-packages/shapely/tests/test_set_operations.pytest_set_operation_array8   s   




r#   c                 C   sX   | t ju r
td tjtdd | ttdgd W d    d S 1 s%w   Y  d S )N0disjoint_subset_union does not support grid_size.grid_size parameter only accepts scalar valuesmatch   	grid_size)r   disjoint_subset_unionr   skipraises
ValueErrorr	   )r   r!   r!   r"   +test_set_operation_prec_nonscalar_grid_sizeJ   s   

"r/   r*   )r   r(   r   c                 C   s   |t ju r
td || | gt|d}|jdksJ t|d ts#J t j| |d}t jt|d}|||g|}t 	t 
|t 
| sHJ d S )Nr$   r)   r   r   )r   r+   r   r,   r	   r   r   r   set_precisionequals	normalizeall)r   r   r*   r    bpoint2expectedr!   r!   r"   test_set_operation_prec_arrayT   s   

$r7   nr(   zfunc, related_funcc                 C   sJ   |t d |  }t d }td| D ]	}||t | }qt||s#J d S )Nr   r(   reduce_test_dataranger   r1   )r8   r   related_funcr    r6   ir!   r!   r"   test_set_operation_reduce_1dimg   s
   r>   c                 C   s.   t dd}| |d d g}t ||sJ d S )Nr(   )r   Pointr1   )r   r<   geomr    r!   r!   r"   %test_set_operation_reduce_single_geomr   s   rA   c                 C   s|   t gd gd }| |d d}t|tsJ | |dd}|jdks"J | |dd}|jdks/J | |dd}|jdks<J d S )	Nr   r   axisr   r   r(   r   r	   r   r   r   r   r<   datar    r!   r!   r"   test_set_operation_reduce_axisy   s   rI   c                 C   sr   | t jdtdtksJ t jdtd}| |tksJ | |dd tgd ks+J | |dd g ks7J d S )N)r   )dtype)r   r   r   rB   r   r(   )npr   objecttolist)r   r<   arr_empty_2Dr!   r!   r"   test_set_operation_reduce_empty   s
   rO   none_positionr   c                 C   s@   t d d }||d  | |}|t d t d }t|| d S Nr   r   r(   r:   insertr   r   r<   rP   	test_datar    r6   r!   r!   r"   "test_set_operation_reduce_one_none   s
   rV   c                 C   sL   t d d }||d  ||d  | |}|t d t d }t|| d S rQ   rR   rT   r!   r!   r"   "test_set_operation_reduce_two_none   s   rW   c                 C   s   | t d gt ks
J d S N)r   r   r<   r!   r!   r"   (test_set_operation_reduce_some_none_len2   s   rZ   c                 C   s   t |d g|  tg  d S rX   r   r   r8   r   r<   r!   r!   r"   "test_set_operation_reduce_all_none   s   r]   c                 C   sT   |d g|  gd dd  ttgksJ |d gd g|  dd  ttgks(J d S )Nr   r(   rB   r   )rM   r   r\   r!   r!   r"   &test_set_operation_reduce_all_none_arr   s   (,r^   c                 C   sF   t jtdd | ttgdgd W d    d S 1 sw   Y  d S )Nr%   r&   r(   r)   )r   r-   r.   r	   rY   r!   r!   r"   2test_set_operation_prec_reduce_nonscalar_grid_size   s
   "r_   c                 C   s"   | t t gtjd}|d u sJ d S Nr)   )r	   rK   nan)r   r<   r    r!   r!   r"   ,test_set_operation_prec_reduce_grid_size_nan   s   rb   c                 C   sR   |t d |  |d}t d }td| D ]}||t | |d}qt||s'J d S )Nr)   r   r(   r9   )r8   r   r<   r*   r    r6   r=   r!   r!   r"   #test_set_operation_prec_reduce_1dim   s
   rc   c                 C   s   t gd gd }| |dd d}t|tsJ | |ddd}|jdks$J | |ddd}|jdks2J | |ddd}|jdks@J d S )	Nr   r   r(   )r*   rC   r   r   rD   rE   rF   rG   r!   r!   r"   #test_set_operation_prec_reduce_axis   s   rd   c                 C   sH   t d d }||d  | |dd}|t d t d dd}t|| d S Nr   r(   r)   r   rR   rT   r!   r!   r"   'test_set_operation_prec_reduce_one_none   s
   rf   c                 C   sT   t d d }||d  ||d  | |dd}|t d t d dd}t|| d S re   rR   rT   r!   r!   r"   'test_set_operation_prec_reduce_two_none   s   rg   c                 C   s    t |d g|  ddtg  d S )Nr(   r)   r[   r\   r!   r!   r"   'test_set_operation_prec_reduce_all_none   s    rh   c                 C   sz   t ddddt ddddt ddddg}t |d|  }|d }td| D ]
}t ||| }q)t||dd dS )zm
    This is tested separately from other set operations as it expects only
    non-overlapping polygons
    r   r(   r   r   NTr2   )r   boxcoverage_union_allr;   coverage_unionr   )r8   rU   r    r6   r=   r!   r!   r"   test_coverage_union_reduce_1dim   s   rm   c                  C   s   dd t dD } tj| d d}t|tsJ tj| dd}|jdks%J tj| dd}|jdks3J tj| d	d}|jdksAJ d S )
Nc                    s"   g | ]  fd dt dD qS )c              	      s$   g | ]}t | |d   d  qS )r(   )r   rj   ).0r=   jr!   r"   
<listcomp>  s   $ z>test_coverage_union_reduce_axis.<locals>.<listcomp>.<listcomp>r   )r;   )rn   r!   ro   r"   rq     s   " z3test_coverage_union_reduce_axis.<locals>.<listcomp>r   rB   r   r   r(   rD   rE   )r;   r   rk   r   r   r   )rH   r    r!   r!   r"   test_coverage_union_reduce_axis  s   rr   c                  C   s   t g d} t g d}tjdkr't| |}t| |g}t||dd d S tjtjdd t| | W d    d S 1 sAw   Y  d S )N)r(   r(   r(   r   r   r   )r   r(   rs   )rt   )g?r(   )r   r(   )r   r   rt   r   Tri   z6CoverageUnion cannot process incorrectly noded inputs.r&   )	r   r   r   rl   multipolygonsr   r   r-   GEOSException)r
   otherresultr6   r!   r!   r"   &test_coverage_union_overlapping_inputs  s   
"rz   zgeom_1, geom_2c                 C   s   g | ]}t |gqS r!   )r
   )rn   non_polygonr!   r!   r"   rq   3  s    rq   c                 C   s   g | ]}t D ]}||gqqS r!   )non_polygon_types)rn   non_polygon_1non_polygon_2r!   r!   r"   rq   5  s    c                    s  t jdkra fdd  | } |}t|dkr@||kr@t  t | |}W d    n1 s1w   Y  | |ks>J d S tjt jdd t | | W d    d S 1 sZw   Y  d S tjt jdd t | | W d    d S 1 s{w   Y  d S )Nr   c                    sH   t | dr| jst }| jD ]}| |O }q|S | jdddhS )NgeomsMulti
LinearRing
LineString)hasattris_emptysetr   r   lstripreplace)r@   gtsparteffective_geom_typesr!   r"   r   >  s   
zDtest_coverage_union_non_polygon_inputs.<locals>.effective_geom_typesr(   z Overlay input is mixed-dimensionr&   z)Unhandled geometry type in CoverageUnion.)r   r   lenr   rl   r   r-   rw   )geom_1geom_2geom_types_1geom_types_2ry   r!   r   r"   &test_coverage_union_non_polygon_inputs0  s&   
""r   zgeom,grid_size,expected皙?皙?ffffff@)	r   r   r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   )r   r   r   )r   r   )r   r   )r   r   ru   r   )r   )r   r   )r   r   ru   r   d   c                 C   s"   t j| |d}t ||sJ d S r`   )r   	union_allr1   )r@   r*   r6   r    r!   r!   r"   test_union_all_precZ  s   =r   c                  C   sP   t ddddt ddddg} t j| dd}t j| dd}t ||s&J d S )	Nr   r   r   r   r   r   r(   r)   )r   rj   unary_unionr   r1   )r   r    r6   r!   r!   r"   test_uary_union_alias  s    r   c                   C   @   t jdd tttd  W d    d S 1 sw   Y  d S )Nz>positional argument `grid_size` for `difference` is deprecatedr&   )r   deprecated_callr   r   r	   r!   r!   r!   r"   $test_difference_deprecate_positional  
   "r   c                   C   r   )Nz@positional argument `grid_size` for `intersection` is deprecatedr&   )r   r   r   intersectionr	   r!   r!   r!   r"   &test_intersection_deprecate_positional  r   r   c                   C   B   t jdd tttgd  W d    d S 1 sw   Y  d S )Nz?positional argument `axis` for `intersection_all` is deprecatedr&   )r   r   r   intersection_allr	   r!   r!   r!   r"   *test_intersection_all_deprecate_positional  
   "r   c                   C   r   )NzHpositional argument `grid_size` for `symmetric_difference` is deprecatedr&   )r   r   r   symmetric_differencer	   r!   r!   r!   r"   .test_symmetric_difference_deprecate_positional  r   r   c                   C   r   )NzGpositional argument `axis` for `symmetric_difference_all` is deprecatedr&   )r   r   r   symmetric_difference_allr	   r!   r!   r!   r"   2test_symmetric_difference_all_deprecate_positional  r   r   c                   C   r   )Nz9positional argument `grid_size` for `union` is deprecatedr&   )r   r   r   unionr	   r!   r!   r!   r"   test_union_deprecate_positional  r   r   c                   C   s   t jdd tttgd  W d    n1 sw   Y  t jdd tttgd d  W d    d S 1 s9w   Y  d S )Nz=positional argument `grid_size` for `union_all` is deprecatedr&   zJpositional arguments `grid_size` and `axis` for `union_all` are deprecated)r   r   r   r   r	   r!   r!   r!   r"   #test_union_all_deprecate_positional  s   "r   c                  C   s^   t ddddt ddddg} tjdd t | d  W d    d S 1 s(w   Y  d S )Nr   r(   r   zApositional argument `axis` for `coverage_union_all` is deprecatedr&   )r   rj   r   r   rk   )rH   r!   r!   r"   ,test_coverage_union_all_deprecate_positional  s    "r   )LnumpyrK   r   r   r   r   r   shapely.testingr   shapely.tests.commonr   r   r   r	   r
   markfilterwarnings
pytestmarkarrayr   get_type_idGeometryTypeGEOMETRYCOLLECTIONall_single_typesr   r   r   r   SET_OPERATIONSr   r   r   REDUCE_SET_OPERATIONSREDUCE_SET_OPERATIONS_PRECr   r+   disjoint_subset_union_allrj   r:   get_dimensionsr|   parametrizer#   r/   r7   r;   r>   rA   rI   rO   rV   rW   rZ   r]   r^   r_   rb   rc   rd   rf   rg   rh   rm   rr   rz   r   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   <module>   s   

	




		


	




	




<