|
POST
|
Hi guys, I was doing a test. Created a simple script that creates 3 blank FCs in a FGDB then delete them right after. I made these short codes to loop several times within the same FGDB and at some point, the schema lock or workspace read only error appeared. Here is the simple script I was running,
import arcpy
filenames = ['data1', 'data2', 'data3']
def createFiles():
for filename in filenames:
print 'Creating '+filename
arcpy.CreateFeatureclass_management(r'C:\TEMP\Dump\TEST.gdb', filename, 'POINT', '', '', '', '')
del filename
def deleteFiles():
arcpy.env.workspace = r'C:\TEMP\Dump\TEST.gdb'
lyrs = arcpy.ListFeatureClasses()
for lyr in lyrs:
print 'Deleting '+lyr
arcpy.Delete_management(lyr, '')
del lyr, lyrs
def runTimes(runNum):
createFiles()
deleteFiles()
x = 0
while x != 100:
print 'Run'+str(x)
runTimes(x)
x += 1
We are actually running a custom tool my colleague developed from python to run data extraction from a SQL database and do a few geoprocessing on data like nearest neighbor interpolation, creating of feature classes and raster datasets, mosaicking and deleting of such files within a single FGDB. And it runs well but most of the time fails due to workspace is read only or schema locks on a feature that prevents creation or deletion of featureclasses. So I was thinking just to simulate that process, well, my simple script does look a bit crude, but my goal was just to see if the FGDB will lock up again, and it did. Maybe you could shed a light more on why workspaces behave like this.
... View more
06-17-2013
09:37 AM
|
0
|
0
|
297
|
|
POST
|
Or you could look into functions like RasterToNumPyArray(arcpy).
... View more
06-06-2013
03:56 PM
|
0
|
0
|
416
|
|
POST
|
Yup you need to use setValue since using line.Field makes the program think there is an actual fieldname "Field"
... View more
06-06-2013
02:04 PM
|
0
|
0
|
835
|
|
POST
|
Hi, You could just probably add a new input parameter:
inputFields = arcpy.GetParameterAsText(4)
Then from the script properties, in the parameters tab, set it to type "field", multiple input and indicate the source layer to get the fields from. You'll get a list of field names with checkboxes and any fieldname you check will be your input.
Cheers
I've written a code that selects attributes one by one. As each attribute is selected a select by location is performed to identify how many records in the select by location file intersect with the selected record from the select by attributes query. The number of records that intersect the selected attribute are recorded to the attribute table. The script works if the field to be updated is hardcodded into the script. I want to be able to pick what field gets to be updated each time the script is run. Is this possible?
import arcpy, os
arcpy.env.workspace = "C:/Temp" #arcpy.GetParameterAsText(0)
arcpy.env.overwriteOutput = True
outputWorkspace = "C:/Temp/Scratch" #arcpy.GetParameterAsText(1)
def outName(input,post="_Output"):
"""Returns output name."""
outName=os.path.basename(input).split(".")[0]+post
return outName
Attribute = "Parcel_Test.shp" #arcpy.GetParameterAsText(2)
Location = "Test_Wetlands.shp" #arcpy.GetParameterAsText(3)
#Get Count of the number of records for the file needing to be updated.
#This count will be automatically plugged into a range value needed to write results from the analysis to the output shapefile.
RangeCount = int(arcpy.GetCount_management(Attribute).getOutput(0))
print "There are", RangeCount, "records that need to be updated"
arcpy.AddMessage("There are "+str(RangeCount)+" that need to be updated\n")
#Create Features Layers from Feature Classes
AttributeFL=outName(Attribute,"_Layer")
LocationFL=outName(Location,"_Layer")
arcpy.MakeFeatureLayer_management(Attribute,AttributeFL)
arcpy.MakeFeatureLayer_management(Location, LocationFL)
#Begin Update
print "\nUpdating file with the number of records that intersect with each attribute"
arcpy.AddMessage("Updating file with the number of records that intersect with each attribute\n")
for attribute in range(0,RangeCount):
FID = "FID=%s" % (attribute)
arcpy.SelectLayerByAttribute_management(AttributeFL,"NEW_SELECTION",FID)
arcpy.SelectLayerByLocation_management(LocationFL,"INTERSECT",AttributeFL)
LocationCount = int(arcpy.GetCount_management(LocationFL).getOutput(0))
arcpy.AddMessage(str(FID)+" has "+str(LocationCount)+" records that intersect with it.")
print str(FID), "has", LocationCount, "records that intersect with it."
#Update the three_mi field
uc=arcpy.UpdateCursor(AttributeFL)
for line in uc:
line.count = LocationCount
uc.updateRow(line) #Actually changes the table values to buffer count
del line
del uc
arcpy.SelectLayerByAttribute_management(AttributeFL,"CLEAR_SELECTION")
arcpy.AddMessage(Attribute+" has been updated\n")
print Attribute, "has been updated\n"
... View more
06-06-2013
01:14 PM
|
0
|
0
|
835
|
|
POST
|
why is your cellsize in quotes? i got the this error message. what's wrong to me? Traceback (most recent call last): File "C:/Users/Administrator/Desktop/arcpy/convert", line 36, in <module> saveRaster = arcpy.PointToRaster_conversion( filename2, "RASTERVALU", outRaster2, "MOST_FREQUENT", "NONE", cellSize) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1772, in PointToRaster raise e ExecuteError: ERROR 999999: Error executing function. Failed to execute (PointToRaster).
# Import arcpy module
import arcpy, os
from arcpy import env
from arcpy.sa import *
# Set environment settings
arcpy.env.workspace = "C:/py2/extract"
arcpy.env.overwriteOutput = True
OutputFolder2 = "C:/py2/result"
# Loop through a list of files in the workspace
RasterFiles2 = arcpy.ListFeatureClasses()
print "POINT TO RASTER"
print RasterFiles2
print " "
# Set local variables
for filename2 in RasterFiles2:
print "Processing: {0}".format(filename2)
outRaster2 = os.path.join(OutputFolder2, filename2 + "_4x")
valField = "RASTERVALU"
assignmentType = "MOST_FREQUENT"
priorityField = "NONE"
cellSize = "0.035714286"
# Execute ExtractValuesToPoints
saveRaster = arcpy.PointToRaster_conversion( filename2, valField, outRaster2, assignmentType, priorityField, cellSize)
print "done "
print arcpy.GetMessages()
... View more
05-15-2013
05:20 PM
|
0
|
0
|
1301
|
|
POST
|
Could you post your code for the python toolbox? Now having an identical error, yet no GitHub merge conflict text. Even turned on SublimeLinter in SublimeText2 to try and find errors, and came up with nothing. If these are not syntax errors, and are in fact logic errors, why does the .pyt shut down completely and not let me run through the logic of the tool and experience the error myself? Currently, the .pyt has a big red X and tells me "no syntax errors". Any help?
... View more
05-14-2013
07:12 PM
|
0
|
0
|
1676
|
|
POST
|
cant you just use Dissolve it using owners name attribute and just indicate multipart output. Or is there anyway that I can view the source code of dissolve or merge process tool?
... View more
05-08-2013
06:38 PM
|
0
|
0
|
589
|
|
POST
|
Hi Tom, Since you can calculate the difference from your tables to get the total number of residents as a new column. Cant you just use graduated symbols or even colors to show positive and negative differences. Hi I'll will find out the difference in population between year 2000 and 2013. I have a feature class file with the population in year 2000 and 2013 that are connected to the municipal number and that is a point theme. What I want is to have is a buffer zones around each point and the size of the buffer zone is determined by the number of residents that each point has. I the population has increased the buffer zone will get a red color and where the population has decreased the buffer zone is will be blue. Is there anyone who can help me with this? Whether as a model in the Model Builder, Python or toolbox. Thank you in advance Tom Anders
... View more
05-02-2013
07:09 PM
|
0
|
0
|
357
|
|
POST
|
if you were only using these codes here, there shouldn't be any issues. import arcpy, os
mxd = arcpy.mapping.MapDocument(r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.mxd")
arcpy.mapping.ExportToPDF(mxd, r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf")
del mxd
... View more
05-01-2013
03:37 PM
|
0
|
0
|
3149
|
|
POST
|
I think you should post your entire code if possible. Seems your incorrectly declaring variables and parameters based on your errors. i.e your range is wrong having 3 values in it. ## for pgNumLeft in range(1, tempDDPLeft.pageCount + 1, 2):
... View more
04-30-2013
07:29 PM
|
0
|
0
|
3149
|
|
POST
|
Hi there, That searchCursor is for 10.1 version by the way. If you just wanted to print out the values,
cur = arcpy.da.SearchCursor(fc, ['FIELDNAME',])
for i in cur:
print i[0]
Did you want to create a list containing the values of that column?
valueList = list(i[0] for i in arcpy.da.SearchCursor(fc, ['FIELDNAME',]))
... View more
04-30-2013
06:37 PM
|
0
|
0
|
648
|
|
POST
|
Did you want to create a list containing the values of that column?
valueList = list(i[0] for i in arcpy.da.SearchCursor(fc, ['FIELDNAME',]))
HI, I wanna list number in the column of OBJECTID_1, see the picture. I wrote it like this : for row in arcpy.SearchCursor(fc): print"%f" %row.getValue("OBJECTID_1") what is wrong? Thanks [ATTACH=CONFIG]23892[/ATTACH]
... View more
04-30-2013
06:30 PM
|
0
|
0
|
648
|
|
POST
|
Hi Scott, I think you can just opt to create a LYR file for raster with correct symbology then just change datasource manually or thru python. Cheers, Chris P
... View more
03-29-2013
02:43 PM
|
0
|
0
|
737
|
|
POST
|
Maybe you should try, expression = !field! + ", " + str(parameter) Hi, I am trying to concatonate an existing field with a parameter in a python script parameter = 4 expression = !field! + ", " + parameter arcpy.management.CalculateField("testshp", "field", expression, "PYTHON") my field is a text field with a value of "1, 2, 3" and i want to make it "1, 2, 3, 4" where everytime the script runs and the user inputs a number it adds a comma, a space, then the parameter. I keep running into issues with combining a string and an int but the parameter is preset to string. Any ideas? Thanks.
... View more
03-10-2013
07:14 PM
|
0
|
0
|
681
|
|
POST
|
Have you tried reading about data driven pages? it has a toolbar in Arcmap and at the same time you can use scripts to further customize it. Cheers.
... View more
02-09-2013
10:58 PM
|
0
|
0
|
655
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-23-2014 12:00 PM | |
| 1 | 01-23-2013 05:05 PM | |
| 1 | 02-13-2018 05:55 PM | |
| 1 | 07-04-2017 02:01 PM | |
| 1 | 08-02-2017 01:57 AM |