<?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 Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077513#M61678</link>
    <description>&lt;P&gt;you need to put your files into a folder... writing to, and reading from the root folder (C:\) is just asking for trouble.&lt;/P&gt;&lt;P&gt;Also, overwriting files is controlled at the project level in Pro, under Geoprocessing Options or by setting the flag within the script (arcpy.env.overwriteOutputs=True) as you have done.&amp;nbsp; However, if a file is used within a loop it may not be able to be deleted until the whole process is complete.&lt;/P&gt;&lt;P&gt;ps&lt;/P&gt;&lt;PRE&gt;"C:\Fire.gdb\Fire.gdb\Buildings_Select"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a gdb in a gdb?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jul 2021 18:20:56 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-07-10T18:20:56Z</dc:date>
    <item>
      <title>ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration. UPDATE</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077508#M61677</link>
      <description>&lt;P&gt;_______________&lt;/P&gt;&lt;P&gt;Forgive me, my language is probably off - I'm very new to programming and this is the first real script I've been asked to write. It's simple, runs through some geoprocessing tools and then prints out a map. When I run it outside of a loop it works fine, however when I get to the point in the second iteration where a mask is extracted from an RGB image file it fails, this is the error I get:&lt;/P&gt;&lt;P&gt;File "C:/Iteration.py", line 34, in &amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APN8_Raster.save(Extract_by_Mask)&lt;BR /&gt;RuntimeError: ERROR 000871: Output Raster: Unable to delete the output C:\Extract_RSF.&lt;/P&gt;&lt;P&gt;I've also gotten a schema lock error, my worry is that the shapefiles I'm looking to overwrite are locked for some reason. I run this script through PyCharm - ArcGIS Pro is closed so for the life of me I cannot figure out why it locks or why it cannot be overwritten. I believe it will do the same thing with the other 2 shape-files required in the process that need to be overwritten in every iteration.&lt;/P&gt;&lt;P&gt;Here's the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcpy import env
env.workspace = r"C:\Users\nahgl\Firewatch\Firewatch.gdb"
env.overwriteOutput = True

fc = "Parcels"
field = ["APN_8"]
RGB_of_RSF = arcpy.Raster("RSF_RGBe_FW2020")
Parcels = "Parcels"
Buildings = "Buildings"
SQL_Expression = "APN_8 = '26603028'"
Map_Expression = "OBJECTID = 1"
Symbology50 = r"C:\Users\nahgl\Firewatch\Python\Symbology_50.lyrx"
Symbology100 = r"C:\Users\nahgl\Firewatch\Python\Symbology_100.lyrx"

with arcpy.da.SearchCursor(fc, field) as cursor:
    for row in cursor:
        print(row[0])
        APN = "APN_8 = " + "'" + row[0] + "'"

        # Process: Select Parcel (Select) (analysis)
        Selected_Parcel = r"C:\Users\nahgl\Firewatch\Firewatch.gdb\Parcels_Select"
        arcpy.analysis.Select(in_features=Parcels, out_feature_class=Selected_Parcel, where_clause=APN)

        # Process: Select Building (Select) (analysis)
        Selected_Buildings = r"C:\Users\nahgl\Firewatch\Firewatch.gdb\Buildings_Select"
        arcpy.analysis.Select(in_features=Buildings, out_feature_class=Selected_Buildings, where_clause=APN)

        # Process: Extract by Mask (Extract by Mask) (sa)
        APN8_Raster = r"memory\Extract_RSF"
        Extract_by_Mask = APN8_Raster
        APN8_Raster = arcpy.sa.ExtractByMask(in_raster=RGB_of_RSF, in_mask_data=Selected_Parcel)
        APN8_Raster.save(Extract_by_Mask)

        # Process: Buffer 100 (Buffer) (analysis)
        Buffer_Output_100 = r"memory\Buffer_100"
        arcpy.analysis.Buffer(in_features=Selected_Buildings, out_feature_class=Buffer_Output_100,
                              buffer_distance_or_field="100 Feet", line_side="FULL", line_end_type="ROUND",
                              dissolve_option="ALL", dissolve_field=[], method="PLANAR")

        # Process: 100ft Buffer Symbology (Apply Symbology From Layer) (management)
        Buffer_Output_100 = arcpy.management.ApplySymbologyFromLayer(in_layer=Buffer_Output_100,
                                                                     in_symbology_layer=Symbology100,
                                                                     symbology_fields=[],
                                                                     update_symbology="DEFAULT")[0]

        # Process: Buffer 50 (Buffer) (analysis)
        Buffer_Output_50 = r"memory\Buffer_50"
        arcpy.analysis.Buffer(in_features=Selected_Buildings, out_feature_class=Buffer_Output_50,
                              buffer_distance_or_field="50 Feet", line_side="FULL", line_end_type="ROUND",
                              dissolve_option="ALL", dissolve_field=[], method="PLANAR")

        # Process: 50ft Buffer Symbology (Apply Symbology From Layer) (management)
        Buffer_Output_50_Final = arcpy.management.ApplySymbologyFromLayer(in_layer=Buffer_Output_50,
                                                                          in_symbology_layer=Symbology50,
                                                                          symbology_fields=[],
                                                                          update_symbology="DEFAULT")[0]

        # Process: Selecting the Project file = Firewatch &amp;amp; Map = RSF_Parcels
        project = arcpy.mp.ArcGISProject(r"C:\Users\nahgl\Firewatch\Firewatch.aprx")
        map = project.listMaps('RSF_Parcels')[0]
        print(map.name)

        # Process: Selecting Buffer_100 as Zoom in layer (Or by Parcels)
        layer = map.listLayers('Buffer_100')[0]
        print(layer)

        # layer = map.listLayers('Parcel')[0] ##If Parcel is used as zoom in layer Map_Expression must be changed to SQL_Expression
        arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", Map_Expression)

        # Process: Selecting Layout that will be used
        lyt = project.listLayouts("RSF_Layout")[0]
        print(lyt.name)

        # Process: Listing all elements within the layout
        mf = lyt.listElements('MAPFRAME_ELEMENT', '*')[0]

        # Process: Setting the extent of the map camera to the selected layer (Buffer_100 or Parcel) &amp;amp; then zooming into frame
        mf.camera.setExtent(mf.getLayerExtent(layer, True, True))
        mf.zoomToAllLayers()

        # Clear the 100 Buffer Selection so it isn't blue
        arcpy.management.SelectLayerByAttribute(layer, "CLEAR_SELECTION")

        # Process: Importing the layout with the zoomed in image to a JPEG (Needs better naming)
        lyt.exportToJPEG(
            r"C:\Users\nahgl\Firewatch\scratch\RGB_%s" % APN[9:-1])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;I've tried deleting the shapefiles after the image is created,&amp;nbsp; this is where I get the schema lock:&lt;/P&gt;&lt;P class="lia-align-left"&gt;"arcgisscripting.ExecuteError: ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application or service.&lt;BR /&gt;Failed to execute (Delete)."&lt;/P&gt;&lt;P class="lia-align-left"&gt;I've done a lot of Google sloothing which leads be to believe this could be a bug? Not sure, using Python 3.7, any advice or help would be much appreciated. Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jul 2021 06:55:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077508#M61677</guid>
      <dc:creator>AndyLaney</dc:creator>
      <dc:date>2021-07-11T06:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077513#M61678</link>
      <description>&lt;P&gt;you need to put your files into a folder... writing to, and reading from the root folder (C:\) is just asking for trouble.&lt;/P&gt;&lt;P&gt;Also, overwriting files is controlled at the project level in Pro, under Geoprocessing Options or by setting the flag within the script (arcpy.env.overwriteOutputs=True) as you have done.&amp;nbsp; However, if a file is used within a loop it may not be able to be deleted until the whole process is complete.&lt;/P&gt;&lt;P&gt;ps&lt;/P&gt;&lt;PRE&gt;"C:\Fire.gdb\Fire.gdb\Buildings_Select"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a gdb in a gdb?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jul 2021 18:20:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077513#M61678</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-10T18:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077516#M61679</link>
      <description>&lt;P&gt;To be sure of no unintended stuff going on with your paths I'd make sure everything is named with the same raw formatting r'...' as per&lt;/P&gt;&lt;PRE&gt;project = arcpy.mp.ArcGISProject(r"C:\Fire.aprx")&lt;/PRE&gt;&lt;P&gt;I think you could avoid a lot of the overrides by using the memory workspace and deleting the memory objects each loop.&lt;/P&gt;&lt;P&gt;I'd follow Dan's suggestions in the first instance.&lt;/P&gt;&lt;P&gt;A final irrelevant point, I've not seen % used in strings very often, I'd say f strings or .format() is preferred.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jul 2021 18:38:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077516#M61679</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-10T18:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077519#M61680</link>
      <description>&lt;P&gt;I removed the middle file paths, sorry for complicating things. Paths are like this:&lt;/P&gt;&lt;DIV&gt;r"C:\Users\nahgl\OneDrive\Desktop\GIS Project\Firewatch\Firewatch.gdb\Parcels_Select"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Would a pause work before it iterates again to clear the lock?&lt;/DIV&gt;</description>
      <pubDate>Sat, 10 Jul 2021 19:21:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077519#M61680</guid>
      <dc:creator>AndyLaney</dc:creator>
      <dc:date>2021-07-10T19:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077520#M61681</link>
      <description>&lt;P&gt;I was reading up on memory workspaces but not quite getting how to implement it. The extracted mask, buffer_100, and buffer_50 would only exist in memory and then it would erase it after the JPEG is produced?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jul 2021 19:26:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077520#M61681</guid>
      <dc:creator>AndyLaney</dc:creator>
      <dc:date>2021-07-10T19:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077523#M61683</link>
      <description>&lt;P&gt;I would try it at least.&amp;nbsp; It is better than trying to delete things until outputs are derived&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jul 2021 20:15:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077523#M61683</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-10T20:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077540#M61685</link>
      <description>&lt;P&gt;What about using the scratch workspace?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jul 2021 00:40:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077540#M61685</guid>
      <dc:creator>AndyLaney</dc:creator>
      <dc:date>2021-07-11T00:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000871 or Schema Lock Trying to write over shapefiles in iteration.</title>
      <link>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077545#M61686</link>
      <description>&lt;P&gt;Did you try it? Nothing is going to happen to the inputs data if you try stuff in the scratch workspace or in_memory.&amp;nbsp; Either or.. Focus on getting to work, then optimize for speed or convenience after&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jul 2021 01:30:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000871-or-schema-lock-trying-to-write-over/m-p/1077545#M61686</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-11T01:30:49Z</dc:date>
    </item>
  </channel>
</rss>

