<?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: Python code optimization - licence checkout? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203811#M6972</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Yes, also UNC pathnames (as opposed to mapped drive letters) are ALWAYS the way to go...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I wonder why that is? I got into the habit of doing this as a number of programs don't recognize relative paths, and so I could switch the drive letter to, for example, an external hard drive or network project depending on what I was working on (collaborating with others) - unfortunate that this has such performance hindrances, but at least I know now. Shapefiles are importing at a rate of 1 per 2-3 seconds now, instead of 1 per 1.5 minutes. (!) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Re: setproduct(), the documentation lists using "import arcinfo" before "import arcpy" as an alternate (legacy) way of doing this. Do you have a preference / notice a difference? Thanks again,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Nov 2010 22:26:56 GMT</pubDate>
    <dc:creator>MattRosales</dc:creator>
    <dc:date>2010-11-22T22:26:56Z</dc:date>
    <item>
      <title>Python code optimization - licence checkout?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203807#M6968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the following script running on roughly 15gb of shapefiles, with the purpose of importing them into a geodatabase. I had previously tried this by finding all of the shapefiles first, and passing them to "Feature class to Feature class" as one block, however it overloaded the tool. This version uses a loop to import them to the geodatabase one-by-one. In this way, the code is stable, and has successfully processed a few thousand shapefiles already, however I am convinced that the process is taking much longer than it should. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, the code takes about 35-40 seconds just to check if the feature class already exists in the geodatabase. This is far, far too long, and I suspect it has something to do with checking out the arcInfo license each time it uses an arcpy function. Does anyone have ideas about increasing the speed and efficiency? I was considering trying something like &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003w000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;this&lt;/A&gt;&lt;SPAN&gt;, but the documentation says it is legacy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the brainstorming,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(I run this code through a normal python console, not the one in arc for stability reasons)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Import system modules
import sys, string, os, fnmatch, arcpy
from arcpy import env

### Set user variables here, if no user-input desired: ###
searchPath = os.path.abspath("/path/to/data") #path to search
searchParam = "*.shp" #search parameter - wildcards OK
shapefileType = "Polyline" #shapefile type: Polyline, Polygon, Point, etc.
OutputDatabase = os.path.abspath("/path/to/output.gdb")
### End user variables ###

### Check and print the input parameters ###
if os.path.isdir(searchPath):
&amp;nbsp;&amp;nbsp; print "Search: " + searchPath + " OK"
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print searchPath + "\n is not a valid path!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; sys.exit(0)

print "Searching for " + searchParam
print "shapefileType = " + shapefileType

if arcpy.Exists(OutputDatabase): # verify that output database exists. 
&amp;nbsp;&amp;nbsp; print "OutputDatabase = " + OutputDatabase + "&amp;nbsp; OK..."
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print searchPath + "\n is not valid"
&amp;nbsp;&amp;nbsp;&amp;nbsp; sys.exit(0)
### End variable check ###
 
env.workspace = OutputDatabase # set the current workspace as the target database.
env.overwriteOutput = True 

# Search function
resultList = [] #The list for collecting results with

for root, dirs, files in os.walk(searchPath): # crawl through the search directory
 for f in files: # for each file in the search directory
&amp;nbsp; if fnmatch.fnmatch(f, searchParam): # check if the filename matches
&amp;nbsp;&amp;nbsp; shpDescr = arcpy.Describe(os.path.join(root, f)) # reads the shapefile
&amp;nbsp;&amp;nbsp; shpType = shpDescr.shapeType # reads the shapefile type
&amp;nbsp;&amp;nbsp; if str(shpType) == shapefileType: # check if the shapefile type matches
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFeatureClass = arcpy.ValidateTableName("cont"+f.replace(".shp",""), OutputDatabase) # generates a database-friendly fieldclass name
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(outFeatureClass): # check to see if already imported
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print os.path.join(root, f) + " already imported as " + outFeatureClass 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exporting " + f + " to " + outFeatureClass + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(os.path.join(root, f), OutputDatabase, outFeatureClass) #export to geodatabase
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except: # error handling
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Error with " + os.path.join(root, f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for msg in range(0, arcpy.GetMessageCount()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.GetSeverity(msg) == 2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddReturnMessage(msg)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempString = "'" + os.path.join(root, f) + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; resultList.append(tempString)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; resultList.append(";")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue
&amp;nbsp;&amp;nbsp;&amp;nbsp; 

if not resultList: # only runs the next lines if there were problems with some of the files.
 resultList.pop() #removes last list value (trailing semicolon)
 resultString = "\"" + "".join(resultList) + "\"" #Convert list to a single string
 outFilesMV = resultString.replace("\\","\\\\")

 # Outputs a list of problem files in the searchPath directory:
 outputFilename = searchPath + "/ImportErrors.txt"
 fu = open(os.path.abspath(outputFilename), 'w')
 fu.write(outFilesMV)
 fu.close()

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:07:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203807#M6968</guid>
      <dc:creator>MattRosales</dc:creator>
      <dc:date>2021-12-11T10:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python code optimization - licence checkout?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203808#M6969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Update - I previously had the code pointing to a locally mapped network drive (IE mapped as 127.0.0.1/some/directory as the letter W: so that I didn't have to type in a long directory name each time. I changed this to the full path directory from C: and had 1000% performance improvement, for whatever reason, making each shapefile import in a matter of seconds. Wow! So, looks like the issue wasn't with the code, but rather with some sort of windows networking performance in stead?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Nov 2010 22:18:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203808#M6969</guid>
      <dc:creator>MattRosales</dc:creator>
      <dc:date>2010-11-22T22:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python code optimization - licence checkout?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203809#M6970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Definitely use setproduct(). In v9.x I found this to be a pretty critical step...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are moving from .shp to FGDB format, you probably won't have any schema issues, and therefore probably don't need the arcpy.Validate thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you aren't changing the schema around, you might consider just using the CopyFeatures tool (instead of FeatureClassToFeatureClass). It should be a little easier/faster.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Nov 2010 22:21:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203809#M6970</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-11-22T22:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python code optimization - licence checkout?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203810#M6971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, also UNC pathnames (as opposed to mapped drive letters) are ALWAYS the way to go...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Nov 2010 22:23:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203810#M6971</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-11-22T22:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python code optimization - licence checkout?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203811#M6972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Yes, also UNC pathnames (as opposed to mapped drive letters) are ALWAYS the way to go...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I wonder why that is? I got into the habit of doing this as a number of programs don't recognize relative paths, and so I could switch the drive letter to, for example, an external hard drive or network project depending on what I was working on (collaborating with others) - unfortunate that this has such performance hindrances, but at least I know now. Shapefiles are importing at a rate of 1 per 2-3 seconds now, instead of 1 per 1.5 minutes. (!) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Re: setproduct(), the documentation lists using "import arcinfo" before "import arcpy" as an alternate (legacy) way of doing this. Do you have a preference / notice a difference? Thanks again,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Nov 2010 22:26:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203811#M6972</guid>
      <dc:creator>MattRosales</dc:creator>
      <dc:date>2010-11-22T22:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python code optimization - licence checkout?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203812#M6973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure why UNC is faster, just something I got into the habit of doing a long time ago. I have a pet peeve against using network drive letters (The S:\ drive?!?! I don't have an S:\ drive, what the hell is that? Oh you mean \\snarf\am\div_lm\ds?, well why didn't you say so!?!). Pet peeve... Anyway...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Setting the license level is also another thing I got into the habit of doing. Like the UNC path thing, I'm not really sure why, just something i started doing, and my scripts always seem to run fine (minus other stuff :)). Here's some v9.3 code that checks out the highest level license (given ArcInfo, ArcEditor, or ArcView):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if gp.CheckProduct("ArcInfo") == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetProduct("ArcInfo")
elif gp.CheckProduct("ArcEditor") == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetProduct("ArcEditor")
elif gp.CheckProduct("ArcView") == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetProduct("ArcView")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; messsage =&amp;nbsp; "ERROR: Can't specify ArcGIS license level... Exiting script!"; showPyMessage(); sys.exit()
message =&amp;nbsp; "Selected an " + gp.ProductInfo() + " license"; showPyMessage()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-code-optimization-licence-checkout/m-p/203812#M6973</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T10:07:15Z</dc:date>
    </item>
  </channel>
</rss>

