|
POST
|
Check the syntax of Clip: it appears that your clipOutput variable is set to a geodatabase and not a feature class.
... View more
10-22-2020
10:43 AM
|
1
|
2
|
6419
|
|
POST
|
Here is what your code looks like when you use the syntax highlighter: def DetermineType(Lanes, Speed):
if Lanes.rstrip() == "1" and int(Speed.rstrip()) < 30:
return 1
elif Lanes.rstrip() == "2" and int(Speed.rstrip()) < 30:
return 2
elif Lanes.rstrip() == "3" and int(Speed.rstrip()) > 30:
return 3
else:
return 4 You need to check for the <Null> values specifically with: ...
elif Lanes.rstrip() is None:
do what you need to do...
... View more
10-22-2020
09:59 AM
|
0
|
3
|
2776
|
|
POST
|
Here's a post of mine that describes some address parsing I have done in the past. Joshua Bixby provides a link to one of the parsing libraries he alludes to above
... View more
10-22-2020
08:07 AM
|
1
|
0
|
1897
|
|
POST
|
Perhaps you could post some of your actual data. Those variable values are really tough to standardise.
... View more
10-21-2020
07:45 PM
|
0
|
0
|
1897
|
|
POST
|
Potentially, you could lose your mind trying to figure out how many combinations of address, city and state your data has. Just sayin'... But if you want the last n characters of a string you'd use: myString = 'Some Street and City State'
myString[-5:]
#returns State
... View more
10-21-2020
02:46 PM
|
1
|
3
|
1897
|
|
POST
|
I asked around and there is no 'button to click' to execute an attribute rule on demand. What was shown me was essentially the same thing I mention above: select a record and simply run a field calculation on the field with the rule and it will fire.
... View more
10-21-2020
01:36 PM
|
0
|
0
|
7455
|
|
POST
|
Not exactly: these rules are specifically set up to fire when a feature is either added or modified so they fall in the class of Immediate Calculations. Basically all the features are already in the feature class and I added a couple of fields; I wrote the rules just to get some practice; I could have just used the field calculator, but where is the fun in that?
... View more
10-20-2020
03:15 PM
|
0
|
1
|
7455
|
|
POST
|
I think someone one showed me how to do this, but I just can't remember. Here is my scenario: I have an existing feature class to which I added a couple of fields. Those fields are to be populated as a concatenation of some other field values. What I did to run them manually was first set them for insert and modify. Then I selected all the features, and in one of the fields I have the new concatenation rules set, I simple hit the space bar while in the selected attributes pane. That's enough for a modification so both rules fired and I'm good to go. However, that's sort of a hack; I thought there is a way to execute a rule manually without even making a phony modification.
... View more
10-20-2020
01:56 PM
|
0
|
9
|
7492
|
|
POST
|
That's a good plan- it's not going anywhere and using a search cursor to trouble shoot you update cursor is good too.
... View more
10-20-2020
01:21 PM
|
0
|
0
|
5504
|
|
POST
|
OID is coming in from the CSV as text and not an integer.... That's the sort of thing you can check by running each segment of code a priori in the console to make sure it is behaving the way you want it to, and not just how you told it to. Here is an example of how I use a dictionary with an update cursor: # use a dictionary to populate a field
import arcpy, time, smtplib, sys, inspect, os
arcpy.env.workspace = r'J:\MayorsMap\AGRC_DownLoads\Parcels_SaltLake.gdb'
ws = arcpy.env.workspace
source = '{}\ParcelInfo'.format(ws)
tableFields = ['parcel_id','OwnerType']
target = '{}\Parcels_CLipped'.format(ws)
updateFields = ['PARCEL_ID', 'OWN_TYPE']
#create a dictionary of the {parcel_id:ownertype} from source...
pidDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(source,tableFields)}
#start an edit session on non-versioned egdb
edit = arcpy.da.Editor(ws)
edit.startEditing()
edit.startOperation()
#step through the tables and update
#if the record has a valid site-id and a null site_guid
#update the site_guid Both of these come from sites_1 feature class
try:
with arcpy.da.UpdateCursor(target,updateFields) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
if keyValue in pidDict and updateRow[1] == None:
updateRow[1] = pidDict[keyValue][0]
updateRows.updateRow(updateRow)
else:
pass
edit.stopOperation()
edit.stopEditing(True)
except Exception as err:
print(err)
Don't worry about the try/except blocks but notice how I check to see if the keyValue is in the dictionary in line 30, nested witihin the for loop...
... View more
10-20-2020
12:05 PM
|
1
|
2
|
5504
|
|
POST
|
I took the liberty of using the Syntax Highlighter to format you code. I think it's right. Look at lines 63 through 75, in particular line 69; I think it needs to be indented so the if statement is within the 'for' loop at line 64. ('If' should line up with line 66). Also, can you verify your csv is being read into the dictionary properly? For scripts like this with several moving parts, I like to run them in a console piece by piece to make sure everything is functioning the way I want them to. I use Spyder, but I think Pycharm can do the same thing... #I have a CSV that contains the information required to populate the COMPKEY based on myOID.
#Need to pick which layer you are adding COMPKEY's
import csv, arcpy
# set the database to connect to and the csv file to read
workspace = r"Database Connections\Connection to hwdsql02.sde"
CompKey= r"C:\GIS\Python\CompKey.csv"
# Create a Describe object for an SDE database; to make sure connecting to proper version
desc = arcpy.Describe(workspace)
# Print Connection properties
cp = desc.connectionProperties
print("\nDatabase Connection Properties:")
print("%-12s %s" % (" Server:", cp.server))
print("%-12s %s" % (" Instance:", cp.instance))
print("%-12s %s" % (" Database:", cp.database))
print("%-12s %s" % (" Version:", cp.version))
arcpy.env.workspace = workspace
#start an edit session
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data): startEditing ({with_undo}, {multiuser_mode})
edit.startEditing(True, True)
print ("start an edit session")
# Start an edit operation
edit.startOperation()
# set up some variables; fc=feature class; csvdict=CSV Dictionary
fc = r"sdedpwutilities.DBO.WaterDistribution\ sdedpwutilities.DBO.wMain"
myOID = ['OID@']
fc_fields = ['OID@','COMPKEY']
csvdict = {}
header = True
#Read the CSV File and store in csvdict dictionary
with open(CompKey, 'r') as f:
reader = csv.reader(f)
#skip header
_ = next(f)
for row in reader:
key = [int(row[0])]
# print (key)
csvdict[row[0]] = [row[1]]
print (csvdict)
print "That was the dictionary"
#cursor to update the fc
with arcpy.da.UpdateCursor(fc, fc_fields) as cursor:
for row in cursor:
myOID = (row[0])
print myOID
# this loop is to assign each field in the dictionary to the cooresponding field in the fc_fields list
if csvdict.has_key(myOID):
print('found myOID for {}'.format(myOID))
row[1] = csvdict[myOID][0]
cursor.updateRow(row)
print cursor
else:
print ('no matching myOID')
# Stop the edit session and save the changes: stopEditing (save_changes) default value is true
edit.stopEditing(True)
print ("stop an edit session")
del cursor
... View more
10-20-2020
11:20 AM
|
1
|
5
|
5504
|
|
POST
|
I wonder if using OID@ as a variable name is causing you the problem. Change that to something like myOID....
... View more
10-20-2020
10:35 AM
|
0
|
1
|
5504
|
|
POST
|
Again since I'm not well versed in Collector, I can only make a suggestion: take a look at Geodatabse Sequences. They dovetail well into arcade attribute rules.
... View more
10-20-2020
10:16 AM
|
0
|
0
|
1663
|
|
POST
|
I clobbered a feature class in our live Egdb that has attribute rules. When restoring feature class from the incremental backup from last night, our DBA is getting this error: Not sure what it means, but we have experienced other 'gotchas' with our feature classes that have attribute rules associated with them. What we just did was restore the entire live egdb from last night to our test egdb, so I just need to truncate the live feature class and then append the test features back in, and I'm good to go. Can anyone explain?
... View more
10-20-2020
08:32 AM
|
0
|
0
|
643
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-11-2018 07:12 AM | |
| 1 | 05-17-2021 11:18 AM | |
| 1 | 06-29-2021 11:42 AM | |
| 1 | 07-05-2012 07:49 AM | |
| 1 | 09-03-2016 06:16 AM |
| Online Status |
Offline
|
| Date Last Visited |
05-19-2026
11:56 AM
|