|
POST
|
The popup can't process a Featureset, only simple data types like text, numbers, or dates. You need to process the Featureset: var fs = FeaturesetByRelationshipName(...)
var candidates = []
for(var f in fs) {
var c = `${f.Candidate_Name}, email: ${f.EMail}, office phone: ${f.Phone_Number}`
Push(candidates, c)
}
return Concatenate(candidates, TextFormatting.NewLine)
... View more
06-14-2023
02:14 PM
|
0
|
0
|
3162
|
|
IDEA
|
I took a stab at implementing this myself, the script and tool can be found here: https://community.esri.com/t5/arcgis-pro-questions/bd-p/arcgis-pro-questions
... View more
06-14-2023
02:02 PM
|
0
|
0
|
3706
|
|
POST
|
@JoeBryant1 posted an Idea earlier about being able to create bookmarks from the features in a feature class / layer. It then got merged into this really old Idea: https://community.esri.com/t5/arcgis-pro-ideas/layer-to-bookmarks-tool-amp-bookmarks-to-layer/idc-p/946511 Seeing as the original Idea is from 2011, I don't think this will be implemented any time soon, but it seemed like a fun little project to implement myself... The function in the following Python script will read a feature class or layer (honoring definition queries and selection) and create a bookmark file using the feature extents. The bookmark file can then be imported into an ArcGIS Pro map. The bookmarks can be named by a field or with an incrementing number. The features can be dissolved by a field (in that case the naming field gets switched to the dissolve field). The features can be buffered. You can specify the minimum length of the smallest dimension of the resulting bookmarks. Using this function, it's easy to turn the script into a script tool, which is attached to this post (as zipped atbx). This was a fun little project, and if it can help some people, all the better 🙂 import arcpy
from pathlib import Path
def _create_bookmark_dict(in_geometry, min_dist):
"""Returns a dict defining a bookmark for the input arcpy.Geometry object."""
e = in_geometry.extent
d = min([e.width, e.height])
if d < min_dist:
buffered_geometry = in_geometry.buffer((min_dist - d) / 2)
e = buffered_geometry.extent
return {
"type": "CIMBookmark",
"location": {
"xmin": e.XMin,
"xmax": e.XMax,
"ymin": e.YMin,
"ymax": e.YMax,
"spatialReference": {"wkid": in_geometry.spatialReference.factoryCode}
}
}
def create_bookmarks(in_features, out_path, name_field=None, dissolve_field=None, buffer_dist=None, min_dist=None):
"""Creates bookmarks from all features in a layer.
in_features (path to feature class as str / arcpy.mp.Layer object): The input features. If this is a layer, definition queries and selection will be honored.
out_path (str): Path of the output bkmx file.
name_field (str): The field used to name the bookmarks. Optional, default is incrementing number.
dissolve_field (str): The field by which to dissolve the features before creating the bookmarks. Optional, by default there is no dissolving. If both name and dissolve field are specified, the name will be ignored and the features will be named by the dissolve field.
buffer_dist: distance by which the input features are buffered, measured in the default units of the in_feature's coordinate system, important for small features. Optional, defaults to zero.
min_dist: minimum extent width or height, measured in the default units of the in_feature's coordinate system, important for small features. Optional, defaults to zero.
"""
# dissolve features
if dissolve_field not in [None, "", "#"]:
in_features = arcpy.management.Dissolve(in_features, "memory/dissolve", [dissolve_field])
if name_field not in [None, "", "#"]:
name_field = dissolve_field
# buffer features
if buffer_dist is not None and buffer_dist > 0:
in_features = arcpy.analysis.Buffer(in_features, "memory/buffer", buffer_dist)
# create the bookmarks
if min_dist is None or min_dist < 0:
min_dist = 0
bookmarks = []
read_fields = ["SHAPE@"]
if name_field not in [None, "", "#"]:
read_fields.append(name_field)
for i, row in enumerate(arcpy.da.SearchCursor(in_features, read_fields)):
try:
bm = _create_bookmark_dict(row[0], min_dist)
except: # eg null geometry
continue
if name_field not in [None, "", "#"] and row[1] is not None:
bm["name"] = row[1]
else:
bm["name"] = str(i)
bookmarks.append(bm)
# write bkmx file
out_dict = {"bookmarks": bookmarks}
f = Path(str(out_path))
f.write_text(str(out_dict))
if __name__ == "__main__":
in_features = arcpy.GetParameter(0)
out_path = arcpy.GetParameterAsText(1)
name_field = arcpy.GetParameterAsText(2)
dissolve_field = arcpy.GetParameterAsText(3)
buffer_dist = arcpy.GetParameter(4)
min_dist = arcpy.GetParameter(5)
create_bookmarks(in_features, out_path, name_field, dissolve_field, buffer_dist, min_dist)
... View more
06-14-2023
02:01 PM
|
15
|
14
|
7240
|
|
POST
|
Summarize Nearby does what you want, but it creates a new feature class. If you want to add a field to the polygon fc, you can do so with Calculate Field. Switch to Arcade and use this expression (change line 1 to your point fc name): var point_fc = FeaturesetByName($datastore, "PointFC")
return Count(Intersects(point_fc, Buffer($feature, 20, "meters")))
... View more
06-14-2023
12:53 AM
|
0
|
0
|
1880
|
|
POST
|
Your startDate isn't a date, because you're extracting the current day... You can also use Today() instead of Now() to get full days. var endDate = Date('12/31/2023','MM/DD/YYYY')
var startDate = Today()
var age = DateDiff(endDate, startDate,'days')
... View more
06-14-2023
12:40 AM
|
1
|
1
|
6409
|
|
POST
|
When you call First() on an empty Featureset, it will return null. You're trying to call an attribute of null, which raises the error. if (IsEmpty(ggsFilter) || IsEmpty(ggsFilter.GGS)) {
//...
} You're missing null checks in your return dictionaries, too. These might pass evaluation, but they will raise errors on execution if you encounter empty filtered Featuresets. An easy way to handle these would be IIf(): if ($feature.EDIT_RESPONSE == 'Abandon') {
var fieldMap = [
{
"attributes": {
//from StructureBoundary
// bla
//from COMPANY
"COMPANY_NAME": IIf(companyFilter == null, "Default Value", .COMPANY_NAME),
"OPERATOR": IIf(companyFilter == null, "Default Value", companyFilter.IS_OPERATOR),
... View more
06-14-2023
12:23 AM
|
1
|
1
|
4442
|
|
POST
|
So there are two ways to retrieve (and set) values from a dictionary: var d = {"A": 1}
// Dot notation
Console(d.A) // 1
d.B = 2
Console(d.B) // 2
// Bracket notation
Console(d["A"]) // 1
d["C"] = 3
Console(d["C"]) // 3 The dot notation is quicker to write and (imo) easier to read, but it does not resolve variables. In your case, it looks for the key "symbol", doesn't find it and raises an error. To make this work, you need the bracket notation: var category = d[symbol]
... View more
06-13-2023
11:15 PM
|
1
|
1
|
2543
|
|
POST
|
Depending on your naming scheme: # if it's always the same start:
!GeoID!.replace("1000000US", "")
# if the number can change:
!GeoID!.split("US")[-1]
... View more
06-13-2023
07:43 AM
|
1
|
1
|
2085
|
|
POST
|
A general form could look like this: // define which attributes to return
var return_attributes = ["lastinspdate", "nextinspdate"]
// load the featureset
var fs = FeatureSetByName($map, "InspInspectionDates", ['central_asset_id', 'lastinspdate', 'nextinspdate'], false)
// filter for id and dates in future
var ref_id = $feature["CENTRAL_AS"]
var dt = Now()
var filt = "central_asset_id = @ref_id AND nextinspdate > @DT"
// get the next future inspection date
var filtered_fs = OrderBy(Filter(fs, filt), "nextinspdate")
var cou = First(filtered_fs)
if(cou == null) { return "No future inspection found" }
var all_attributes = Dictionary(Text(cou))["attributes"]
var popup_lines = []
for(var a in return_attributes) {
var att = return_attributes[a]
var val = all_attributes[att]
var line = `${att}: ${val}`
Push(popup_lines, line)
}
return Concatenate(popup_lines, TextFormatting.NewLine) This is useful if you want to keep the expression expandable to include more/less fields later. If you don't need that, you can just hardcode it: // define which attributes to return
var return_attributes = ["lastinspdate", "nextinspdate"]
// load the featureset
var fs = FeatureSetByName($map, "InspInspectionDates", ['central_asset_id', 'lastinspdate', 'nextinspdate'], false)
// filter for id and dates in future
var ref_id = $feature["CENTRAL_AS"]
var dt = Now()
var filt = "central_asset_id = @ref_id AND nextinspdate > @DT"
// get the next future inspection date
var filtered_fs = OrderBy(Filter(fs, filt), "nextinspdate")
var cou = First(filtered_fs)
if(cou == null) { return "No future inspection found" }
var popup_lines = [
`Last inspection: ${cou["lastinspdate"]}`,
`Next inspection: ${cou["nextinspdate"]}`,
]
return Concatenate(popup_lines, TextFormatting.NewLine)
... View more
06-13-2023
07:09 AM
|
0
|
1
|
3277
|
|
POST
|
Untested, supply your table and field names in lines 13 & 17. import arcpy
def mean(values):
values = [v for v in values if v is not None]
try:
return sum(values) / len(values)
except ZeroDivisionError:
raise ValueError("No non-null values in input list!")
# get the morning and evening readings from the update table (dict with id as key)
update_rows = {
i: [m, e]
for i, m, e in arcpy.da.SearchCursor("UpdateTable", ["GaugeID", "Morning", "Evening"])
}
# update the gauge layer
with arcpy.da.UpdateCursor("Gauges", ["GaugeID", "AverageReading"]) as cursor:
for i, avg in cursor:
try:
avg = mean(update_rows[i])
except KeyError:
print("GaugeID not found in update table: " + str(i))
continue
except ValueError:
print("Could not calculate average for GaugeID " + str(i))
continue
cursor.updateRow([i, avg])
... View more
06-13-2023
05:00 AM
|
0
|
0
|
794
|
|
POST
|
This is expected behavior, current is different to a file path. When you use current, ArcGIS knows that you want to work with the currently opened project. When you use a file path, ArcGIS loads that project into RAM, without actually opening it in the application. IT does all its operations on that copy in RAM, regardless of whether you currently have opened that project or not. Your code works perfectly fine. Just add that piece at the end of it and then take a look at the copy: aprx.saveACopy(r"project_folder\ProjectCopy") You can also use the save() method, but for that to work, you need to call the script from outside the current project.
... View more
06-12-2023
12:33 PM
|
0
|
2
|
4322
|
|
POST
|
Maybe use the complete name in line 11? Database.DataOwner.PipelineJunction
... View more
06-12-2023
03:31 AM
|
0
|
1
|
2526
|
|
POST
|
Something like this? // split the field into single districts
var districts = Split($feature.districts, ", ")
// get a count for each district
var counts = Dictionary()
for(var i in districts) {
var d = districts[i]
counts[d] = IIf(HasKey(counts, d), counts[d], 0) + 1
}
// combine districts and counts
var output = []
for(var d in counts) {
Push(output, counts[d] + " * " + d)
}
// return
return Concatenate(output, ", ")
... View more
06-09-2023
02:34 PM
|
1
|
0
|
1202
|
|
POST
|
Does it work if you insert this after line 9? // check if the DataOwner is included in the dictionary
if(!HasKey(partners, featureDataOwner)) return false
... View more
06-09-2023
02:04 PM
|
1
|
1
|
1690
|
| 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
|