<?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: Trying to get raster extents into a GDB using open cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214447#M67769</link>
    <description>&lt;P&gt;That is a lot of code for someone to try to figure out all the indents, etc.&lt;/P&gt;&lt;P&gt;Might get more responses if you edit the post and paste the code in using the code formatter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_0-1663715689201.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51706i778CAF5BBD7B37FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_0-1663715689201.png" alt="RhettZufelt_0-1663715689201.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_1-1663715699942.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51707i710B0CAF0733011B/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_1-1663715699942.png" alt="RhettZufelt_1-1663715699942.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2022 23:16:09 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2022-09-20T23:16:09Z</dc:date>
    <item>
      <title>Trying to get raster extents into a GDB using open cursor</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214402#M67768</link>
      <description>&lt;P&gt;Hello, I am fairly new to py programming and have 1/2 copy pasted this and 1/2 developed this to meet my requirements.&amp;nbsp; Most of the script is successful, but the cursor seems to stall after the first record is inserted.&amp;nbsp; I have added all of the code, just in case some of the set up is the problem...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;try:
    import sys, traceback, os
    import arcpy
    arcpy.env.overwriteOutput = True
    
    #inDir = arcpy.GetParameterAsText(0)
    inDir = "Q:\\CCR\\1.Alexis Creek Flights\\"
    #outFile = arcpy.GetParameterAsText(1)
    outFile = "Q:\\EntireQDrive.gdb"
    print "In Dir: " + (inDir)
    print "Out File: " + (outFile)
    print "dirname: " + os.path.dirname(outFile)
    print "basename: " + os.path.basename(outFile)
    FileName = os.path.dirname(outFile) + os.path.basename(outFile)
    print "filename: " + (FileName)
    arcpy.env.workspace = FileName
    
    feature_classes = []
    walk = arcpy.da.Walk(inDir, datatype="RasterDataset", type="All")
    
    for dirpath, dirnames, filenames in walk:
        for filename in filenames:
            #print (dirpath)
            #print (filenames)
            feature_classes.append(os.path.join(dirpath, filename))

    arcpy.CreateFeatureclass_management(FileName,"CCR", "POLYGON")
    print ("Created FC")
    
    fieldName1 = "RasterName"
    fieldLength1 = 100
    fieldName2 = "RasterPath"
    fieldLength2 = 250
    arcpy.AddField_management("CCR", fieldName1, "TEXT", fieldLength1)
    arcpy.AddField_management("CCR", fieldName2, "TEXT", fieldLength2)
    print ("Added Field")
    
    cursor = arcpy.InsertCursor("CCR")
    point = arcpy.Point()
    array = arcpy.Array()
    corners = ["lowerLeft", "lowerRight", "upperRight", "upperLeft"]

    #print (feature_classes)
    for Ras in feature_classes:
        print(Ras)
        feat = cursor.newRow()  
        r = arcpy.Raster(Ras)
        for corner in corners:    
            point.X = getattr(r.extent, "%s" % corner).X
            point.Y = getattr(r.extent, "%s" % corner).Y
            array.add(point)
        array.add(array.getObject(0))
        polygon = arcpy.Polygon(array)
        feat.shape = polygon
        feat.setValue("RasterName", Ras.split('\\')[-1])
        feat.setValue("RasterPath", Ras)
        cursor.insertRow(feat)
        array.removeAll()
    del feat
    del cursor  
    
    print ("")
    print ("All Done :)")

    
except arcpy.ExecuteError: 
    msgs = arcpy.GetMessages(2) 
    arcpy.AddError(msgs) 
    print msgs
except:
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)
    print pymsg + "\n"
    print msgs&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:25:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214402#M67768</guid>
      <dc:creator>LeonConsus</dc:creator>
      <dc:date>2022-09-21T14:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get raster extents into a GDB using open cursor</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214447#M67769</link>
      <description>&lt;P&gt;That is a lot of code for someone to try to figure out all the indents, etc.&lt;/P&gt;&lt;P&gt;Might get more responses if you edit the post and paste the code in using the code formatter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_0-1663715689201.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51706i778CAF5BBD7B37FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_0-1663715689201.png" alt="RhettZufelt_0-1663715689201.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_1-1663715699942.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51707i710B0CAF0733011B/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_1-1663715699942.png" alt="RhettZufelt_1-1663715699942.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 23:16:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214447#M67769</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-20T23:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get raster extents into a GDB using open cursor</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214620#M67770</link>
      <description>&lt;P&gt;Thanks Rhett, missed that in my original post.&amp;nbsp; It has now been updated &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:24:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-get-raster-extents-into-a-gdb-using-open/m-p/1214620#M67770</guid>
      <dc:creator>LeonConsus</dc:creator>
      <dc:date>2022-09-21T14:24:35Z</dc:date>
    </item>
  </channel>
</rss>

