|
POST
|
I'm not quite sure what you're trying to achieve, because sum_ano and sum_perimeter aren't defined in your code assuming Area_ha and Area_km2 area the area values of the same polygon, the result will be 100, as that's the conversion factor between ha and km² But, assuming you want to get the sums of two fields grouped by a third field, and then divide those sums for each group: // load your data
var d = {
geometryType:"",
fields:[
{name:"GroupField", type:"esriFieldTypeInteger"},
{name:"Field1", type:"esriFieldTypeDouble"},
{name:"Field2", type:"esriFieldTypeDouble"},
],
features:[]
}
for(var i = 0; i < 20; i++) {
var f = {attributes: {GroupField: Round(Random()*10, 0), Field1: Random(), Field2: Random()}}
Push(d.features, f)
}
var fs = Featureset(Text(d))
//return fs
// get the sums grouped by a field
var fs_sums = GroupBy(fs, ["GroupField"], [
{name: "sum_field_1", expression: "Field1", statistic: "SUM"},
{name: "sum_field_2", expression: "Field2", statistic: "SUM"},
])
// use group by again, grouping by the same field, but using another expression
var fs_quotient = GroupBy(fs_sums, ["GroupField"], [
{name: "sum_field_1", expression: "sum_field_1", statistic: "SUM"},
{name: "sum_field_2", expression: "sum_field_2", statistic: "SUM"},
{name: "quotient", expression: "sum_field_1 / sum_field_2", statistic: "SUM"},
])
return fs_quotient
... View more
10-20-2022
10:53 PM
|
1
|
0
|
3887
|
|
POST
|
In regards to an Arcade community, please lend your support to this idea: Arcade Community - Esri Community In regards to making featuresets available in the labeling and visualization profile: This would be great, but it's probably not coming any time soon. Post from February 2022: There are no plans to extend the labeling or visualization profiles to include FeatureSet functionality for performance reasons. Label and visualization expressions are executed on a per-feature basis and a feature set query executed per-feature would slow down draw performance. For this use-case the recommendation is to use a calculate attribute rule where the script is executed at data creation or update time rather than once per draw loop. FeatureSetByName can be used to perform FeatureSet lookups with any other dataset in the same workspace. Cross-database cases are not currently possible but an idea to support that for future workflows could be submitted for conversation.
... View more
10-20-2022
12:07 AM
|
1
|
1
|
1341
|
|
POST
|
For a Python toolbox (.pyt): in the pyt, reload the imported modules. this will recompile it into the pycache folder refresh the toolbox in Pro. this will make it reread the pycache # Toolbox.pyt
import arcpy
import custom_module
# reload the custom module
import importlib
importlib.reload(custom_module)
class Toolbox():
#... For script tools, I'm not sure, try refreshing the toolbox in Pro.
... View more
10-19-2022
11:55 PM
|
2
|
6
|
4586
|
|
POST
|
You have to change the workspace in the loop: import arcpy as ap
# Set the current workspace
ap.env.workspace = "C:/student/PPA/"
# Confirm that the feature class exists
# If exists, it will be deleted, and a new file geodatabase created with the same name.
# If it does not exist, a new file geodatabase will be created.
# Set local variables
out_folder_path = "C:/student/PPA"
out_name = "PPA.gdb"
# You don't need the else. Just delete the gdb if it exists, then create it
# regardless of whether it existed or not
if ap.Exists("PPA.gdb"):
ap.management.Delete("PPA.gdb")
ap.CreateFileGDB_management("C:/student/PPA/", "PPA.gdb")
# Listing Workspace
workspaces = ap.ListWorkspaces("*", "Folder")
print(workspaces)
# Listing datasets in workspaces
for i in workspaces:
arcpy.env.workspace = i
fc = ap.ListFeatureClasses("*", "Polygon")
print(fc) Also, while it is customary to import some common Python modules with an alias (for example "import numpy as np"), arcpy is commonly imported without an alias. Importing it as "ap" won't result in any errors, but it might make it harder for you to exchange code with others (for example in this forum). If your course uses this alias, keep using it. If not, I suggest importing arcpy without alias.
... View more
10-19-2022
11:47 PM
|
0
|
2
|
1600
|
|
POST
|
Of course you can just let it trigger on update and remove the insert part. Be aware that this will let invalid inserts through. Alternatively, you can return your original error message instead of a default value. This way, invaliud inserts will be rejected. Of course, this will also reset all values in the other fields, when you're editing in the table, not the pane.
... View more
10-19-2022
06:18 AM
|
0
|
1
|
4846
|
|
POST
|
Huh. Try publishing the layer as web image layer / feature layer. That works for me in both Map Viewer versions. I use Portal, it might be different for AGOL. As far as I know, the symbol options in Map Viewer are pretty basic, so you probably won't be able to configure that symbology online. I could be wrong though, as I configure everything in Pro before publishing.
... View more
10-19-2022
12:40 AM
|
0
|
0
|
5618
|
|
POST
|
Yeah, as I thought. You're adding the rule to the feature class you want to update. That means that you create a point, and then the rule triggers and edits a point in the same class. The rule is meant to be created on a different point feature class that you use to edit the "real" feature class.
... View more
10-18-2022
12:02 PM
|
0
|
0
|
5038
|
|
POST
|
In line 17, you try to get the geometry of the line, but in lines 1-3 you explicitly tell Arcade to NOT load the geometries. Does it work if you change that?
... View more
10-18-2022
11:39 AM
|
1
|
1
|
1741
|
|
POST
|
For reference, this is the expression: // Reference layer using the FeatureSetByPortalItem() function.
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'd10b9e8dbd7f4cccbd0a938a06c586e9' , 0, ['Report_road_condition'], false);
// Empty dictionary to capture each hazard reported as separate rows.
var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],
'geometryType': '', 'features': []};
var index = 0;
// Split comma separated hazard types and store in dictionary.
for (var feature in fs) {
var split_array = Split(feature["Report_road_condition"], ',')
var count_arr = Count(split_array)
for(var i = 0; i < count_arr; i++ ){
choicesDict.features[index++] = {
'attributes': { 'split_choices': Trim(split_array[i]),
}}
}}
// Convert dictionary to featureSet.
var fs_dict = FeatureSet(Text(choicesDict));
// Return featureset after grouping by hazard types.
return GroupBy(fs_dict, ['split_choices'],
[{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]); At a quick glance, I don't see where this error could come from. Anything I can think of would either work or give a different error. Check these points anyway: Make sure your portal url and item and sublayer id are correct Make sure you query the correct field (Report_road_condition in the example) Make sure that this field is a text field If these don't work, we need to know more to help: Test the original expression from the example in your Dashboard, does that work? Post your expression If possible, share your data publicly
... View more
10-18-2022
11:31 AM
|
0
|
1
|
2352
|
|
POST
|
Are you sure that you're creating it on the right feature class? This behavior sounds like you create the rule on the class you want to update.
... View more
10-18-2022
11:00 AM
|
0
|
2
|
5044
|
|
POST
|
You could try a Calculation Rule like this: // Calculation Attribute Rule
// field: DisplayName
// triggers: Insert, Update
if(IsEmpty($feature.DisplayName)) {
// When you're inserting without DisplayName, return a default value
if($editcontext.editType == "INSERT") {
return "Default Name"
}
// When you delete the value during editing, restore the previous value
if($editcontext.editType == "UPDATE") {
return $originalfeature.DisplayName
}
}
// When DisplayName has a value, just return that
return $feature.DisplayName This rule will ensure that there is at least a default value in DisplayName, but the editor won't get feedback that something went wrong.
... View more
10-18-2022
12:50 AM
|
2
|
3
|
4880
|
|
POST
|
Your points don't actually pair up (look at the sharp corners), so you'll have problems getting a 1-1 relationship to work. If you have to use these points, you can use CalculateField with an Arcade expression like this: // Calculate a new field on PointFC_1 that stores the OBJECTID of the closest Point in PointFC_2
// load PointFC_2
var point_fc_2 = FeaturesetByName($datastore, "PointFC_2")
// get points close to the current point, choose a buffer value that is big enough to get at least 1 other point!
var p_buffer = Buffer($feature, 1000, "meters")
var close_points = Intersects(point_fc_2, p_buffer)
// loop through the points and find the ID of the closest one
var min_dist = 99999
var closest_oid = null
for(var p in close_points) {
var dist = Distance(p, $feature)
if(dist < min_dist) {
min_dist = dist
closest_oid = p.OBJECTID
}
}
return closest_oid This will leave some points in FC2 without partner and it will give some points in FC1 the same partner. If you want to get a 1-1 relationship, you have to generate your points differently. Copy and edit this Python script, then run it in the Python window: polygon_layer = "TestPolygons"
point_distance = 500
buffer_distance = 100
# create output fc
points = arcpy.management.CreateFeatureclass("", "PairedPoints", "POINT")
arcpy.management.AddField(points, "PolygonOID", "LONG")
arcpy.management.AddField(points, "PointPairID", "LONG")
arcpy.management.AddField(points, "Type", "TEXT")
# generate points ON the line
points_on_lines = arcpy.management.GeneratePointsAlongLines(polygon_layer, "PointsOnLines", 'DISTANCE', point_distance)
# read the polygon geometries as dict {OBJECTID: Geometry}
polygon_shapes = {p[0]: p[1] for p in arcpy.da.SearchCursor(polygon_layer, ["OID@", "SHAPE@"])}
# start inserting points into the output fc
with arcpy.da.InsertCursor(points, ["SHAPE@", "PolygonOID", "PointPairID", "Type"]) as i_cursor:
# loop through the points on the line
with arcpy.da.SearchCursor(points_on_lines, ["SHAPE@", "ORIG_FID", "OID@"]) as s_cursor:
for shp, poly_id, point_id in s_cursor:
# get the polygon this point is on
poly_shp = polygon_shapes[poly_id]
# create a small buffer around the point
p_buffer = shp.buffer(0.01)
# get the 2 points where the buffer intersects with the polygon
i_points = p_buffer.intersect(poly_shp, 1)
sr = poly_shp.spatialReference
fp = arcpy.PointGeometry(i_points.firstPoint, sr)
lp = arcpy.PointGeometry(i_points.lastPoint, sr)
# calculate the angle between those points -> line angle at the curretn point
angle = fp.angleAndDistanceTo(lp)[0]
# create two points perpendicular to the line
p1 = shp.pointFromAngleAndDistance(angle + 90, buffer_distance)
p2 = shp.pointFromAngleAndDistance(angle + 90, -buffer_distance)
# calculate if the points are inside or outside the polygon
p1_type = "OUTSIDE" if p1.disjoint(poly_shp) else "INSIDE"
p2_type = "INSIDE" if p1_type == "OUTSIDE" else "OUTSIDE"
# insert both points
i_cursor.insertRow([p1, poly_id, point_id, p1_type])
i_cursor.insertRow([p2, poly_id, point_id, p2_type])
... View more
10-17-2022
03:20 AM
|
0
|
0
|
1706
|
|
POST
|
You are checking fsParcel for null, but you need to check GPin. The reason for this check: Intersects() returns an empty Featureset when there are no intersecting features. Calling First() on an empty Featureset returns null. Trying to call a field on null will give an error. So, try this expression: var fsParcel = FeatureSetByName($datastore, "COPY_BaseParcel", ["GPin"])
var fsIntersectParcel = Intersects($feature, fsParcel)
var GPin = First(fsIntersectParcel)
if(GPin == null) return null
return GPin.GPin
... View more
10-17-2022
01:34 AM
|
0
|
0
|
1315
|
|
POST
|
Get your Table name as variable (put "%" around the name in ModelBuilder) Use Calculate Value # Expression
generate_arcade_expression(%TableName%)
# Code Block
def generate_arcade_expression(table_name):
return f"""
var fs = FeaturesetByName($datastore, "{table_name}")
var fs_intersect = Intersectcs(fs, $feature)
//...
""" Use the output of Calculate Value as Arcade Expression for Add Attribute Rule.
... View more
10-17-2022
01:07 AM
|
0
|
0
|
710
|
| 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
|