|
POST
|
I just took a quick look at your code. You need to make at least one change. For the comparison, it can help to convert case, so that it does not prevent a match. You can either convert your oldText to upper case for comparison, or remove the .upper() and do a case sensitive match: # change:
if "Print Date" in oldText.upper():
# to:
if "PRINT DATE" in oldText.upper():
# or:
if "Print Date" in oldText:
... View more
11-28-2018
09:13 AM
|
0
|
0
|
4392
|
|
POST
|
You could process all your MXDs in a directory using os.walk or similar. If you only wanted to rename textboxes with the word "Date" in the text, you could use something like: import arcpy, glob, os
path = r"C:\Directory\to\search"
os.chdir(path)
for file in glob.glob("*.mxd"):
print "Processing: {}".format(file)
mxd = arcpy.mapping.MapDocument(file)
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
if "DATE" in elm.text.upper():
elm.name = 'DateBox'
print elm.text, elm.name
mxd.save() # or mxd.saveACopy('newname')
del mxd This assumes that only one box will contain the word "Date". To take this further, you could check for other text and name the box accordingly (if a dictionary key is found in the text, set the name to the paired value, for example).
... View more
11-27-2018
08:19 PM
|
1
|
18
|
4392
|
|
POST
|
Using Dan's example, try the comparison with just "DATE" and use .upper(): if "DATE" in oldText.upper():
new_fixed = "{}: {}".format(oldText.split(":")[0], newdate)
... View more
11-27-2018
09:15 AM
|
0
|
0
|
4392
|
|
POST
|
The lines would be inserted in this section: with arcpy.da.UpdateCursor(pointLayer, updateFieldsList) as cursor:
for Row in cursor:
keyValue = Row[0]
if keyValue in valueDict:
for n in range (1,len(sourceFieldsList)):
if valueDict[keyValue][n-1] is not None:
Row[n] = valueDict[keyValue][n-1]
else:
Row[n] = 'n/a'
cursor.updateRow(Row) But I'm not sure this will give you the results you want. Normally, the dictionary technique that Richard describes in his blog is used to avoid creating joins. And since you are doing a spatial join anyway, I would probably use the field calculator to copy the contents of the polygon's field that you want into the point's field. The join should only join points to polygons if the point is inside the polygon, so the calculation will only make the update where there is a match. If you do want to use the dictionary, I suspect that your dictionary key needs to be the OID from the point feature and the value needs to be the Class_ID from the polygon feature. You may want to look at the field names that the join uses as it might be something like pointLayer.OID and polyLayer.Class_ID. Hope this helps.
... View more
11-19-2018
10:57 AM
|
1
|
0
|
947
|
|
POST
|
In your dictionary, the last 3 dictionary keys contain null values: {.... 16: (None,), 17: (None,), 18: (None,)} You can try something like this to test for null/None: if valueDict[keyValue][n-1] is not None:
Row = valueDict[keyValue][n-1]
else:
# use substitute value or pass
... View more
11-19-2018
09:19 AM
|
1
|
2
|
947
|
|
POST
|
You reference Richard Fairhurst's article which describes a process using a dictionary to avoid using a join. I notice in your code you are using a join before creating a dictionary: #Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(pointLayer, polygonLayer, sjpoints)
# populate the dictionary from the polygon
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)} First, can you verify the join works as expected. I'm not sure the TARGET_FID and OID@ are providing the link you need to make the dictionary technique work. I am making the assumption that you want to capture some attribute of the polygon feature and save it as an attribute with all the points that fall inside the polygon. Perhaps you can clarify if this is not the case. As an additional test, you can print some or all of the valueDict to see if there are null/None values associated with the various dictionary keys. You could add a test in the update block, that if the dictionary key's value is None/null, then skip the update or substitute a default value. As written, the block is skipping any updates if the keyValue is not in the valueDict. Hope this helps.
... View more
11-15-2018
09:22 PM
|
1
|
1
|
5843
|
|
POST
|
I place a "revision" at the bottom of my maps using dynamic text. The format is easy to figure out: Rev: <dyn type="date" format="yyMMdd"/><dyn type="time" format="HHmm"/> Working with dynamic text Another method I like to use is naming the text boxes when you create them. This helps in finding a specific one and makes it easy to replace text. Set the 'Element Name' on 'Size and Position' tab in Desktop version. for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
if elm.name == "PrintDate": # text element named 'PrintDate'
elm.text = "Print date: {}".format(someDate)
# elm.text = "Print date: <dyn type=\"date\" format=\"\"/>"
... View more
11-13-2018
03:04 PM
|
2
|
20
|
4392
|
|
POST
|
While the json returned should be consistent in format, you may wish to search for "token":" and start your substring after its location.
... View more
11-08-2018
11:52 AM
|
0
|
0
|
2826
|
|
POST
|
Can you use an expression like mid(string, start, end)? Or find the third " and select to the fourth ".
... View more
11-08-2018
11:31 AM
|
0
|
2
|
2826
|
|
POST
|
The AGOL token is a text string of consistent length. I would use the python json module for extracting the token and other items in the response. If you are using another method to extract the token, it will be quoted string following the word token. If you use f=json, you will get json without formatting which may make it easier to parse.
... View more
11-08-2018
10:51 AM
|
0
|
4
|
2826
|
|
POST
|
Just venturing a guess... The > in your where clause probably needs to be escaped with %3E. OBJECTID%3E1 You could omit the where as a test. HTML URL Encoding Reference
... View more
11-07-2018
04:47 PM
|
0
|
0
|
8502
|
|
POST
|
I use json.dumps to clean up what I send to the server; it converts None to null: >>> import json
>>> attribs = { 'someValue' : None }
>>> attribs
{'someValue': None}
>>> update_dict = { "features" : json.dumps(attribs) }
>>> update_dict
{'features': '{"someValue": null}'}
... View more
11-06-2018
09:09 AM
|
2
|
0
|
1639
|
|
POST
|
Here are some sample python toolboxes that might give you some ideas for your project. The first is basically a python toolbox version of the script tool described in the blog post mentioned in my previous post. I have added a dropdown for the weight values. Select a feature layer or feature class; select a field in that feature; choose an attribute and select the weight. import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Select Value"
self.alias = "selection"
# List of tool classes associated with this toolbox
self.tools = [SelectValue]
class SelectValue(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Select Value"
self.description = ""
self.canRunInBackground = False
self.fcfield = (None, None) # global to remember field selection
def getParameterInfo(self):
"""Define parameter definitions"""
# First parameter
inFeature = arcpy.Parameter(
displayName="Input Features",
name="inFeature",
datatype=["DEFeatureClass","GPFeatureLayer"],
parameterType="Required",
direction="Input")
# Second parameter
fieldName = arcpy.Parameter(
displayName="Field Name",
name="fieldName",
datatype="Field",
parameterType="Required",
direction="Input")
fieldName.parameterDependencies = [inFeature.name]
fieldName.filter.list = ["Short", "Long", "Double", "Float", "Text"]
# Third parameter
fldProperty = arcpy.Parameter(
displayName="Property",
name="fldProperty",
datatype="String",
parameterType="Required",
direction="Input")
fldProperty.parameterDependencies = [inFeature.name, fieldName.name]
# Fourth parameter
weightVal = arcpy.Parameter(
displayName="Weight",
name="weightVal",
datatype="String",
parameterType="Required",
direction="Input")
weightVal.filter.list = [ 1, 2, 5, 8, 10 ]
weightVal.value = weightVal.filter.list[0]
params = [inFeature, fieldName, fldProperty, weightVal]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if parameters[0].value and parameters[1].value: # get first field and value list
fc, col = parameters[0].valueAsText, parameters[1].valueAsText
desc = arcpy.Describe(parameters[0])
if desc.dataType == 'FeatureLayer': # if feature layer, use catalog path
fc = desc.catalogPath
if self.fcfield != (fc, col):
self.fcfield = (fc, col)
parameters[2].filter.list = [str(val) for val in sorted(set(row[0] for row in arcpy.da.SearchCursor(fc,col)))]
if parameters[2].value not in parameters[2].filter.list:
parameters[2].value = parameters[2].filter.list[0]
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
inFeature = parameters[0].valueAsText
fieldName = parameters[1].valueAsText
fldProperty = parameters[2].valueAsText
weightVal = parameters[3].valueAsText
messages.addMessage(
"\nInput Feature: {}".format(inFeature))
messages.addMessage(
"\nSelected Field: {}".format(fieldName))
messages.addMessage(
"\nWeight Value: {}".format(weightVal))
messages.addMessage(
"\nField Property: {}".format(fldProperty))
desc = arcpy.Describe(parameters[0])
messages.addMessage(
"\nDataType: {}\nPath: {}".format(desc.dataType, desc.catalogPath))
return
The second reads domain information into a list for the dropdown. In this example, the domain is hard-coded to a specific domain in a specific database (lines 32-33). It could be modified to allow the user to select the database and domain name. import arcpy, operator
def getDomain(gdb, domainName):
domDict = {} # empty dictionary
domains = arcpy.da.ListDomains(gdb)
for domain in domains: # assumes domainName references a coded value domain
if domain.name == domainName:
coded_values = domain.codedValues
for val, desc in coded_values.items():
domDict[desc] = val # use { desc: val, ... } for dropdown menu
return domDict
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
self.domain = getDomain(r'C:\Path\to\file.gdb',
'DomainName') # domain description: domain code
def getParameterInfo(self):
"""Define parameter definitions"""
domValue = arcpy.Parameter(
displayName = "Select Domain",
name = "domValue",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
domValue.filter.type = "ValueList"
# set filter list; descriptions sorted in code order
domValue.filter.list = [x[0] for x in sorted(self.domain.items(), key=operator.itemgetter(1))]
domValue.value = domValue.filter.list[0] # default first item in list
return [domValue]
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
messages.addMessage('Selected: {} -- Code: {}'.format(parameters[0].value, self.domain[parameters[0].value]))
return
Hope this gives you some ideas.
... View more
11-01-2018
08:16 PM
|
1
|
0
|
1959
|
|
POST
|
Have you tried adding it to the URL: &token=yourtokenvalue
... View more
10-31-2018
09:19 AM
|
1
|
0
|
5197
|
|
POST
|
Are you creating a script tool or Python toolbox? Both have an updateParameters function that can help with creating a choice list. This blog Generating a choice list from a field discusses programming the validator in a script tool. And to help me understand your project... In your list, 'dolomite' has a weight of 2. Would you want the user to select 'dolomite' and give it a weight other than 2? Do you want the user to be able to select from other features? And if so, are they similarly structured (same field layout)?
... View more
10-27-2018
11:07 AM
|
1
|
1
|
1959
|
| 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
|