|
POST
|
Try deleting the row and cursor within the 'try' statement and you should no longer get this error: try:
#update table with difference value
with arcpy.da.UpdateCursor(table, ["FEAT_SEQ", "YEAR_OF_BIRTH", "DIFFERENCE"], "FEAT_SEQ = " + str(FEAT_SEQ) + AND ("YEAR_OF_BIRTH = " + str(list2[0]) + " OR YEAR_OF_BIRTH = " + str(list2[1]))) as cursor:
for row in cursor:
row[2] = DIFFERENCE
cursor.updateRow(row)
del row, cursor
except:
pass
... View more
10-28-2013
03:09 AM
|
0
|
0
|
2165
|
|
POST
|
I don't believe that will improve performance. Is there a reason you are not indexing the sample feature class?
... View more
10-25-2013
12:15 PM
|
0
|
0
|
3026
|
|
POST
|
Here is the updated code that should work: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
table = "data"
# create empyt list to append ID field
list = []
# iterate through table and append ID to list
with arcpy.da.SearchCursor(table, ["id"]) as cursor:
for row in cursor:
list.append(row[0])
del row, cursor
#remove duplicate IDs
list = dict.fromkeys(list)
list = list.keys()
#iterate through list
for id in list:
list2 = []
with arcpy.da.SearchCursor(table, ["id", "age", "difference"], "id = " + str(id)) as cursor:
for row in cursor:
#append age to new list
list2.append(row[1])
#sort list
list2.sort()
try:
#calculate the difference
difference = list2[1] - list2[0]
except:
difference = ''
del row, cursor
try:
#update table with difference value
with arcpy.da.UpdateCursor(table, ["id", "age", "difference"], "age = " + str(list2[0]) + " AND id = " + str(id)) as cursor:
for row in cursor:
row[2] = difference
cursor.updateRow(row)
except:
pass
del row, cursor Here is an explanation of the where clauses. 1. "id = " + str(id) "id" is the field name and 'str(id)' is the variable for the id value in the list. The line 'for id in list' is setting this variable. 2. "age = " + str(list2[0]) + " AND id = " + str(id)) This query is selecting the age field that is equal to the first value in the second list. In this case, the first value is the largest year from today's data, (i.e. 1955). If you have the year 1955 in two different 'ids', the AND is ensuring that the update will update the correct row.
... View more
10-25-2013
11:39 AM
|
0
|
0
|
3026
|
|
POST
|
Just so I understand you correctly. In your example: ID AGE NEWID DIFFERENCE 2259 1955 22591955 n/a 2259 1956 22591956 1 2259 1986 22591986 n/a 2259 1989 22591989 n/a The 'Difference' value is not being calculated between 1986 and 1989 because the age from 1955 and 1956 is larger when compared to todays date. Is that correct?
... View more
10-25-2013
11:24 AM
|
0
|
0
|
3026
|
|
POST
|
Hi Clinton, Here is an example on how you can do this: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
table = "data"
# create empyt list to append ID field
list = []
# iterate through table and append ID to list
with arcpy.da.SearchCursor(table, ["id"]) as cursor:
for row in cursor:
list.append(row[0])
del row, cursor
#remove duplicate IDs
list = dict.fromkeys(list)
list = list.keys()
#iterate through list
for id in list:
list2 = []
with arcpy.da.SearchCursor(table, ["id", "age", "difference"], "id = " + str(id)) as cursor:
for row in cursor:
#append age to new list
list2.append(row[1])
#sort list
list2.sort()
try:
#calculate the difference
difference = list2[-1] - list2[-2]
except:
pass
del row, cursor
try:
#update table with difference value
with arcpy.da.UpdateCursor(table, ["id", "age", "difference"], "age = " + str(list2[-2]) + " AND id = " + str(id)) as cursor:
for row in cursor:
row[2] = difference
cursor.updateRow(row)
except:
pass
del row, cursor
... View more
10-25-2013
10:01 AM
|
0
|
0
|
3026
|
|
POST
|
Hi Anthony, In the catalog tree, right-click on the mosaic dataset > Properties > Feature Extent tab. You can click 'Recalculate' or manually set the extent.
... View more
10-25-2013
03:57 AM
|
1
|
0
|
1217
|
|
POST
|
Hi Nick, What version of ArcGIS Desktop are you using? I could not reproduce this with 10.2. Have you tried simply import the table outside of a script? For example, right-click on the File Geodatabase > Import > Table (single).
... View more
10-25-2013
03:14 AM
|
0
|
0
|
1351
|
|
POST
|
Hi Shane, The SearchCursor will work on the selection created from the Select by Location. Try the following: def onClick(self): self.mxd = arcpy.mapping.MapDocument('current') layers = arcpy.mapping.ListLayers(self.mxd) self.items = [] for layer in layers: if layer.name.lower() == "parks": hydLayer = layer print hydLayer df = arcpy.mapping.ListDataFrames(self.mxd)[0] extent = str(df.extent) print extent dfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]), df.spatialReference) arcpy.SelectLayerByLocation_management(hydLayer, "INTERSECT", dfAsFeature, "", "NEW_SELECTION") global labels labels = [] with arcpy.da.SearchCursor(hydLayer, ["NAME"]) as cursor: for row in cursor: labels.append(row[0]) del cursor, row You will need to change "NAME" to the label field. Then, you can then pass the global labels variable to the 'onFocus' function of the combo box: def onFocus(self, focused): self.items = labels Note: the arcpy.da.SearchCursor can only be used for 10.1 and beyond. If you are using 10.0 you will need to use: rows = arcpy.SearchCursor(hydLayer, "", "", "NAME") for row in rows: labels.append(row.NAME) del row, rows
... View more
10-25-2013
03:03 AM
|
0
|
0
|
995
|
|
POST
|
Hi Ryan, You could probably accomplish this easier with python. Here is an example: import arcpy
from arcpy import env
# set workspace where shapefiles are located
env.workspace = r"C:\data\temp\python"
# create empty list
list = []
# append each shapefile in workspace to list
for shapefile in arcpy.ListFeatureClasses("*.shp"):
list.append(shapefile)
# import list of shapefiles into File Geodatabase feature dataset
arcpy.FeatureClassToGeodatabase_conversion(list, r"C:\Temp\Python\Redlands.gdb\Data")
# set workspace to File Geodatabase
env.workspace = r"C:\Temp\Python\Redlands.gdb"
# loop through each feature class in 'Data' feature dataset and add fields
for fc in arcpy.ListFeatureClasses("*", "", "Data"):
arcpy.AddField_management(fc, "SHEET_NAME", "TEXT", "", "", "50")
arcpy.AddField_management(fc, "ENGINEER", "TEXT", "", "", "100")
arcpy.AddField_management(fc, "PROJECT_NO", "TEXT", "", "", "50")
arcpy.AddField_management(fc, "SHEET_NO", "TEXT", "", "", "50")
arcpy.AddField_management(fc, "DATE", "TEXT", "", "", "50")
... View more
10-24-2013
12:26 PM
|
1
|
0
|
583
|
|
POST
|
These do not show up in my registry? Under HKEY_USERS, "esri" isn't an option, and in HKEY_CURRENT_USERS, "Server10.1" isn't an option. I know that it is installed on the machine, I am using it (and it shows up in the HKEY_LOCATION_MACHINE tree). We are using Windows 2008 R2 Standard, for whatever that's worth... Any thoughts? Make sure you are logged on as the arcgis server account user.
... View more
09-23-2013
12:32 PM
|
0
|
0
|
4879
|
|
POST
|
Hi Rachel, You can do this using the Con tool as you suspected. Here is an example on how to iterate through rasters in a directory and change all values less than 1 in each raster to a value of 0: import arcpy from arcpy import env env.workspace = r"C:\temp\python" arcpy.CheckOutExtension("spatial") for raster in arcpy.ListRasters("*"): arcpy.gp.Con_sa(raster, "0", raster + "_con.tif", raster, '"VALUE" < 1')
... View more
09-23-2013
11:12 AM
|
0
|
0
|
1026
|
|
POST
|
You can iterate through the first folder and then iterate through the second folder, find the table name that contains the name of the file from the first folder, and then perform the comparison. Here's an example: import arcpy, os
from arcpy import env
folder1 = r"C:\temp\python\A"
folder2 = r"C:\temp\python\B"
env.workspace = folder1
for file in arcpy.ListFiles("*.csv"):
fileName = file.split(".")[0]
env.workspace = folder2
for file2 in arcpy.ListFiles("*.csv"):
if fileName in file2:
arcpy.FileCompare_management(folder1 + os.sep + file, file2, "ASCII", "CONTINUE_COMPARE", r"C:\Temp\Python" + os.sep + fileName + "_compare.txt")
env.workspace = folder1
... View more
09-23-2013
05:52 AM
|
0
|
0
|
4675
|
|
POST
|
Hi Ahmed, Try using the 'Select Layer by Attribute' and then the 'Feature Class to Feature Class' function. Ex: wClause = '"Layer" = \'line2\'' arcpy.SelectLayerByAttribute_management("alignment.dwg Polyline", "NEW_SELECTION", wClause) arcpy.FeatureClassToFeatureClass_conversion("alignment.dwg Polyline", r"F:\Projects\New File Geodatabase.gdb", "Line2")
... View more
09-17-2013
02:49 AM
|
0
|
0
|
1279
|
|
POST
|
Hi Kaitlynn, Try adding arcpy.RefreshActiveView() at the end of your code.
... View more
09-10-2013
10:41 AM
|
0
|
0
|
1503
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a month ago | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Online
|
| Date Last Visited |
59m ago
|