
    h-              
          d dl mZ d dlmZ d dlmZmZ d dlZd dl	m
Z
mZmZ d dlmZmZmZmZmZmZ d dlmZ d dlmZmZ d dlZ ee      j6                  j9                         d	z  Zd
ddddddddd	Zej?                         D  ci c]  \  } }|| 
 c}} Z g dZ!d d d d dd dZ"d Z#ejH                  jK                  e d      Z&ejH                  jK                  e xs e d      Z'ejH                  jK                  e d      Z(ejH                  jK                  e xs e d      Z)ejH                  jK                  e d      Z*ejH                  jK                  e d      Z+d Z, ejZ                  d      d        Z. ejZ                  d      d         Z/ ejZ                  de!!      d"        Z0 ejZ                  dd#g!      d$        Z1 ejZ                  d      d%        Z2 ejZ                  d      d&        Z3 ejZ                  d      d'        Z4 ejZ                  d      d(        Z5 ejZ                  d      d)        Z6 ejZ                  d      d*        Z7 ejZ                  d      d+        Z8 ejZ                  d      d,        Z9 ejZ                  d      d-        Z: ejZ                  d      d.        Z; ejZ                  d      d/        Z< ejZ                  d      d0        Z= ejZ                  d      d1        Z> ejZ                  d      d2        Z? ejZ                  d      d3        Z@ ejZ                  dg d4!      d5        ZAyc c}} w )6    )BytesIO)Path)ZIP_DEFLATEDZipFileN)__gdal_version_string____version__list_drivers)HAS_ARROW_APIHAS_ARROW_WRITE_APIHAS_GDAL_GEOSHAS_PYARROW
HAS_PYPROJHAS_SHAPELY)
vsi_rmtree)readwritefixtures
FlatGeobufGeoJSON
GeoJSONSeqGPKGzESRI Shapefile)	.fgb.geojson	.geojsonl	.geojsons.gpkgz	.gpkg.zip.shpz.shp.zipz.shz)r   r   r   r   r      )r   r   r   r   r   r   c                     dj                  d t        t               j                               D              }dt         dt
         d| S )Nz, c              3   2   K   | ]  \  }}| d | d  yw)()N ).0driver
capabilitys      I/var/www/html/immo/lib/python3.12/site-packages/pyogrio/tests/conftest.py	<genexpr>z'pytest_report_header.<locals>.<genexpr>8   s)      FJ (!J<q!s   zpyogrio z
GDAL z
Supported drivers: )joinsortedr	   itemsr   r   )configdriverss     r'   pytest_report_headerr.   7   sU    ii "()=)=)?"@ G
 ;-  '( )%Y	(    zGDAL>=3.6 required)reasonzGDAL>=3.6 and pyarrow requiredzpyproj requiredz&GDAL>=3.8 required for Arrow write APIz GDAL compiled with GEOS requiredzShapely >= 2.0 requiredc                     || j                   k(  r| S || j                   | z  }|j                         r|S t        |       \  }}}}|dk(  rd|d<   d|d<   n|dk(  r
d|d<   d|d<   t	        |||fi | |S )Nr   Fspatial_indexUnknowngeometry_typer   MultiPolygon)suffixstemexistsr   r   )testfile_pathdst_dirextdst_pathmeta_geometry
field_datas           r'   prepare_testfilerA   W   s    
m"""M../u55H$($7!D!Xz
f} %_ )_	 %_ ._	(Hj1D1Or/   session)scopec                      t         S N	_data_dirr#   r/   r'   data_dirrH   p   s    r/   functionc                 Z    t        |dd      }t        t        d      z  }t        || |      S )Nparamr   +naturalearth_lowres/naturalearth_lowres.shp)getattrrG   r   rA   )tmp_pathrequestr;   r9   s       r'   naturalearth_lowresrP   u   s/    
'7F
+C%R SSMM8S99r/   )rC   paramsc                 0    t        || |j                        S rE   rA   rK   rN   rP   rO   s      r'   naturalearth_lowres_all_extrU   }       /7==IIr/   r   c                 0    t        || |j                        S rE   rS   rT   s      r'   naturalearth_lowres_geojsonrX      rV   r/   c                    | |j                    dz  }t        |dt        d      5 }dD ]2  }|j                   d| }|j	                  |j
                  |z  |       4 	 ddd       |d| d	|j                    fS # 1 sw Y   xY w)
z4Wrap naturalearth_lowres as a zip file for VSI testsz.zipw   )modecompressioncompresslevel)dbfprjshpshxcpg.Nz/vsizip//)namer   r   r7   r   parent)rN   rP   pathoutr;   filenames         r'   naturalearth_lowres_vsirk      s     ,112$77D	C\	K Gs6 	GC-2231SE:HII)008;XF	GG
 8D6#6#;#;"<===G Gs   8A;;Bc              #      K   t        |       \  }}}}d| j                   }t        d| d| d      }d|d<   d|d<   t        |||fd	d
i| | t	        |j
                         yw)z8Write naturalearth_lowres to a vsimem file for VSI testspyogrio_fixture_z/vsimem/re   r   Fr2   r5   r4   layerrP   N)r   r7   r   r   r   rg   )rP   r=   r>   r?   r@   rf   r<   s          r'   naturalearth_lowres_vsimemro      s      %))<$=!D!Xz16678DhtfAdV512H!D*D	(HjN0ENN
Nxs   A&A(c                      t         dz  S )Nzline_zm.gpkgrF   r#   r/   r'   line_zm_filerq      s    ~%%r/   c                      t         dz  S )Nz
curve.gpkgrF   r#   r/   r'   
curve_filers      s    |##r/   c                      t         dz  S )Nzcurvepolygon.gpkgrF   r#   r/   r'   curve_polygon_fileru          ***r/   c                      t         dz  S )Nzmultisurface.gpkgrF   r#   r/   r'   multisurface_filerx      rv   r/   c                      t         dz  S )Nztest_gpkg_nulls.gpkgrF   r#   r/   r'   test_gpkg_nullsrz      s    ---r/   c           	      ^    | dz  }t        |dd t        j                  g d      gdg       |S )Nztest_no_geometry.gpkgno_geometry)abccol)rn   r?   r@   fields)r   nparray)rN   rj   s     r'   no_geometry_filer      s;     11H	HH_-.w Or/   c                 z    d}| dz  }t        |d      5 }|j                  |      }d d d        |S # 1 sw Y   |S xY w)NaB  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { "int64": 1, "list_int64": [0, 1] },
                "geometry": { "type": "Point", "coordinates": [0, 2] }
            },
            {
                "type": "Feature",
                "properties": { "int64": 2, "list_int64": [2, 3] },
                "geometry": { "type": "Point", "coordinates": [1, 2] }
            },
            {
                "type": "Feature",
                "properties": { "int64": 3, "list_int64": [4, 5] },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            },
            {
                "type": "Feature",
                "properties": { "int64": 4, "list_int64": [6, 7] },
                "geometry": { "type": "Point", "coordinates": [3, 2] }
            },
            {
                "type": "Feature",
                "properties": { "int64": 5, "list_int64": [8, 9] },
                "geometry": { "type": "Point", "coordinates": [4, 2] }
            }
        ]
    }ztest_ogr_types_list.geojsonrZ   openr   )rN   list_geojsonrj   fr>   s        r'   list_field_values_filer      sN    	L> 77H	h	 "GGL!" O" O   0:c                 z    d}| dz  }t        |d      5 }|j                  |      }d d d        |S # 1 sw Y   |S xY w)Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [0, 0]
                },
                "properties": {
                    "top_level": "A",
                    "intermediate_level": {
                        "bottom_level": "B"
                    }
                }
            }
        ]
    }ztest_nested.geojsonrZ   r   )rN   nested_geojsonrj   r   r>   s        r'   nested_geojson_filer      sN    	N& //H	h	 $GGN#$ O$ Or   c                 z    d}| dz  }t        |d      5 }|j                  |      }d d d        |S # 1 sw Y   |S xY w)Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { "col": "2020-01-01T09:00:00.123" },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            },
            {
                "type": "Feature",
                "properties": { "col": "2020-01-01T10:00:00" },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            }
        ]
    }ztest_datetime.geojsonrZ   r   )rN   datetime_geojsonrj   r   r>   s        r'   datetime_filer     sP    	  11H	h	 &GG$%& O& Or   c                 z    d}| dz  }t        |d      5 }|j                  |       d d d        |S # 1 sw Y   |S xY w)Na  {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { "datetime_col": "2020-01-01T09:00:00.123-05:00" },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            },
            {
                "type": "Feature",
                "properties": { "datetime_col": "2020-01-01T10:00:00-05:00" },
                "geometry": { "type": "Point", "coordinates": [2, 2] }
            }
        ]
    }ztest_datetime_tz.geojsonrZ   r   )rN   datetime_tz_geojsonrj   r   s       r'   datetime_tz_filer   ,  sN    	  44H	h	 %	#$% O% Or   c                     t        t        t        d      z  d      \  }}}}| dz  }t        |||fi | t	        |d      5 }|j                         }ddd       |S # 1 sw Y   S xY w)z\Extracts first 3 records from naturalearth_lowres and writes to GeoJSON,
    returning bytesrL      max_featurestest.geojsonrbNr   rG   r   r   r   )rN   r=   r>   r?   r@   rj   r   bytes_buffers           r'   geojson_bytesr   F  s|     %)DFGGVW%!D!Xz .(H	(Hj1D1	h	  vvx    s   AA'c              #      K   t        t        t        d      z  d      \  }}}}| dz  }t        |||fddi| t	        |d      5 }| ddd       y# 1 sw Y   yxY ww)	zgExtracts first 3 records from naturalearth_lowres and writes to GeoJSON,
    returning open file handlerL   r   r   r   rn   testr   Nr   )rN   r=   r>   r?   r@   rj   r   s          r'   geojson_fileliker   W  ss      %)DFGGVW%!D!Xz .(H	(Hj??$?	h	   s   AA A	A AA c                 R     G d dt               }d} ||j                  d            S )Nc                       e Zd Zd Zd Zy)-nonseekable_bytes.<locals>.NonSeekableBytesIOc                      y)NFr#   )selfs    r'   seekablez6nonseekable_bytes.<locals>.NonSeekableBytesIO.seekablej  s    r/   c                     t        d      )Nzcannot seek)OSError)r   argskwargss      r'   seekz2nonseekable_bytes.<locals>.NonSeekableBytesIO.seekm  s    -((r/   N)__name__
__module____qualname__r   r   r#   r/   r'   NonSeekableBytesIOr   i  s    		)r/   r   z{
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": { },
                "geometry": { "type": "Point", "coordinates": [1, 1] }
            }
        ]
    }zUTF-8)r   encode)rN   r   geojsons      r'   nonseekable_bytesr   f  s+    )W )		G gnnW566r/   ))CP932u   ﾎ)CP936u   中文)CP1250u   Đ)CP1252   ÿ)CP1253u   Φ)CP1256u   شc                     | j                   S )a'  Return tuple with encoding name and very short sample text in that encoding
    NOTE: it was determined through testing that code pages for MS-DOS do not
    consistently work across all Python installations (in particular, fail with conda),
    but ANSI code pages appear to work properly.
    )rK   )rO   s    r'   encoded_textr     s    . ==r/   )Bior   pathlibr   zipfiler   r   numpyr   pyogrior   r   r	   pyogrio._compatr
   r   r   r   r   r   pyogrio.corer   pyogrio.rawr   r   pytest__file__rg   resolverG   DRIVERSr+   
DRIVER_EXTALL_EXTS	START_FIDr.   markskipifrequires_arrow_apirequires_pyarrow_apirequires_pyprojrequires_arrow_write_apirequires_gdal_geosrequires_shapelyrA   fixturerH   rP   rU   rX   rk   ro   rq   rs   ru   rx   rz   r   r   r   r   r   r   r   r   r   )r;   r%   s   00r'   <module>r      s     )  
  $ # N!!))+j8	  
 .5]]_=kc6fck=
= 		 [[''M(9BV'W {{))([1Q *   ++$$^<M$N!;;--.;3 .  
 [[''@ (   ;;%%+o>W%X 2 i  ! j!: ": j2J 3J j*6J 7J j!	> "	> j!  "  i & !& i $ !$ i + !+ i + !+ i . !. j! " j!% "%P j! "8 j! "2 j! "2 j! "  j! " j!7 "70 
"#"O >s   M$