<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to unlock GeoPackage so can delete it in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-unlock-geopackage-so-can-delete-it/m-p/1208428#M65632</link>
    <description>&lt;P&gt;How can one remove a lock on a GeoPackage when used with a Python Toolbox?&amp;nbsp;I have posted a similar question on &lt;A href="https://gis.stackexchange.com/questions/439512/properly-closing-geopackage-after-opening-by-ogr-so-as-to-delete-it-later" target="_self"&gt;GIS Stack Exchange.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My overall goal is to download a GeoPackage from online, and then create a shapefile copy of a subset of it (based on what area of the GeoPackage layer intersects another shapefile). After that, I don't need the large GeoPackage anymore and want to delete it. However, when trying to delete with os.remove,&amp;nbsp; I'm getting:&amp;nbsp;&lt;SPAN&gt;PermissionError: [WinError 32] The process cannot access the file because it is being used by another process. When using arcpy.Delete_management, I get:&amp;nbsp;ERROR 000601: Cannot delete gpkg. May be locked by another application. Here's a minimum reproducible example:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;gpkg_wesm = &lt;SPAN class=""&gt;'my/output/directory/WESM.gpkg'&lt;/SPAN&gt;
urllib.request.urlretrieve(&lt;SPAN class=""&gt;'https://rockyweb.usgs.gov/vdelivery/Datasets/Staged/Elevation/metadata/WESM.gpkg'&lt;/SPAN&gt;, filename = gpkg_wesm)
gpkg_ds = osgeo.ogr.Open(gpkg_wesm, update = &lt;SPAN class=""&gt;1&lt;/SPAN&gt;)
lyr0 = gpkg_ds.GetLayer(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;)
layer_wesm = &lt;SPAN class=""&gt;os&lt;/SPAN&gt;.&lt;SPAN class=""&gt;path&lt;/SPAN&gt;.join(gpkg_wesm, lyr0.GetDescription())     
arcpy.FeatureClassToFeatureClass_conversion(in_features = layer_wesm, out_path = &lt;SPAN class=""&gt;'my/output/directory'&lt;/SPAN&gt;, out_name = &lt;SPAN class=""&gt;'WESM.shp'&lt;/SPAN&gt;)
gpkg_ds = None
&lt;SPAN class=""&gt;os&lt;/SPAN&gt;.&lt;SPAN class=""&gt;remove&lt;/SPAN&gt;(gpkg_wesm)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Aug 2022 20:18:07 GMT</pubDate>
    <dc:creator>Eniac-6</dc:creator>
    <dc:date>2022-08-31T20:18:07Z</dc:date>
    <item>
      <title>How to unlock GeoPackage so can delete it</title>
      <link>https://community.esri.com/t5/python-questions/how-to-unlock-geopackage-so-can-delete-it/m-p/1208428#M65632</link>
      <description>&lt;P&gt;How can one remove a lock on a GeoPackage when used with a Python Toolbox?&amp;nbsp;I have posted a similar question on &lt;A href="https://gis.stackexchange.com/questions/439512/properly-closing-geopackage-after-opening-by-ogr-so-as-to-delete-it-later" target="_self"&gt;GIS Stack Exchange.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My overall goal is to download a GeoPackage from online, and then create a shapefile copy of a subset of it (based on what area of the GeoPackage layer intersects another shapefile). After that, I don't need the large GeoPackage anymore and want to delete it. However, when trying to delete with os.remove,&amp;nbsp; I'm getting:&amp;nbsp;&lt;SPAN&gt;PermissionError: [WinError 32] The process cannot access the file because it is being used by another process. When using arcpy.Delete_management, I get:&amp;nbsp;ERROR 000601: Cannot delete gpkg. May be locked by another application. Here's a minimum reproducible example:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;gpkg_wesm = &lt;SPAN class=""&gt;'my/output/directory/WESM.gpkg'&lt;/SPAN&gt;
urllib.request.urlretrieve(&lt;SPAN class=""&gt;'https://rockyweb.usgs.gov/vdelivery/Datasets/Staged/Elevation/metadata/WESM.gpkg'&lt;/SPAN&gt;, filename = gpkg_wesm)
gpkg_ds = osgeo.ogr.Open(gpkg_wesm, update = &lt;SPAN class=""&gt;1&lt;/SPAN&gt;)
lyr0 = gpkg_ds.GetLayer(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;)
layer_wesm = &lt;SPAN class=""&gt;os&lt;/SPAN&gt;.&lt;SPAN class=""&gt;path&lt;/SPAN&gt;.join(gpkg_wesm, lyr0.GetDescription())     
arcpy.FeatureClassToFeatureClass_conversion(in_features = layer_wesm, out_path = &lt;SPAN class=""&gt;'my/output/directory'&lt;/SPAN&gt;, out_name = &lt;SPAN class=""&gt;'WESM.shp'&lt;/SPAN&gt;)
gpkg_ds = None
&lt;SPAN class=""&gt;os&lt;/SPAN&gt;.&lt;SPAN class=""&gt;remove&lt;/SPAN&gt;(gpkg_wesm)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 20:18:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-unlock-geopackage-so-can-delete-it/m-p/1208428#M65632</guid>
      <dc:creator>Eniac-6</dc:creator>
      <dc:date>2022-08-31T20:18:07Z</dc:date>
    </item>
  </channel>
</rss>

