|
POST
|
I assume somewhere in your code you are setting a value for world_imagery_layer. Something like: world_imagery_item = ent_gis.content.search("title: WorldImagery_AOI_NewYork owner:api_data_owner", "Map Image Layer")[0]
world_imagery_layer = world_imagery_item.layers[0]
m.add_layer(world_imagery_layer) The error suggests you might have a typo in the layer's name. The layer would not be found and a None would be returned. If you don't spot the error, you should share the bit of code where the world_imagery_layer is being set.
... View more
01-03-2021
07:07 PM
|
0
|
1
|
6081
|
|
POST
|
The historical map is probably using time animation. You may need to adjust the time slider to the appropriate period or select "disable time animation" when creating your map. If this does not apply in your case, then sharing a bit more information on how you created your map would help in providing solutions.
... View more
01-03-2021
01:16 PM
|
0
|
1
|
1025
|
|
POST
|
As @DavidPike suggests, you should use the da.SearchCursor. I noticed that you are attempting to access and set a map title using ListLayoutElements . This will return a list, and you will need to access the proper text element. It might be easier if you use the dynamic map "Title" as this property can be accessed and changed. Here's a code snippet which illustrates these ideas. Since it looks like you are using shape files, you may need to make some changes. mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
feature = 'survey selection'
fields = ['OID@', 'VendorFarm'] # OID@ is ObjectID token (see search cursor help)
jpgPath = r"C:\Path\For\JPGs" # save location for jpgs
# clear any existing selections
arcpy.SelectLayerByAttribute_management(feature, "CLEAR_SELECTION")
with arcpy.da.SearchCursor(feature, fields) as cursor:
for FID, VendorFarm in cursor: # unpack each row by assigning to field name variables
mxd.title = VendorFarm
query = '"FID" = {}'.format(str(FID))
arcpy.SelectLayerByAttribute_management(feature, "NEW_SELECTION", query)
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
jpg = "{}\\{}.jpg".format(jpgPath, VendorFarm) # assuming VendorFarm is valid filename
arcpy.mapping.ExportToJPEG (mxd, jpg) If you need to use the ListLayoutElements, I would suggest that your map's text elements be named as this will help you find the correct element. Just a rough code snippet to illustrate: titleElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
for t in titleElement:
if t.name == 'MapTitle'
t.text = 'Some New Text' Hope this helps.
... View more
12-29-2020
06:16 PM
|
1
|
0
|
2957
|
|
POST
|
The Weighted Overlay tool might help with maximizing and minimizing the various objectives.
... View more
12-17-2020
05:12 PM
|
0
|
0
|
3213
|
|
POST
|
If I understand your project goal correctly, that you want to see if a feature class' name is in a data table, and if so, return the associated field name for that table, then the following script may serve as a starting point. import arcpy
fc = arcpy.GetParameter(0) # input feature class : feature layer, input
tbl = arcpy.GetParameter(1) # input data table: table, input
# FieldName : Parameter(2) # derived, output, string
fc_desc = arcpy.Describe(fc)
arcpy.AddMessage("Feature type: {}".format(fc_desc.dataType)) # 'FeatureClass','FeatureLayer'
arcpy.AddMessage("Feature name: {}".format(fc_desc.name))
arcpy.AddMessage("Feature catalog path: {}".format(fc_desc.catalogPath))
tbl_desc = arcpy.Describe(tbl)
arcpy.AddMessage("Table type: {}".format(tbl_desc.dataType)) # 'Table'
arcpy.AddMessage("Table name: {}".format(tbl_desc.name))
arcpy.AddMessage("Table catalog path: {}".format(tbl_desc.catalogPath))
# may wish to validate that table has fields 'FEATURENAME' and 'FIELDNAME'
where = "FEATURENAME = '{}'".format(fc_desc.name)
arcpy.AddMessage("Where clause: {}".format(where))
cursor = arcpy.da.SearchCursor(tbl_desc.catalogPath,['FIELDNAME'], where)
if any(cursor):
fieldname = cursor[0]
else:
fieldname = '' # empty string
del cursor
arcpy.SetParameterAsText(2, fieldname)
arcpy.AddMessage("Fieldname: {}".format(fieldname if len(fieldname) else '* FIELD NOT FOUND *')) The script uses a number of AddMessage lines for debugging. It does provide an idea for the general flow. In actual use, I would probably have most of the work done in the ToolValidator section where the parameters can be checked more thoroughly before the script tool completes. One check the validator would make is to verify that the data table has the proper fields. Another check could determine that the feature's name is in the data table. If you plan to add a field to the feature, the tool could also be set to verify that the feature does not already contain the field.
... View more
12-16-2020
12:58 PM
|
0
|
0
|
1702
|
|
POST
|
If you want to clear selections in the Tool Validator section, you might try: def updateParameters(self):
if self.params[0].value: # feature has been selected
arcpy.SelectLayerByAttribute_management(self.params[0].value, "CLEAR_SELECTION")
# code continues
... View more
12-02-2020
07:52 PM
|
1
|
0
|
6039
|
|
POST
|
Yes, the tool should clear the selection. Typically, this would be when things complete. The user would need to manually clear any selections before reusing the tool, or the next use of the tool would be limited to the selections. If it is important to see the selected feature after running the tool, I suppose you could insert the "clear selection" instruction at the start of the tool validator code. The idea would be to clear any selections before populating the drop-downs. I could also see that allowing the user to select a group of features to search may help performance if there are lots of parcels and only a specific neighborhood needs to be searched. Then the user would need to know if the dropdown doesn't contain enough selections, then exit the tool, clear any selections and try again.
... View more
12-02-2020
07:40 PM
|
0
|
1
|
6040
|
|
POST
|
Perhaps this tech support article will help: How To: Calculate unique identifier values similar to Global IDs I don't think a field using a GUID can have a default value set. An alternative would be to create/use a text field.
... View more
12-01-2020
07:08 PM
|
0
|
0
|
1391
|
|
POST
|
The error indicates that to_addresses is a string value, but the line of code is expecting to process a list. >>> to_addresses = ['one@somewhere.gov', 'two@somewhere.gov', '', '#' ]
>>> to_addresses[:] = (value for value in to_addresses if value != '' and value != '#')
>>> to_addresses
['one@somewhere.gov', 'two@somewhere.gov'] Per the line of code, empty values and '#' will be removed from the list. It also looks like you are setting up to process two email messages in your lines of code after __name__ == __main__. But you are just resetting the variables to new values, so only the last value will actually be used. Since bcc_addresses is not defined, this will also cause an error.
... View more
11-25-2020
03:22 PM
|
0
|
0
|
725
|
|
POST
|
Its a little difficult to understand your code since it isn't formatted. It does appear that you are trying to run the tool inside Pro using the "CURRENT" project (in what looks like it might be the 4th line). But I'm not sure that you are using the current project when attempting to update the symbology.
... View more
11-20-2020
08:57 PM
|
0
|
1
|
1258
|
|
POST
|
Here's the script I used for debugging my Tool Validator code. Since it is tested outside ArcMap, there are some modifications that are necessary. For example, a full path to the feature containing your PINs is needed. # HELP at http://desktop.arcgis.com/en/arcmap/latest/analyze/creating-tools/debugging-a-toolvalidator-class.htm
import arcpy
# Load the toolbox and get the tool's parameters, using the tool
# name (not the tool label).
#
arcpy.ImportToolbox(r"C:\Path\to\toolbox.tbx") # toolbox location
params = arcpy.GetParameterInfo("SearchParcel") # name of script (not tool label)
# Set required parameters
#
params[0].value = r"C:\Path\to\geodatabase.gdb\PARCELS_BASE" # feature layer
# params[1].value = '0401' # first part of PIN
# params[2].value = '02' # middle part of PIN
# ToolValidator class block
# ----------------------------------------------------------------
class ToolValidator(object):
def __init__(self):
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
# (initializeParameters code here)
return
def updateParameters(self):
if self.params[0].value: # feature has been selected
useFields = ['PIN'] # name of field used by tool (parcel identification number - a string)
desc = arcpy.Describe(self.params[0].value) # information about the input feature
print(desc.dataType) # # Debug # #
fieldNames = { f.name: f.type for f in desc.fields } # dictionary used to keep field names and types together
print(fieldNames) # # Debug # #
if set(useFields).issubset(fieldNames.keys()): # all fields were found by tool
print("Field found in feature class") # # Debug # #
# NOTE: If feature has selections, only the selections will be searched
fc, fld = str(self.params[0].value), useFields
self.params[1].filter.list = sorted(set([f[0][:4] for f in arcpy.da.SearchCursor(fc,fld)]))
if self.params[1].value not in self.params[1].filter.list:
self.params[1].value = self.params[1].filter.list[0]
print(self.params[1].filter.list[0]) # # Debug # #
print(len(self.params[1].filter.list)) # # Debug # #
print(self.params[1].filter.list) # # Debug # #
where_1 = "PIN LIKE '{}%'".format(self.params[1].value)
print(where_1) # # Debug # #
self.params[2].filter.list = sorted(set([f[0][5:7] for f in arcpy.da.SearchCursor(fc,fld,where_1)]))
if self.params[2].value not in self.params[2].filter.list:
self.params[2].value = self.params[2].filter.list[0]
print(self.params[2].filter.list[0]) # # Debug # #
print(len(self.params[2].filter.list)) # # Debug # #
print(self.params[2].filter.list) # # Debug # #
where_2 = "PIN LIKE '{} {}%'".format(self.params[1].value, self.params[2].value)
print(where_2) # # Debug # #
self.params[3].filter.list = sorted(set([f[0][8:] for f in arcpy.da.SearchCursor(fc,fld,where_2)]))
if self.params[3].value not in self.params[3].filter.list:
self.params[3].value = self.params[3].filter.list[0]
print(self.params[3].filter.list[0]) # # Debug # #
print(len(self.params[3].filter.list)) # # Debug # #
print(self.params[3].filter.list) # # Debug # #
# output completed whereClause
self.params[4].value = "PIN = '{} {} {}'".format(self.params[1].value, self.params[2].value, self.params[3].value)
print(self.params[4].value) # # Debug # #
else: # at least one of the field names does not exist in feature; using the parameter to hold an error message
if 'PIN' not in fieldNames.keys():
self.params[1].value = "ERROR: Field 'PIN' not in selected feature class."
print(self.params[1].value) # # Debug # #
return
def updateMessages(self):
self.params[0].clearMessage()
self.params[1].clearMessage()
self.params[2].clearMessage()
self.params[3].clearMessage()
if self.params[0].value is not None: # set error message if field not in feature so user can correct problem
if self.params[1].value is not None:
if self.params[1].value.startswith("ERROR:"):
self.params[1].value = None # clear error message in parameter value, if desired
self.params[2].value = None
self.params[3].value = None
self.params[0].setErrorMessage("Field '{}' is not in Input FC '{}'".format('PIN', self.params[0].value))
print('Setting message 0') # # Debug # #
return
# ----------------------------------------------------------------
# Call routine(s) to debug
#
validator = ToolValidator()
validator.updateParameters()
validator.updateMessages()
print('\n')
for p in params:
print(p.name, p.datatype, p.parameterType, p.direction, p.value)
print('\n')
# tool script (modified for debugging):
inFC = params[0].value # arcpy.GetParameterAsText(0) # input feature class (Input, Data Type 'Feature Layer')
PIN_a = params[1].value # arcpy.GetParameterAsText(1) # PIN[:4] (Input, Data Type 'String')
PIN_b = params[2].value # arcpy.GetParameterAsText(2) # PIN[5:7] (Input, Data Type 'String')
PIN_c = params[3].value # arcpy.GetParameterAsText(3) # PIN[8:] (Input, Data Type 'String')
whereClause = params[4].value # arcpy.GetParameterAsText(4) # set by ToolValidator updateParameters (Output, Derived, Data Type 'String')
arcpy.AddMessage("Where clause used: {}".format(whereClause))
print("Where clause used: {}".format(whereClause)) # # Debug # #
# convert inFC to feature layer since we are outside arcmap
arcpy.MakeFeatureLayer_management(inFC,'inFC_layer')
# use layer created
arcpy.SelectLayerByAttribute_management('inFC_layer', "NEW_SELECTION", where_clause=whereClause)
for i in range(arcpy.GetMessageCount()): # display messages from SelectLayerByAttribute tool
arcpy.AddMessage(arcpy.GetMessage(i))
# print messages created by SelectLayers
print(arcpy.GetMessages()) # # Debug # #
n = arcpy.GetCount_management(inFC)
arcpy.AddMessage("Number of records selected: {}".format(n))
print("Number of records selected: {}".format(n)) # # Debug # # You will notice that I've added some print statements inside the Tool Validator. Normally I wouldn't try to debug the tool's script while working on the validator's code, but it can be placed at the bottom and will need some modification. Even then, you may get some unexpected results. For testing the params (just before the validator class), I started with just the feature and added parts of the PIN to see what changes this would make. Hope this helps.
... View more
11-16-2020
03:38 PM
|
0
|
4
|
6149
|
|
POST
|
I suggest the ToolValidator for this. Modifying the example given in the enable/disable a parameter section, the code would look something like: def updateParameters(self):
# params[0] = Individual or Combine
# params[4] = Output Filename
if self.params[0].value == "Combine":
self.params[4].enabled = True
else:
self.params[4].enabled = False
... View more
11-12-2020
05:23 PM
|
2
|
0
|
1203
|
|
POST
|
I was experimenting with some code that uses a LIKE in the where clause. It pulls parts of the PIN from the data and loads it into dropdowns for the user to select from. Hopefully, it is similar enough to your project that it will give you some ideas. Here's the validator section: import arcpy
class ToolValidator(object):
def __init__(self):
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
# (initializeParameters code here)
return
def updateParameters(self):
if self.params[0].value: # feature has been selected
useFields = ['PIN'] # name of field used by tool (parcel identification number - a string)
desc = arcpy.Describe(self.params[0].value) # information about the input feature
fieldNames = { f.name: f.type for f in desc.fields } # dictionary used to keep field names and types together
if set(useFields).issubset(fieldNames.keys()): # all fields were found by tool
# NOTE: if any selections have been made in fc, then only selected features will be searched
fc, fld = str(self.params[0].value), useFields
self.params[1].filter.list = sorted(set([f[0][:4] for f in arcpy.da.SearchCursor(fc,fld)]))
if self.params[1].value not in self.params[1].filter.list:
self.params[1].value = self.params[1].filter.list[0]
where_1 = "PIN LIKE '{}%'".format(self.params[1].value)
self.params[2].filter.list = sorted(set([f[0][5:7] for f in arcpy.da.SearchCursor(fc,fld,where_1)]))
if self.params[2].value not in self.params[2].filter.list:
self.params[2].value = self.params[2].filter.list[0]
where_2 = "PIN LIKE '{} {}%'".format(self.params[1].value, self.params[2].value)
self.params[3].filter.list = sorted(set([f[0][8:] for f in arcpy.da.SearchCursor(fc,fld,where_2)]))
if self.params[3].value not in self.params[3].filter.list:
self.params[3].value = self.params[3].filter.list[0]
# output completed whereClause
self.params[4].value = "PIN = '{} {} {}'".format(self.params[1].value, self.params[2].value, self.params[3].value)
else: # at least one of the field names does not exist in feature; using the parameter to hold an error message
if 'PIN' not in fieldNames.keys():
self.params[1].value = "ERROR: Field 'PIN' not in selected feature class."
return
def updateMessages(self):
self.params[0].clearMessage()
self.params[1].clearMessage()
self.params[2].clearMessage()
self.params[3].clearMessage()
if self.params[0].value is not None: # set error message if field not in feature so user can correct problem
if self.params[1].value is not None:
if self.params[1].value.startswith("ERROR:"):
self.params[1].value = None # clear error message in parameter value, if desired
self.params[1].setErrorMessage("Field '{}' is not in Input FC '{}'".format('PIN', self.params[0].value))
return
For my testing, I used the following script: import arcpy
inFC = arcpy.GetParameterAsText(0) # input feature class (Input, Data Type 'Feature Layer')
PIN_a = arcpy.GetParameterAsText(1) # PIN[:4] (Input, Data Type 'String')
PIN_b = arcpy.GetParameterAsText(2) # PIN[5:7] (Input, Data Type 'String')
PIN_c = arcpy.GetParameterAsText(3) # PIN[8:] (Input, Data Type 'String')
whereClause = arcpy.GetParameterAsText(4) # set by ToolValidator updateParameters (Output, Derived, Data Type 'String')
arcpy.AddMessage("Where clause used: {}".format(whereClause))
arcpy.SelectLayerByAttribute_management(inFC, "NEW_SELECTION", where_clause=whereClause)
for i in range(arcpy.GetMessageCount()): # display messages from SelectLayerByAttribute tool
arcpy.AddMessage(arcpy.GetMessage(i))
n = arcpy.GetCount_management(inFC)
arcpy.AddMessage("Number of records selected: {}".format(n)) Hope this helps.
... View more
11-10-2020
12:09 AM
|
1
|
6
|
6179
|
|
POST
|
I did some testing with an older version (2.1.2) and ran your script in the Python window. When I used a path to the open project (line 4 in the code), the changes did not appear in the open version. I closed the project without saving and reopened it. The changes were there. I reset the symbology and commented out line 4. I changed line 5 to: p = arcpy.mp.ArcGISProject("CURRENT") The remainder of the script was the same. After running the script in the Python window, the symbology in the project was updated to the new settings. As a final test, I reset the project symbology, closed Pro and ran the script outside Pro using the path to the project. When the project was reopened, the changes were visible. So, if you are working in Pro's Python window, use "CURRENT" otherwise use the path.
... View more
11-06-2020
03:52 PM
|
2
|
1
|
10850
|
|
POST
|
And checking line 16, 'value' is a valid field name found in the layer named 'polygons'?
... View more
11-05-2020
09:25 PM
|
0
|
1
|
10850
|
| 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 |
09-15-2025
02:54 PM
|