|
POST
|
"{} {} '{}'".format(FieldName,opName,valName) if type(valName) is str else "{} {} {}".format(FieldName,opName,valName) You might try something like:
... View more
04-10-2018
01:16 PM
|
3
|
0
|
1591
|
|
POST
|
Can you share more information about the script tool? Or even the tool itself?
... View more
04-09-2018
11:34 AM
|
0
|
0
|
2538
|
|
POST
|
You are using filename in the listing of extensions. Just use the extension: ext = ['.mdb','.gdb'] If the file ends in either of these extensions, then the filename will be found. Also, you need to set the inputDir to the correct value.
... View more
04-04-2018
10:03 AM
|
1
|
0
|
2057
|
|
POST
|
Topic discussed in: domain values showing not domain description. Per the discussion, you might check your feature's JSON file.
... View more
04-03-2018
09:58 AM
|
0
|
0
|
2346
|
|
POST
|
You might try something like: # empty dictionary
dict = {}
# read PREM_ID as key and coordinates
with arcpy.da.SearchCursor(newfc,['PREM_ID','SHAPE@X','SHAPE@Y']) as cur:
for row in cur:
dict[row[0]]= {'x':row[1],'y':row[2] }
# update old feature
with arcpy.da.UpdateCursor(basefc,['PREM_ID','SHAPE@X','SHAPE@Y']) as upCur:
for row in upCur:
# if PREM_ID is in dictionary, update x,y else skip update
if row[0] in dict:
row[1] = dict[row[0]]['x']
row[2] = dict[row[0]]['y']
upCur.updateRow(row)
print "Updated {}".format(row[0])
... View more
04-02-2018
08:21 PM
|
1
|
0
|
1487
|
|
POST
|
An alternative perhaps: import arcpy
x = 7079975.52661
y = 2184310.50409
# WGS 1984 : (4326) Lat/Lon
# NAD_1983_2011_StatePlane_California_II_FIPS_0402_Ft_US - WKID: 6418
ptGeometry = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference(6418)).projectAs(arcpy.SpatialReference(4326))
# print ptGeometry.JSON
print ptGeometry.firstPoint.X, ptGeometry.firstPoint.Y
# Result: -120.172262515 39.1457869508
... View more
04-02-2018
04:37 PM
|
0
|
1
|
9862
|
|
POST
|
Here is a good tutorial from Arc User magazine: Create a Python Tool That Summarizes ArcMap Layer Properties. There are links at the top of the article so you can save the article as a PDF and download the associated dataset and resources. This article will walk you through the steps of adding a Python script to a standard toolbox (.tbx). When Comparing custom and Python toolboxes (this link is a branch from the documentation in my previous comment), the scripts are quite different. Examine the script that comes with the Arc User article to see the differences. The script gets added to the toolbox using a "Wizard" tool. Your script might start something like this: #Import modules...
import arcpy
#User input variables...
topRaster = arcpy.GetParameterAsText(0)
bottomRaster = arcpy.GetParameterAsText(1)
# other input parameters ??
# code to do something with the rasters
# Return or output something
arcpy.SetParameter(2, SomeResult) Can you describe what you would like your tool to do?
... View more
03-29-2018
09:47 PM
|
0
|
0
|
5889
|
|
POST
|
There is some help documentation here: A quick tour of creating tools with Python (although it is not exactly a tutorial). It does offer some explanation of the differences between a script tool and a Python toolbox.
... View more
03-29-2018
01:52 PM
|
1
|
1
|
5889
|
|
POST
|
For an example of populating a dictionary, see Turbo Charging Data Manipulation with Python Cursors and Dictionaries (starting with example 1). You will see code like this: # Use list comprehension to build a dictionary from a da SearchCursor
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
You mention using the NAME field. If it is to be used as the key, what will you use as the value?
... View more
03-27-2018
03:29 PM
|
1
|
13
|
10647
|
|
POST
|
You may need to supply the domain name in your update_dict. {
"fields": [{
"name": "Field_Name",
"domain": {
"type": "codedValue",
"name": "Domain_Name",
"codedValues": [{
"name": "Code Name",
"code": 1
}]
}
}]
}
... View more
03-27-2018
10:20 AM
|
2
|
0
|
9865
|
|
POST
|
There is some discussion about this in the thread: Conditional Drop Down Lists - Tool Validator. Specifically mentioned is this blog Generating a choice list from a field which you should check out as I think it basically does what you want. Specifically, examine the Tool Validator code discussed in the blog. A second blog article that may also be of interest: Generating a multivalue choice list
... View more
03-21-2018
11:40 AM
|
1
|
1
|
4713
|
|
POST
|
With version 10.5, I was having some luck using something like: lyr.replaceDataSource(r"L:\Data\CFX_2018_180214\gdb\CFX_2018.gdb","FILEGDB_WORKSPACE","BB_Points", True)
# omitting 'IFS_Working' from the path
# L:\Data\CFX_2018_180214\gdb\CFX_2018.gdb\IFS_Working\BB_Points It seems strange that the feature class name would be omitted from the path or layer name. This could cause problem if other feature classes in the file geodatabase contain an identical feature name. Could it be a bug? Replacing the data source did not change the layer name, so that had to be set. Also, the old symbology was retained, so that may also need to be corrected. Also, I was working inside ArcMap's Python window and would use arcpy.RefreshActiveView to update the map.
... View more
03-15-2018
08:39 PM
|
1
|
1
|
4538
|
|
POST
|
In your code you are using a function to find a set of unique values, but the function isn't returning anything (therefore, it equals None). Add a line to "return uniqueValues". def unique(fc, field):
values = [row[0] for row in arcpy.da.SearchCursor(fc,(field))]
uniqueValues = set(values)
print(uniqueValues)
return uniqueValues # unique should return a value
Vals = unique(fc, field)
Also if the goal is to count the number of records with a certain attribute, you can modify the function to return a count of the unique records and you will not need to use SelectLayerByAttribute. You would use just one Search Cursor. import arcpy
fc = r'C:\Path\To\file.gdb\feature'
field = 'FieldName' # not an alias
d = {}
with arcpy.da.SearchCursor(fc, (field)) as rows:
for row in rows:
if row[0] not in d: # add to dictionary with value of 1
d[row[0]] = 1
else: # it is in dictionary, just incrment counter
d[row[0]] += 1
for k, v in d.iteritems(): # print results
print k, v
# === same idea, but as a function
def unique2(fc, field):
ud = {}
with arcpy.da.SearchCursor(fc, (field)) as rows:
for row in rows:
if row[0] not in ud:
ud[row[0]] = 1
else:
ud[row[0]] += 1
return ud
Vals2 = unique2(fc, field)
print 'Vals2:'
for k, v in Vals2.iteritems():
print k, v
... View more
03-14-2018
09:47 AM
|
2
|
0
|
2020
|
|
POST
|
Wondering about line 12 in your script: for lyr in arcpy.mapping.List(mxd): Should it be (ListLayers): for lyr in arcpy.mapping.ListLayers(mxd):
... View more
03-13-2018
07:22 PM
|
4
|
0
|
3213
|
|
POST
|
It looks like you are comparing LinkKey (or "field") to a text value instead of a number in your whereclause. Try: # omit the single quotes around the second %s
whereclause = "%s = %s" % ('LinkKey', x)
# optional format
whereclause = "{} = {}".format('LinkKey', x)
... View more
03-12-2018
09:52 AM
|
2
|
0
|
4640
|
| 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
|