Back to <a SpatiaLite page</a>
<h2>Reading SHP and DBF files directly from within a Zipfile</h2>
Starting since version <b>5.0.0</b> SpatiaLite has the capability to directly read any <b>Shapefile</b> (or <b>DBF</b> file) contained within a compressed <b>Zipfile</b>.<br>
Several closely related SQL functions have been introduced as well.
<h3>Accessing a Zipped SHP</h3>
All these new SQL functions are now supported:
<ul>
<li><b>ImportZipSHP()</b>: the main function allowing to import a whole Shapefile into a new Spatial Table into the currently connected Database.</li>
<li><b>PROJ_GuessSridFromZipSHP()</b>: a helper fuction for attempting to guess the SRID for a given zipped SHP.</li>
<li><b>Zipfile_NumSHP()</b>: a helper function returning the total count of Shapefiles contained within a given Zipfile.</li>
<li><b>Zipfile_ShpN()</b>: a helper function returning the for the <b>Nth</b> Shapefile contained within a given Zipfile.</li>
</ul>
<br>
We'll now start a quick tutorial about using all these new SQL functions.
<b>Note</b>: the tutorial is based on the dataset you can download from <a
<verbatim>
SELECT Zipfile_NumSHP ( )
------------
4
</verbatim>
<ul>
<li>the SQL function <b>Zipfile_NumSHP()</b> will inspect a Zipfile then returning the total count of Shapefiles it contains.</li>
<li>it requires just a single argument: the absolute or relative path leading to the Zipfile.</li>
<li><b>Note</b> it will return <b>0</b> if the Zipfile does not contain any Shapefile.
<ul>
<li><b>NULL</b> will be returned if the Zipfile does not exist of if it's corrupted or invalid.</li>

</ul>
<verbatim>
SELECT Zipfile_shpN ( , 1 )
------


SELECT Zipfile_shpN ( , 2 )
------


SELECT Zipfile_shpN ( , 3 )
------


SELECT Zipfile_shpN ( , 4 )
-------

</verbatim><ul>
<li>the SQL function <b>Zipfile_ShpN()</b> will inspect a Zipfile then returning the of the <b>Nth</b> Shapefile it contains.</li>
<li>it requires two argumenst:
<ul>
<li>the absolute or relative path leading to the Zipfile.</li>
<li>the relative index (<b>1 based</b>) of the Shapefile within the Zipfile.</li>

<li><b>Note</b>: <b>NULL</b> will be returned if the Zipfile does not exist of if it's invalid or if the index value is outside the expected range.</li>
</ul>
<verbatim>
SELECT PROJ_GuessSridFromZipSHP ( , )
------------
32632
</verbatim>
<li>the SQL function <b>PROJ_GuessSridFromZipSHP()</b> will inspect a Zipfile then returning the <b>SRID</b> value declared by the <b>.PRJ</b> member  of the Shapefile contained into the Zipfiles as identified by its
<li>it requires two argumenst:
<ul>
<li>the absolute or relative path leading to the Zipfile.</li>
<li>the of the Shapefile within the Zipfile (without adding any <b>.shp</b>, <b>.shx</b> or <b>.dbf</b> suffix).</li>

<li><b>Note</b>: <b>-1</b> will be returned if the Shapefile has no <b>.PRJ</b> member, of if it contains an invalid WKT definition.</li>
<ul>
will be returned on invalid arguments or if the Shapefile does not exist.</li>

</ul>
<br><br>
<hr>
<h3>Accessing a Zipped DBF</h3>
All these new SQL functions are now supported:
<ul>
<li><b>ImportZipDBF()</b>: the main function allowing to import a whole DBF file into a new Table into the currently connected Database.</li>
<li><b>Zipfile_NumDBF()</b>: a helper function returning the total count of DBF files contained within a given Zipfile.</li>
<li><b>Zipfile_DbfN()</b>: a helper function returning the for the <b>Nth</b> DBF file contained within a given Zipfile.</li>
</ul>

<br><hr><br>
Back to <a SpatiaLite page</a>