|
POST
|
Just a couple of things that might help in my understanding your question. First, escaping vs. raw string, I just want to make sure this isn't the actual issue. folder = r'S:\\GIS\ServerMXDs\\_Future_Services\\CityWorks'
# should be
folder = r'S:\GIS\ServerMXDs\_Future_Services\CityWorks'
# or
folder = 'S:\\GIS\\ServerMXDs\\_Future_Services\\CityWorks' Second. Are you examining the layer source path for a specific name, such as layer.dataSource contains "ServiceEstablishments"? Are you also checking layer.name for this value as "ServiceEstablishments" may be an alias for a data source path that does not contain the phrase? I think your "in" and "split" would otherwise work.
... View more
09-29-2017
02:34 PM
|
1
|
2
|
2365
|
|
POST
|
With Field Calculator, you can only do a single pass, and you wouldn't get the exact name you are looking for. Each name would be appended with an ID number. That said, you might get something close with this. Pre-Logic Script Code: d ={} # global dictionary for counting
def seq_count(f0,f1,f2):
global d # access counting dictionary
dictValue = "{}{}".format(f0,f1)
if dictValue not in d.keys():
d[dictValue] = 1 # insert key into dictionary and set value to 1
return "{}_{}".format(dictValue,d[dictValue]) # value to update field
else:
d[dictValue] += 1 #increment value in dictionary
return "{}_{}".format(dictValue,d[dictValue]) # value to update field Call it with: seq_count(!rpsuid!, !facilityNumber!, !waterUtilityNodeIDPK!) Result: 6705Water_1
6705Water_2
6705Sewer_1
6705Sewer_2
6705Sewer_3
6705Comm_1
... View more
09-26-2017
12:05 PM
|
1
|
3
|
1812
|
|
POST
|
You can run the code inside ArcMap's python window, or by adding a few additional lines ("import arpy", path to layer, etc) you can run it frome idle or command line. It is not meant to run in field calculator.
... View more
09-26-2017
11:07 AM
|
0
|
0
|
4722
|
|
POST
|
Using two passes, this provides the sequential numbering desired. layer = 'layerName' # your layer or shapefile
field0 = "rpsuid" # first field to concatenate
field1 = "facilityNumber" # second field to concatenate
field2 = "waterUtilityNodeIDPK" # field to update
d0 = {} # dictionary for counting (first pass)
d1 = {} # dictionary for counting (second pass)
# first pass - just count
with arcpy.da.SearchCursor(layer, [field0, field1, field2]) as rows:
for row in rows:
dictValue = "{}{}".format(row[0],row[1])
if dictValue not in d0.keys():
d0[dictValue] = 1 # insert key into dictionary and set value to 1
else:
d0[dictValue] += 1 # increment value in dictionary
# second pass - update
with arcpy.da.UpdateCursor(layer, [field0, field1, field2]) as rows:
for row in rows:
dictValue = "{}{}".format(row[0],row[1])
if dictValue not in d1.keys():
d1[dictValue] = 1 # insert key into dictionary and set value to 1
# check value in d0 from first pass
if d0[dictValue] > 1:
row[2] = "{}_{}".format(dictValue,d1[dictValue]) # value to update field
else:
row[2] = dictValue # value to update field
else:
d1[dictValue] += 1 #increment value in dictionary
row[2] = "{}_{}".format(dictValue,d1[dictValue]) # value to update field
rows.updateRow(row)
print "Done" Results: 6705Water_1
6705Water_2
6705Sewer_1
6705Sewer_2
6705Sewer_3
6705Comm
... View more
09-23-2017
10:57 AM
|
1
|
3
|
4722
|
|
POST
|
How about something like: layer = 'layerName' # your layer or shapefile
field0 = "rpsuid" # first field to concatenate
field1 = "facilityNumber" # second field to concatenate
field2 = "waterUtilityNodeIDPK" # field to update
d = {} # dictionary for counting
with arcpy.da.UpdateCursor(layer, [field0, field1, field2]) as rows:
for row in rows:
dictValue = "{}{}".format(row[0],row[1])
if dictValue not in d.keys():
d[dictValue] = 0 # insert key into dictionary and set value to 0 or 1
# 0 will start appending with '_1' and 1 will start with '_2'
row[2] = dictValue # value to update field
# print dictValue
else:
d[dictValue] += 1 #increment value in dictionary
row[2] = "{}_{}".format(dictValue,d[dictValue]) # value to update field
# print "{}_{}".format(dictValue,d[dictValue])
rows.updateRow(row)
# print d
You may be able to add an sql_clause in the UpdateCursor if you want a certain order. The sequential numbering is not exactly as you desire; that would require two passes. But this produces results that may be acceptable: 6705Water
6705Water_1
6705Sewer
6705Sewer_1
6705Sewer_2
6705Comm
... View more
09-22-2017
05:38 PM
|
1
|
0
|
4722
|
|
POST
|
Since you are using SQL Server, would it be possible to create a view of your feature/table (removing fields like geometry, blobs, rasters, etc. that you don't want), and then set up a direct ODBC connection between Excel and the view?
... View more
09-22-2017
12:29 PM
|
0
|
0
|
13155
|
|
POST
|
I would also suggest Turbo Charging Data Manipulation with Python Cursors and Dictionaries (see Example 1). Using a search cursor, you would load a dictionary with values contained in the SKMS_for field along with the objectID or globalID for that dataset. Then using an update cursor, if the field value is in the dictionary, you can do your editing or mark the row for later action.
... View more
09-22-2017
09:24 AM
|
0
|
1
|
4000
|
|
POST
|
I was able to generate the exact same error as the one you mentioned in a previous post by adding a nonexistent field to the fields dictionary: fields = dict((f.name, []) for f in arcpy.ListFields(layer) if not f.required) # your line 17
fields['bull'] = [] # nonexistant field When using a wild card for the field list in SearchCursor (or not specifying a field list), SearchCursor will return all fields with a few exceptions (raster and BLOB fields are excluded). You will need to exclude these fields when you create your dictionary. This code might work to exclude rasters and blobs from the fields dictionary: fields = dict((f.name, []) for f in arcpy.ListFields(layer) if not (f.required or f.type == "Blob" or f.type=="Raster")) Another option would be to create a try/except block around lines 20-21, perhaps: for f in fields.keys():
try:
fields .append(row.getValue(f))
except:
print "{} not in field list".format(f)
If these suggestions fail, you should print the fields dictionary and compare it to field list in your feature.
... View more
09-20-2017
03:23 PM
|
1
|
1
|
2208
|
|
POST
|
If you print the "fields" variable between lines 17 and 18, what do you get? Something like: {u'Field1': [], u'Field2': [], u'Field3': [], u'Field4': []}
... View more
09-20-2017
09:27 AM
|
0
|
0
|
2208
|
|
POST
|
You might try: arcpy.CalculateField_management("Mainfb_Stage_P","AFileN","!ABFileN!.replace('/','-')","PYTHON_9.3")
... View more
09-20-2017
09:13 AM
|
0
|
0
|
1290
|
|
POST
|
Dan, are you using multiple data frames in your map document? I think your code might be making it through the active data frame and getting hung up in an inactive data frame. It seems that some elements of a layer don't exist (or can't be accessed) if they are in an inactive data frame. I've been testing the following code in 10.5 without error. But the map document becomes a bit unstable until I manually activate the first data frame. mxd = arcpy.mapping.MapDocument('CURRENT')
for df in arcpy.mapping.ListDataFrames(mxd):
mxd.activeView = df.name # data frames should have unique names
print df.name
for layer in arcpy.mapping.ListLayers(mxd, data_frame=df):
if layer.isGroupLayer:
print "Group Layer: {}".format(layer.name)
elif layer.isFeatureLayer:
print "Feature Layer: {}".format(layer.name)
fields = dict((f.name, []) for f in arcpy.ListFields(layer) if not f.required)
for row in arcpy.SearchCursor(layer):
for f in fields.keys():
fields[f].append(row.getValue(f))
del row
print fields
del layer
del df
del mxd Part of what this does is specify a data frame in ListLayers (line 6). Since this active view is set by using a data frame name, it is important that all data frames have unique names. When fields is printed (line 17) it appears as I would expect. The code above may not be switching active views in the most efficient manner, but I have not seen any examples where it is done differently. I had previously thought that the problem might have been with SearchCursor needing a field list, but it appears that it defaults to a list of all fields (with some exceptions).
... View more
09-19-2017
08:38 PM
|
0
|
4
|
2208
|
|
POST
|
Regarding the comment in your code around line 8: # need to find way to get list of layers there can be more than one data frame Consider the following: >>> mxd = arcpy.mapping.MapDocument('CURRENT')
>>> for df in arcpy.mapping.ListDataFrames(mxd):
... print df.name
... for layer in arcpy.mapping.ListLayers(mxd, data_frame=df):
... print layer.name
...
DataFrame1
LayerInDF1
DataFrame2
LayerInDF2
>>> for layer in arcpy.mapping.ListLayers(mxd):
... print layer.name
...
LayerInDF1
LayerInDF2
>>> Your use of ListLayers without specifying a data_frame should process all layers in all data frames. You may need to activate the data frames as you loop through them.
... View more
09-19-2017
09:37 AM
|
1
|
0
|
2208
|
|
POST
|
Looks like the line Dan Patterson is referring to is after the first "elif". Formatting the code for Geonet will provide line numbers and help the discussion.
... View more
09-18-2017
04:08 PM
|
0
|
0
|
4434
|
|
POST
|
Since the code is not properly indented, it is difficult to offer a suggestion. Formatting your code when posting to Geonet will help: Code Formatting... the basics++ Also, can you include the error message text?
... View more
09-18-2017
02:07 PM
|
1
|
0
|
4434
|
|
POST
|
In AGOL, I click on the feature layer in the Content tab. Then on the Overview tab, there is a Service URL link in the Layers section. The Service URL page has a link to the JSON file located at the top of the page. If you are using ArcGIS server, you will look for the REST services end point. This documentation may help: An overview of geoprocessing REST Services
... View more
09-18-2017
11:55 AM
|
1
|
1
|
5760
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|