|
POST
|
The SelectByLocation process above only selects where the Trans_Lyr intersects the Sub_Lyr at a specified distance. If you need to get a count of Trans_Lyr features that are within a distance of each feature in the Sub_Lyr, you will have to put it inside of a loop. I think you should iterate through the Sub_Lyr features to make separate layers for each unique feature. This is the only way I know to do this: with arcpy.da.UpdateCursor ("subLayer_lyr", ["Line_Count"]) as LineCountList:
for subrow in LineCountList:
for i in IDs:
arcpy.MakeFeatureLayer_management(transLayer, "transLayer_lyr", """Unique_ID = '%s'""" %i)
arcpy.SelectLayerByLocation_management("transLayer_lyr", 'WITHIN_A_DISTANCE', "subLayer_lyr", .000002, "NEW_SELECTION")
result=int(arcpy.GetCount_management("transLayer_lyr").getOutput(0))
#print result
subrow[0] = result
LineCountList.updateRow(subrow)
arcpy.Delete("transLayer_lyr")
print "Line_Count Updated"
del LineCountList I apologize, I didn't quite understand the original question.
... View more
05-11-2017
07:16 AM
|
0
|
2
|
3787
|
|
POST
|
I would try not running it on the network to see if you get faster results. Also, try putting the result variable outside of the cursor/row loop. #MakeFeatureLayer
arcpy.MakeFeatureLayer_management(subLayer, "subLayer_lyr")
arcpy.MakeFeatureLayer_management(transLayer, "transLayer_lyr")
arcpy.SelectLayerByLocation_management("transLayer_lyr", 'WITHIN_A_DISTANCE', "subLayer_lyr", .000002, "NEW_SELECTION")
result=int(arcpy.GetCount_management("transLayer_lyr").getOutput(0))
arcpy.CalculateField_management("subLayer_lyr", "Line_Count", "%s" %result, "PYTHON_9.3", "")
##with arcpy.da.UpdateCursor ("subLayer_lyr", ["Line_Count"]) as LineCountList:
## for subrow in LineCountList:
## #print result
## subrow[0] = result
## LineCountList.updateRow(subrow)
##print "Line_Count Updated"
##del LineCountList Since, If I'm reading it correctly, you're only updating the 'Line_Count' field with a single value. And since the field is not dependent on other variables or exceptions, you can use the CalculateField tool... which will hopefully be quicker. Give that a try.
... View more
05-10-2017
01:01 PM
|
0
|
1
|
3787
|
|
POST
|
Try this, maybe: Remove the variable for the field, and just put it directly in the cursor: with arcpy.da.UpdateCursor (subLayer, ["LineCount", "SHAPE@"]) as LineCountList: Create a layer out of the Sub FC, then call it within the cursor? #MakeFeatureLayer
arcpy.MakeFeatureLayer_management(subLayer, "subLayer_lyr")
arcpy.MakeFeatureLayer_management(transLayer, "transLayer_lyr")
arcpy.SelectLayerByLocation_management("transLayer_lyr", 'WITHIN_A_DISTANCE', "subLayer_lyr", .000002, "NEW_SELECTION")
with arcpy.da.UpdateCursor ("subLayer_lyr", [TLineCountField, "SHAPE@"]) as LineCountList:
for subrow in LineCountList:
result=int(arcpy.GetCount_management("transLayer_lyr").getOutput(0))
#print result
subrow[0] = result
LineCountList.updateRow(subrow)
print "Line_Count Updated"
del LineCountList Lastly, you're not using the "SHAPE@" field within the cursor now, you can remove that field from the cursor. It's weird that this script is taking over 30 minutes to run... Is this is entire script?
... View more
05-10-2017
11:32 AM
|
0
|
3
|
3787
|
|
POST
|
It seems like there is a Null InspectionDate in row[1]. A SQL query can get around that: dateQry="""INSPDATE IS NOT NULL"""
#Loop through related table and store only the max date for each unique ID.
with arcpy.da.SearchCursor(relatedTblPath, relTblFields, dateQry) as cursor:
for row in cursor:
joinID = row[0]
if joinID not in dict_RelTbl.keys():
dict_RelTbl[joinID] = row
# if the key is in the dictionary already (one to many relationship), compare the dates and keep the most recent date
else:
curDate = dict_RelTbl[joinID][1]
if row[1] > curDate:
dict_RelTbl[joinID] = row
... View more
05-10-2017
06:30 AM
|
1
|
1
|
2792
|
|
POST
|
Once you have all the current dates in the Hydrants table, you can run something like this to check if any 'InspectionDate' values in the Hydrants table are less than those in the Inspection table. import arcpy
hydrants = r''
inspTable = r''
#set dictionary key:value pairs to FacilityID and the latest InspectionDate
dateDict = {}
with arcpy.da.SearchCursor(inspTable, ['FacilityID','InspectionDate']) as cursor:
for row in cursor:
key = row[0]
value = row[1]
if key not in dateDict:
dateDict[key]=value
elif value > dateDict[key]:
dateDict[key]=value
del cursor
#search Hydrants for FacilityIDs in dateDict and compare dates
with arcpy.da.UpdateCursor(hydrants, ['FacilityID','InspectionDate']) as cursor:
for row in cursor:
if row[0] in dateDict:
if row[1] < dateDict[row[0]]:
row[1] = dateDict[row[0]]
cursor.updateRow(row)
del cursor
... View more
05-09-2017
01:19 PM
|
2
|
4
|
2792
|
|
POST
|
Jay, I'm just getting more and more confused and I don't think I completely understand the original question. E-mail me if necessary mitchh300@gmail.com
... View more
05-05-2017
07:58 AM
|
0
|
1
|
629
|
|
POST
|
I agree with Neil. I don't like using layer selections inside of da.cursor loops. Also, nested da.cursor loops is probably making this script run slow. Try getting a layer selection, then running an update/search cursor on that selection.
... View more
05-05-2017
07:07 AM
|
1
|
5
|
3787
|
|
POST
|
ohhhhhh wait wait wait... You're calling 3 rows in the search cursor.. when you're only asking arcpy to search one row 'myField'. So, that'd be row[0] only... no row[1] or row[2].
... View more
05-05-2017
06:45 AM
|
0
|
5
|
1800
|
|
POST
|
Try this on lines 30 - 35: #with arcpy.da.SearchCursor(myLayer, ['CreationDate', 'additionalcomments'], dateQry) as cursor:
with arcpy.da.SearchCursor(fc, myField1, dateQry) as cursor:
for row in cursor:
print(row)
CreatevalDate = (str(row[0]),str(row[1]),str(row[2]))
notInspected.append(CreatevalDate)
del cursor That will make each item in the list a tuple. If you want each item in the list to be a string, do that following (ugly way). #with arcpy.da.SearchCursor(myLayer, ['CreationDate', 'additionalcomments'], dateQry) as cursor:
with arcpy.da.SearchCursor(fc, myField1, dateQry) as cursor:
for row in cursor:
print(row)
notInspected.append(str(row[0])+','+str(row[1])+','+str(row[2]))
del cursor *Note: don't forget to delete the cursors
... View more
05-05-2017
06:43 AM
|
1
|
6
|
1800
|
|
POST
|
Jay, My apologies, try this: dateQry="""CreationDate < date{}""".format(month_ago) This will return values that are less than a month ago.
... View more
05-05-2017
05:58 AM
|
0
|
8
|
1800
|
|
POST
|
Jay, You can add a SQL Expression inside a da.cursor loop. Example: notInspected = []
dateQry="""InspectionDate > date%s AND InspectionDate < date%s"""%month_ago %today
with arcpy.da.SearchCursor(myLayer, ['myField'], dateQry) as cursor:
...do something...
Depending on what type of database you're using and what field type the date is stored in, the SQL syntax will change. See here: SQL reference | ArcGIS Desktop
... View more
05-04-2017
12:39 PM
|
0
|
11
|
1800
|
|
POST
|
The issue we're having is only a single date is being recorded in the 'last_edited_date' & 'created_date' fields for Editor Tracking when the data is being synced back to the server (see below). When in reality, the field is editing features about every 5-10 minutes. Editor Tracking is enabled on every FC and table in the enterprise geodatabase, and UTC time is being recorded. Is there a way to change this? We're using Feature Services with ArcGIS Collector for disconnected editing. We recently started using ArcServer 10.5 and SQL Server 2016. The enterprise geodatabase is 10.5 as well.
... View more
05-02-2017
10:29 AM
|
0
|
6
|
2737
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-28-2024 11:43 AM | |
| 1 | 09-12-2025 07:32 AM | |
| 1 | 10-26-2018 06:50 AM | |
| 1 | 10-26-2018 08:43 AM | |
| 1 | 02-25-2016 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
12-02-2025
01:10 PM
|