|
POST
|
Just as a side note, nesting 10 IIFs is bound to get complicated with the closing parantheses. It's much easier to do var att = $feature.Attribute
return When(att==1, "ForestCover", att==2, "ShrubCover", att=3, "Grassland", "Not Found")
... View more
09-22-2021
05:26 AM
|
1
|
2
|
4456
|
|
POST
|
// before line 40
var module_desc = null
if(Count(cuMoDe) > 0) {
module_desc = First(cuMoDe).ModuleDescription
}
// before line 44
'Module_desc': module_desc,
... View more
09-22-2021
01:12 AM
|
1
|
1
|
3004
|
|
POST
|
It is possible, but a bit cumbersome. The popup doesn't evaluate HTML code returned by an expression, so you will have to create multiple expressions like this: // index of the agreement link you want to return
// 0 for first, 1 for second, ...
var return_index = 0
// split the agreements field
var agreements = Split($feature.Agreements, ", ")
// return early if you try to return an agreement that doesn't exist
if(return_index + 1 > Count(agreements)) {
return ""
}
// return the specified agreement link
return "https://testsite.sharepoint.com/sites/ROW/Easements/" + agreements[return_index] + ".pdf" Copy that expression multiple times (if your maximum agreement number is 5, you should have 5 expressions) and change the return_index. You shoulb be able to show the links in the popup's attribute table. If you want to get fancy, you can create expressions for the agreement names, too: // index of the agreement name you want to return
// 0 for first, 1 for second, ...
var return_index = 0
// split the agreements field
var agreements = Split($feature.Agreements, ", ")
// return early if you try to return an agreement that doesn't exist
if(return_index + 1 > Count(agreements)) {
return ""
}
// return the specified agreement link
var sep = IIF(return_index == 0, "", ", ")
return sep + agreements[return_index] Then you can create your example from above in the popup's HTML code: Agreements: <a href="{expression/link1}">{expression/name1}</a><a href="{expression/link2}">{expression/name2}</a><a href="{expression/link3}">{expression/name3}</a><a href="{expression/link4}">{expression/name4}</a>
... View more
09-22-2021
01:01 AM
|
1
|
0
|
2555
|
|
POST
|
You are on the right track, your for loop is just a little wonky. What you're doing is this: increase index check if it is 2 yes: return Filepath (and you try to return it from the feature set as opposed to returning it from row) no: set output to " " and return that So the code gets to the first row, sees that index = 1 != 2 and returns " ". Copy this function and change the return_index for each instance. // the number of the row from which you want to return the AttachmentID
// 1 for first, 2 for second, ...
var return_index = 2;
var related_table = OrderBy(FeatureSetByRelationshipName($feature,"%vw_EventAttachments"), "AttachmentID");
var filter_query = "EGUID = '" + $feature["EGUID"] + "'";
var related_data_filtered = Filter(related_table, filter_query);
var related_data_filtered_count = Count(related_data_filtered);
// return early if you want to get an attachment that doesn't exist
if(return_index > related_data_filtered_count) {
return "";
}
var index = 1;
for (var row in related_data_filtered) {
if(index == return_index) {
return row.Filepath;
}
index++;
}
... View more
09-22-2021
12:40 AM
|
2
|
1
|
1708
|
|
POST
|
Sure, that's one of the most common use cases for Attribute Rules. // Calculation Attribute Rule
// Field: LocationID
// Triggers: Insert, Update
// Exclude: True
// load the Areas poylgon class
var areas = FeatureSetByName($datastore, "NameOfFeatureclass", ["NameField"], true)
// intersect the areas with the inserted/edited feature
var inter = Intersects(areas, $feature)
// if feature is not in any area, return null
if(inter == null || Count(inter) == 0) {
return null
}
// else return the first intersecting area's name field
return First(inter).NameField
... View more
09-22-2021
12:05 AM
|
2
|
3
|
4082
|
|
POST
|
If you don't want to deal with selections, you can check if the point intersects the geometry objects of the targeted layer. Depending on the object count, this might be a lot slower. # construct your query geometry
query_geometry = ...
# optional: buffer
query_geometry = query_geometry.buffer(100)
# read the geometries of the target layer
layer_geometries = [r[0] for r in arcpy.da.SearchCursor(layer, ["SHAPE@"])]
# filter by intersection with query_geometry
intersecting_geometries = [g for g in layer_geometries if not g.disjoint(query_geometry)]
... View more
09-21-2021
01:30 AM
|
1
|
0
|
2398
|
|
POST
|
Sorry, I should have tested it... It works with datatype GPFeatureLayer and not setting the filter type. I edited the post above accordingly for future reference.
... View more
09-20-2021
08:18 AM
|
2
|
0
|
5211
|
|
POST
|
Sooooo.... I use the default metadata option, which seems to be "Item description". Like you, I just tried creating a new python toolbox, editing the metadata of the default tool and searching for that tool. Didn't work: Then I remembered: For my work, I programmed quite a few tools (e.g. input forms). Because the tools were in constant development, I didn't want to manually edit the metadata each time I changed some parameters. So I created a custom Parameter class and gave the Tool class some extra attributes and wrote a function that creates the tool help files automatically. def Parameter(*args, **kwargs):
"""Wrapper for `arcpy.Parameter` which allows for a custom attribute `description`.
I can't just inherit from `arcpy.Parameter`, because arcpy is a wrapper for C classes and when I tried, it didn't work as expected. Using a wrapper class and forwarding all the methods and attributes would be too cumbersome. That's why this is a function that returns an `arcpy.Parameter`, using python's dynamic typing to add a custom attribute (which does noting in the underlying C code).
"""
try:
desc = kwargs["description"]
del kwargs["description"]
except KeyError:
desc = ""
p = arcpy.Parameter(*args, **kwargs)
p.description = desc
return p # Toolbox.pyt
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.canRunInBackground = False
# attributes for automatically creating the metadata
self.description = "This is a test tool."
self.usage = "You can't do anything with this tool."
self.search_keys = ["test", "another_tag"]
def getParameterInfo(self):
"""Define parameter definitions"""
params = [
## arcpy.Parameter(name="parameter", displayName="Parameter", datatype="GPString", parameterType="Optional", direction="Input"),
Parameter(name="parameter", displayName="Parameter", datatype="GPString", parameterType="Optional", direction="Input", description="This parameter does nothing."),
]
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."""
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."""
return
def create_tool_help_files():
import os
import datetime
import xml.etree.cElementTree as ET
today = datetime.datetime.now().strftime("%Y%m%d")
for tool in Toolbox().tools:
tool_instance = tool()
metadata = ET.Element("metadata")
dataIdInfo = ET.SubElement(metadata, "dataIdInfo")
# ESRI metadata
esri = ET.SubElement(metadata, "Esri")
ET.SubElement(esri, "CreaDate").text = today
ET.SubElement(esri, "CreaTime").text = today
ET.SubElement(esri, "ArcGISFormat").text = "1.0"
ET.SubElement(esri, "SyncOnce").text = "TRUE"
ET.SubElement(esri, "ModDate").text = today
ET.SubElement(esri, "ModTime").text = today
scaleRange = ET.SubElement(esri, "scaleRange")
ET.SubElement(scaleRange, "minScale").text = "150000000"
ET.SubElement(scaleRange, "maxScale").text = "5000"
# tool metadata
toolMeta = ET.SubElement(metadata,
"tool",
xmlns = "",
name = tool.__name__,
displayname = tool_instance.label,
toolboxalias = "")
ET.SubElement(toolMeta, "arcToolboxHelpPath").text = "c:\\program files\\arcgis\\pro\\Resources\\Help\\gp"
# Tags
searchKeys = ET.SubElement(dataIdInfo, "searchKeys")
tags = getattr(tool_instance, "search_keys", [])
for t in tags:
ET.SubElement(searchKeys, "keyword").text = str(t)
# Summary und Usage
summary = ET.SubElement(toolMeta, "summary").text = getattr(tool_instance, "description", "")
usage = ET.SubElement(toolMeta, "usage").text = getattr(tool_instance, "usage", "")
# parameter metadata
paramMeta = ET.SubElement(toolMeta, "parameters")
parameters = tool_instance.getParameterInfo()
if parameters is None:
parameters = []
for p in parameters:
param = ET.SubElement(paramMeta,
"param",
name = getattr(p, "name", ""),
displayname = getattr(p, "displayName", ""),
type = getattr(p, "parameterType", ""),
direction = getattr(p, "direction", ""),
datatype = getattr(p, "datatype", ""),
expression = getattr(p, "name", ""))
dialogReference = ET.SubElement(param, "dialogReference").text = getattr(p, "description", "n/a")
# Credit
idCredit = ET.SubElement(dataIdInfo, "idCredit").text = getattr(tool, "credit", "My employer\nMy Name\nMy mail address")
# some more general metadata
idCitation = ET.SubElement(dataIdInfo, "idCitation")
resTitle = ET.SubElement(idCitation, "resTitle").text = getattr(tool, "label", "")
distInfo = ET.SubElement(metadata, "distInfo")
distributor = ET.SubElement(distInfo, "distributor")
distorFormat = ET.SubElement(distributor, "distorFormat")
ET.SubElement(distorFormat, "formatName").text = "ArcToolbox Tool"
mdHrLv = ET.SubElement(metadata, "mdHrLv")
ET.SubElement(mdHrLv, "ScopeCd ", value = "005")
mdDateSt = ET.SubElement(metadata, "mdDateSt",Sync="TRUE").text = today
# write XML
directory = os.path.dirname(__file__)
toolbox_label = os.path.basename(__file__).replace(".pyt", "")
ET.ElementTree(metadata).write("{}.{}.pyt.xml".format(os.path.join(directory, toolbox_label), tool.__name__))
# execute the file from IDE to automatically create the tool metadata files
if __name__ == "__main__":
create_tool_help_files() And it works: Please don't ask me why...
... View more
09-20-2021
06:04 AM
|
0
|
0
|
3751
|
|
POST
|
Yes, that is a known limitation of Arcade, as explained in this thread.
... View more
09-20-2021
05:20 AM
|
0
|
0
|
2648
|
|
POST
|
You could do it like this: class DummyTool
def getParameterInfo(self):
param0 = arcpy.Parameter(
displayName="Choice One",
name="input_choice_1",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input"
)
param0.filter.list = ["Polygon"]
params = [param0]
return params
... View more
09-20-2021
01:05 AM
|
1
|
2
|
5225
|
|
POST
|
The last part of your rule is a little wonky: Instead of appending to currentTOC in the for loop, you overwrite it constantly. You return in the for loop, so the first entry of masterFilter is the only one being changed. You do return the edit, but you don't return the result for the field, which is probably why the value is "stolen". var currentTOC = [];
for (var record in masterFilter) {
var update = [{
'globalid': record.GlobalID,
'attributes': {
'current_liquid_level': $feature.toc_to_liquid_ft_1
}
}];
Push(currentTOC, update)
// for older Arcade versions (pre ArcGIS Pro 2.8):
// currentTOC[Count(currentTOC)] = update
}
return {
'result': $feature.toc_to_liquid_ft_1,
'edit': [{
'className': 'RMCDemo_GIS.SDE.RMC_Demo_Master_Layer',
'updates': currentTOC
}]
}
... View more
09-20-2021
12:22 AM
|
1
|
1
|
1444
|
|
POST
|
Yeah, it's the $map global. The documentation could be clearer on that. Think about it this way: Attribute Rules are executed on the database level. The database knows the tables it contains (so it has access to $datastore), but is has no clue about the context in which you are currently using a featureclass (so it has no access to $map). Popups are executed on the application level. The application knows about the database the queried featureclass is in (it has access to $datastore), and it also knows about the context in which you're using the featureclass (has access to $map).
... View more
09-20-2021
12:10 AM
|
0
|
2
|
2654
|
|
POST
|
Don't do it as constraint rule, but as calculation rule on accountname: // Calculation attribute rule
// Field acccountname
// Triggers: Insert, Update
if(IsEmpty($feature.accountname)) {
return null
}
var input = Replace($feature.accountname, "-", "")
return Left(input, 2) + "-" + Mid(input, 2, 5) + "-" + Right(input, 2) To ensure that this calculates correct values, you can do a constraint rule that checks for the length of the string: // Constraint attribute rule
// rejects the edit if there are not exactly 9 characters
var input = Replace($feature.accountname, "-", "")
return Count(input) == 9
... View more
09-19-2021
11:47 PM
|
1
|
1
|
1376
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-30-2023 09:57 AM | |
| 1 | 05-18-2023 12:51 AM | |
| 1 | 03-05-2023 12:46 PM | |
| 1 | 12-07-2022 07:01 AM | |
| 1 | 06-21-2022 08:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-03-2024
06:14 PM
|