|
POST
|
// load the feature set using an appropriate FeatureSetBy* function
// see FeatureSetByID and below:
// https://developers.arcgis.com/arcade/function-reference/data_functions/#featuresetbyid
var fs = FeatureSetBy*(...)
// filter the feature set by county ID
// your scrrenshot shows field aliases, not names, check that I guessed the right name
var county_id = $feature.CountyID
var fs_county = Filter(fs, "CountyID = @county_id")
// return the sum of field "Acres"
return Sum(fs_county, "Acres")
... View more
01-05-2022
12:00 AM
|
0
|
1
|
1883
|
|
IDEA
|
You can add styles to your project favorites. That way, they are available in all projects.
... View more
01-04-2022
11:43 PM
|
0
|
0
|
2773
|
|
POST
|
Have you checked that your geometries are OK? An invalid geometry will display on the map but won't show a label. If this is what's wrong, running the RepairGeometries tool should solve it. https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/check-geometry.htm https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/repair-geometry.htm
... View more
01-03-2022
12:40 AM
|
0
|
0
|
2397
|
|
POST
|
NOT TESTED AT ALL, TEST FIRST ON A COPY OF YOUR FC! fc = "path:/to/your/fc"
# the screenshot you shared shows the field aliases (they have spaces).
# you need to use the actual field names in this script!
# get the correct room names as dict {room_id: room_name}
cursor = arcpy.da.SearchCursor(fc, ["RoomID", "RoomName"], "RoomName <> 'ROOM NAME'")
room_dict = dict([row for row in cursor])
# go through each wrong record an insert the right room number
# notice the different SQL query!
with arcpy.da.SearchCursor(fc, ["RoomID", "RoomName"], "RoomName = 'ROOM NAME'") as cursor:
for row in cursor:
try:
name = room_dict[row[0]]
cursor.updateRow([row[0], name])
except KeyError:
print("No RoomNumber found for RoomID {}".format(row[0]))
... View more
01-03-2022
12:32 AM
|
0
|
0
|
2165
|
|
POST
|
In this case you have to call FeatureSetByRelationShip multiple times: to get the busses at the stop for each bus to get the passengers var busses_at_stop = FeatureSetByRelationshipName($feature, "BussesAtStop") // first related table
var total_passengers_at_stop = 0
for(var bus in busses_at_stop) {
var passengers_in_bus = FeatureSetByRelationshipName(bus, "PassengersInBus") // second related table
total_passengers_at_stop += Sum(passengers_in_bus, "Numpass")
}
return total_passengers_at_stop
... View more
01-02-2022
11:54 PM
|
1
|
0
|
3926
|
|
POST
|
If you want to get attachments from an attachment table created by the EnableAttachments tool, then you should use the Attachments() function (as Josh said). If your attachments are from a table created by a user, then I'd guess the problem is that you try to store the result of FeatureSetByName into a reserved variable name (Attchments). Try this: // the name attachments is reserved for the Attachments() function
var attach = FeatureSetByRelationshipName($feature, 'rel_Structure_Attachments', ['globalid'], false);
if (Count(attach) > 0) {
return "Relationships were found."
} else {
return "No relationship were found."
}
... View more
01-02-2022
11:41 PM
|
0
|
0
|
2404
|
|
POST
|
Ah, I overlooked the AGOL tag... You can't create a relationship class between AGOL layers. You can only create them between tables/feature classes in geodatabases and then publish the tables. Same with attribute rules. Honestly, I'm not sure if my approach works in AGOL at all, never used it. I know it works when you publish the layers to Portal and consume them in a web app.
... View more
12-15-2021
02:04 AM
|
0
|
1
|
4336
|
|
POST
|
// summary FeatureSets
var no_loss_type_1 = {"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"A - No Impact","FeatureCount":35}},{"attributes":{"Category":"B - Material Excavation","FeatureCount":2}},{"attributes":{"Category":"D - Habitat Restoration","FeatureCount":3}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":8}},{"attributes":{"Category":"F - Utilities","FeatureCount":2}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":14}}]}
var no_loss_type_2 = {"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"B - Material Excavation","FeatureCount":1}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":3}},{"attributes":{"Category":"F - Utilities","FeatureCount":1}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":2}}]}
no_loss_type_1 = FeatureSet(Text(no_loss_type_1))
no_loss_type_2 = FeatureSet(Text(no_loss_type_2))
// This is ugly, but it works
var count_dict = {} // dict of {Category: FeatureCount}
var cat_array = [] // to keep track of the dict keys
var fs_array = [no_loss_type_1, no_loss_type_2] // FeatureSets to combine
for(var i in fs_array) {
for(var f in fs_array[i]) {
// get category and feature count
var cat = f.Category
var cnt = f.FeatureCount
if(Includes(cat_array, cat)) {
// cat already in dict? -> add the dict's value to cnt
cnt += count_dict[cat]
} else {
// new cat? -> append cat to cat_array
Push(cat_array, cat)
}
// add/update the count in count_dict
count_dict[cat] = cnt
}
}
// Create output FeatureSet
var out_fs = {
"fields":[
{"name":"Category","type":"esriFieldTypeString"},
{"name":"FeatureCount","type":"esriFieldTypeInteger"},
],
"geometryType":"",
"features":[]
}
// add features
for(var i in cat_array) {
var cat = cat_array[i]
var f = {"attributes": {"Category": cat, "FeatureCount": count_dict[cat]}}
Push(out_fs.features, f)
}
return FeatureSet(Text(out_fs))
... View more
12-15-2021
12:47 AM
|
1
|
1
|
1343
|
|
POST
|
apologies that going through my formatting was likely arduous! Eh, I just ran it through an online HTML prettifier, no big problem. Is this normal in survey123 connect? I haven't worked with Survey123, so I don't know if it's "normal". I certainly hope not! But ESRI blocks many HTML things in their widgets, and it seems that they block different things in different widgets. Survey123 seems to block more things than e.g. the Info widget in a WebApp, as we saw in your post about the underline. But coloring the first bullet point is obviously wrong, and that is probably not Survey123's fault. If you want, you can post your code (either her or in a pm) and I'll take a look at it when I have time. No promises on a solution, though.
... View more
12-13-2021
07:25 AM
|
1
|
1
|
1628
|
|
POST
|
Create a new point feature class: name: PolygonCentroids add GlobalID add Field: PolygonGUID, type GUID Create a relationship class between the polygon feature class and PolygonCentroids: name: RsPolygonCentroids key fields: Polygons.GlobalID, PolygonCentroids.PolygonGUID Create an attribute rule for your polygon feature class: // Calculation Attribute Rule on polygon feature class
// field: empty
// triggers: insert, update, delete
// this object will be returned to edit the related point fc
var edit_points = {"className": "PolygonCentroids", "adds": [], "updates": [], "deletes": []}
var mode = $editcontext.editType
var poly_guid = $feature.GlobalID
var p_geometry = Centroid($feature)
var p_attributes = {"PolygonGUID": poly_guid}
if(mode == "INSERT") {
// if a polygon is inserted, insert a new point
Push(edit_points.adds, {"geometry": p_geometry, "attributes": p_attributes})
} else {
// find the related point(s)
var related_points = FeatureSetByRelationshipName($feature, "RsPolygonCentroids")
for(var p in related_points) {
if(mode == "UPDATE") {
// update geometry
Push(edit_points.updates, {"globalID": p.GlobalID, "geometry": p_geometry})
}
if(mode == "DELETE") {
// delete point
Push(edit_points.deletes, {"globalID": p.GlobalID})
}
}
}
// apply the edits
return {"edits": [edit_points]} The names are up to you, of course, but you have to change them in the script accordingly. This will give you an automatically updated point feature class with the polygon centroids and the GlobalID of the respective polygons. To get the polygon attributes in the point popup, create an Arcade expression for each attribute you want to show, you can show the results in the popup's attribute table as usual. var related_polygons = FeatureSetByRelationshipName($feature, "RsPolygonCentroids")
if(Count(related_polygons) > 0) {
return First(related_polygons).Attribute
}
... View more
12-13-2021
06:52 AM
|
1
|
6
|
4385
|
|
POST
|
Hmmm. If you use "Split by" instead of "Category", you can change the symbols in the "Series" tab. I was expecting that I could group symbols there like in the Symbology tab, but right-clicking in the symbol table does nothing. Doesn't seem to be implemented. You could post it as an Idea.
... View more
12-13-2021
03:56 AM
|
1
|
0
|
1537
|
|
POST
|
This is how your code looks when you format it cleanly: <div style="font-weight:bold; font-size:15px; color:#00ffff">You are invited to participate in the Stories for Stream2Sea Project because you:</div>
<ul>
<li>
<div style= "font-size:15px; color:#ffffff">
Are a Canadian citizen;
</li>
<li>
<li>
<div style= "font-size:15px; color:#ffffff">
Are over 18 years of age;
</li>
<li>
<li>
<div style= "font-size:15px; color:#ffffff">
Are Ocean: Your body is 60% water, you live in a country with 3 ocean borders, the world's longest coastline, with the largest proportion of freshwater lakes.
</ul>
<br></li>
<div style="font-weight:bold; color: #00ffff; font-size:15px;">
What is involved</div style="font-weight:bold">
<div style="font-size:15px;">
<ol>
<li>
<li>
<div style= "font-size:15px; color:#ffffff">
Reading & consenting to this Letter;
</li>
<li>
<li>
<div style= "font-size:15px; color:#ffffff">
Completing the story guide to share your story on the Stream2Sea StoryMap [HYPERLINK].
</li>
</ol>
<br> You're opening lots of div and li tags without closing them. Survey123 seems to do a lot of work to hide that, but this is what the result should look like (Info widget in a WebApp; you get the same result when you copy your code into a text file, save that as .html and open it with your broser): I don't know why your first bullet point is colored, you did close those tags correctly. It could be a result of Survey123 fighting with your code. Clean up your code and see if that works or not. From my own painful experience: When you open a tag, immediatly close it. Only then start to fill out its content. This way, you don't forget to close tags. Put general attributes (eg font size, font color) into an enclosing div, so that you don't have to specify them over and over again. Indenting your code can help you understand its structure and find missing closing tags. <div style="font-size: 15px; color: white;"> <!-- General font attributes -->
<div style="font-weight: bold; color: #00ffff"> <!-- Special font attributes for this div -->
You are invited to participate in the Stories for Stream2Sea Project because you:
</div>
<ul>
<li>Are a Canadian Citizen;</li>
<li>Are over 18 years of age;</li>
<li>Are Ocean: Your body is 60% water, you live in a country with 3 ocean borders, the world's longest coastline, with the largest proportion of freshwater lakes.</li>
</ul>
<br/>
<div style="font-weight: bold; color: #00ffff">
What is involved
</div>
<ol>
<li>Reading & consenting to this Letter;</li>
<li>Completing the story guide to share your story on the Stream2Sea StoryMap [HYPERLINK].</li>
</ol>
</div>
... View more
12-12-2021
11:23 PM
|
0
|
3
|
1630
|
|
POST
|
As the title suggests, all my notifications have disappeared. I logged in, saw that I had like 8 or so notifications, clicked on the bell and was informed that I in fact had no notifications at all. I still got my comment history and my subscriptions, just the notifications got eaten by the server, I guess. Logging out didn't do anything.
... View more
12-12-2021
10:13 PM
|
0
|
3
|
1483
|
|
POST
|
A few general remarks: You don't need to call perc_cover_values[sample_id], you already have that defined as sample_list You can use a where clause in SearchCursor. No need to select in the layer first. It's better form to let calc_veg_dom only handle the calculation and do the table manipulation in main. This way, all the input and output is in one place instead of hidden in another method. You don't need the sample points at all for this. You know which perc_cover values are from the same sampling site by looking at herb_stratum_repeat.parentglobalid. This also eliminates the need for CalculateField and you can use the UpdateCursor. import arcpy
# GLOBAL VARIABLES
ID_FIELD = "globalid"
POINT_ID_FIELD = 'parentglobalid'
PERC_COVER_FIELD = 'abs_perc_cover_herb'
DOM_SPECIES_FIELD = 'dom_species_herb'
def calc_veg_dom(sample_dict):
"""Applies the 50/20 rule for calculating vegetation dominance. The function creates a list that identifies the
percent values that are for dominant species for a specific sampling point.
Arguments:
sample_dict: Dictionary, {ID_FIELD: PERC_COVER_FIELD}
Retuns:
Dictionary, {ID_FIELD: DOM_SPECIES_FIELD}
"""
# convert to [ [ID_FIELD, PERC_COVER_FIELD] ], so we can sort
sample_list = [[s_id, perc] for s_id, perc in sample_dict.items()]
# sort descending by PERC_COVER_FIELD
sample_list.sort(key=lambda s: s[1], reverse=True)
# calculate the total cover and target cover values
total_cover = sum([s[1] for s in sample_list])
perc_cover_50 = total_cover * 0.5
perc_cover_20 = total_cover * 0.2
dom_dict = dict()
# 50% rule: species that contribute to more than 50% are dominant, species with tied cover values must be taken together
# 20% rule: species with more than 20% coverage are dominant
percentages = [] # to check for tied cover values and to calculate cover sum
for item in sample_list:
if sum(percentages) <= perc_cover_50:
percentages.append(item[1])
dom_dict[item[0]] = "Y"
elif item[1] in percentages or item[1] >= perc_cover_20:
dom_dict[item[0]] = "Y"
else:
dom_dict[item[0]] = "N"
return dom_dict
###########################################################################################################
def main():
# You only need the stratum table!
fc = arcpy.GetParameterAsText(0)
stratum_table = arcpy.GetParameterAsText(1)
# load the table data
fields = [ID_FIELD, POINT_ID_FIELD, PERC_COVER_FIELD]
stratum_data = [row for row in arcpy.da.SearchCursor(stratum_table, fields)]
# get uniqe point_ids
point_ids = {sd[1] for sd in stratum_data} # set eliminates duplicates
# output dict {ID_FIELD: DOM_SPECIES_FIELD}
dom_dict = dict()
# for each point, get the perc_covers and calculate dominance
for point_id in point_ids:
# input for calc_veg_dom: {ID_FIELD: PERC_COVER_FIELD}
point_stratum_data = {sd[0]: sd[2] for sd in stratum_data if sd[1] == point_id}
# output from calc_veg_dom: {ID_FIELD: DOM_SPECIES_FIELD}
point_dom_data = calc_veg_dom(point_stratum_data)
# add results to dom_dict
dom_dict.update(point_dom_data)
# write the results into stratum_table
fields = [ID_FIELD, DOM_SPECIES_FIELD]
with arcpy.da.UpdateCursor(stratum_table, fields) as cursor:
for s_id, dom in cursor:
try:
dom = dom_dict[s_id]
cursor.updateRow([s_id, dom])
except KeyError:
print("No dominance value found for {} = {}".format(ID_FIELD, s_id))
if __name__ == "__main__":
#main()
# test calc_veg_dom
import random
sample_dict = dict()
x = 0
while sum(sample_dict.values()) < 100:
sample_dict["id_{}".format(x)] = random.randint(5, 40)
x += 1
print("in: ", sample_dict)
print("out: ", calc_veg_dom(sample_dict))
... View more
12-10-2021
01:56 AM
|
1
|
1
|
3915
|
| 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
|