|
POST
|
You had issues before because you didn't have the null check. When IncidentNumber is null, codeStatement will be "incident_number = ". That is an invalid sql statement, so the Filter() function will fail. When the Arcade expression is validated, it uses default values (I think, not too sure about that. @jcarlson ?), so the expression didn't get validated because it raised an error, until you set incident to a non-null value. With the null check I suggested, you return a default response if the IncidentNumber is null. When you return from a script, the rest of the script isn't executed anymore, so Filter() doesn't get a chance to raise an error, so the expression validates.
... View more
02-19-2023
12:46 AM
|
0
|
1
|
2878
|
|
POST
|
You have the wrong order of arguments for DateDiff Date('today') isn't a thing, Today is You want to use IIf You're not using the correct quote marks, but some mixture of apostrophes and accents, but that might be because you posted your code as text var numDays = 20;
var days = DateDiff(Today(), $feature.inspection_date, 'days');
return IIf(days > numDays, 'inspection needed', $feature.maintenance)
... View more
02-18-2023
03:02 AM
|
0
|
0
|
1194
|
|
POST
|
You canuse the Append tool: Append (Data Management)—ArcGIS Pro | Documentation use the shaep file as input dataset use the table as target dataset set the field matching type to "Use the field map to reconcile field differences" in the field map, remove the source for each output field, set the source of the target field to the input field you want to copy for example, in this screenshot I'm copying the values of "Shapefile.NEAR_FID" to "Table.IntegerField"
... View more
02-17-2023
03:21 AM
|
0
|
0
|
2859
|
|
POST
|
For the Calculate Field tool with Arcade: var related = First(FeaturesetByRelationshipName($feature, "TestPoints__ATTACHREL"))
if(related == null) { return $feature.ATT_NAME }
return related.OBJECTID + ".jpg" Before: After:
... View more
02-16-2023
11:38 PM
|
1
|
3
|
2802
|
|
POST
|
The problem comes in that I don't know how to iterate inside the Z values of the 3d polyline. A polyline is basically a twodimensional array of vertices: polyline = [ [point, point, point], [point, point, point, point, point] ] The geometry and its parts are iterable objects, the vertices are arcpy.Point objects. shape = [r[0] for r in arcpy.da.SearchCursor(layer, ["SHAPE@"])][0]
print("Shape: " + str(shape))
for part in shape:
print("\tPart: " + str(part))
for vertex in part:
print("\t\tVertex: " + str(vertex))
print("\t\t\tCoordinates: " + str([vertex.X, vertex.Y, vertex.Z, vertex.M])) You have to construct a new line geometry, updating the vertices as points probably won't get you anywhere. Assuming that layer and dest_fc are in the same order: # read the elevation values
endpoint_elevations = [row
for row in arcpy.da.SearchCursor(layer, ["Cota_i", "Cota_f"])
]
# start the update cursor for the complete shape token, not just z
with arcpy.da.UpdateCursor(fc_dest, ["SHAPE@"]) as cursor:
for i, row in enumerate(cursor):
# get the corresponding elevation values
start, end = endpoint_elevations[i]
# interpolate the elevation for each vertex
# if your fc is m-aware, you can also uncomment the two lines to update the m values
shape = row[0]
part = shape[0]
new_part = []
slope = (end - start) / shape.length
m_value = 0
for v, vertex in enumerate(part):
if v == 0:
vertex.Z = start
else:
v0 = part[v-1]
v1 = vertex
m_value += ((v1.X - v0.X)**2 + (v1.Y - v0.Y)**2)**0.5
vertex.Z = start + slope * m_value
#vertex.M = m_value
new_part.append(vertex)
# create a new shape and update the feature
new_shape = arcpy.Polyline(arcpy.Array(new_part),
spatial_reference=shape.spatialReference,
#has_m=True,
has_z=True
)
cursor.updateRow([new_shape])
... View more
02-16-2023
11:29 PM
|
1
|
3
|
2555
|
|
POST
|
To post code: Try doing a null check: var incident = $feature.incident_number
if(incident == null) { return "No Incident number!" }
var u = ...
... View more
02-16-2023
10:59 AM
|
1
|
0
|
2905
|
|
POST
|
Does it work if you set the layer to refresh automatically?
... View more
02-16-2023
10:54 AM
|
1
|
1
|
1656
|
|
POST
|
That sketch helped alot. It turns out to be relatively easy: # parameters
polygon_fc = "TestPolygons"
id_field = "IntegerField"
date_field = "DateField"
out_path = "memory/CurrentState"
# copy the feature class
out_fc = arcpy.management.CopyFeatures(polygon_fc, out_path)
# read the input fc
fields = [id_field, date_field, "SHAPE@"]
polygons = [dict(zip(fields, row))
for row in arcpy.da.SearchCursor(polygon_fc, fields)
]
# get unique ids
unique_ids = {p[id_field]
for p in polygons
}
# iterate over the unique ids
for uid in unique_ids:
# get all states of that polygon, sort by date
states = [p
for p in polygons
if p[id_field] == uid
]
states.sort(key=lambda s: s[date_field])
# start updating the output fc for this id
with arcpy.da.UpdateCursor(out_fc, ["SHAPE@"], where_clause=f"{id_field} = {uid}", sql_clause=[None, f"ORDER BY {date_field}"]) as cursor:
# cursor and states are in the same order (oldest to newest)
for i, row in enumerate(cursor):
# get the geometry of this row
state_geometry = states[i]["SHAPE@"] # == row[0]
# erase/subtract each newer state
for k in range(i+1, len(states)):
newer_state_geometry = states[k]["SHAPE@"]
state_geometry -= newer_state_geometry # we can use "-" to get the difference between two polygons
# update the geometry
cursor.updateRow([state_geometry]) Original: Current state:
... View more
02-16-2023
09:12 AM
|
0
|
0
|
2236
|
|
POST
|
var yes = []
for(var field in $feature) {
if($feature[field] == "Yes"){
Push(yes, field)
}
}
return Concatenate(yes, ", ")
... View more
02-16-2023
12:49 AM
|
2
|
1
|
2045
|
|
POST
|
You can probably whip up some Python script. But this part is very unclear: Some polygons that have partially overlap will be changed. For example I have one polygon from 2020 that have cross polygon from 2019 and anther cross polygon from 2021 The 2020 polygon will be cut by 2021 polygon but not by 2019 polygon. Can you clarify that, maybe with a sketch?
... View more
02-16-2023
12:41 AM
|
0
|
1
|
2268
|
|
POST
|
// return early if your condition is false
// this makes the rest of the code more readable
var condition = true
if(!condition) {
return Geometry($feature)
}
var paths = Geometry($feature).paths
var new_paths = []
for(var p in paths) {
var path = paths[p]
var new_path = []
for(var v in path) {
var vertex = path[v]
var new_vertex = [vertex.x, vertex.y, -0.8]
Push(new_path, new_vertex)
}
Push(new_paths, new_path)
}
return Polyline({paths: new_paths, spatialReference: Geometry($feature).spatialReference})
... View more
02-14-2023
04:14 AM
|
2
|
0
|
1775
|
|
POST
|
Similarly to @DavidPike 's answer, I would summarize the points by their polygon attribute and generate random point for each region your problematic points belong to. But I would skip the spatial join and just update the geometry directly. Steps to use: Backup your data! This will change the geometry of the problematic points. Create a backup. Select the problematic points this will remove the need for the geometry logic David suggested Copy paste the script into the ArcGIS Pro Python window Edit the varibales point_layer, polygon_layer, polygon_id, and point_polygon_id Run the script # names of the point and polygon layers in the current map
point_layer = "TestPoints"
polygon_layer = "TestPolygons"
# names of the relationship fields
polygon_id = "TextField" # primary key of the polygon layer
point_polygon_id = "TextField" # foreign key that links the points to the polygons
# get the regions where the points should be
point_regions = [row[0] for row in arcpy.da.SearchCursor(point_layer, [point_polygon_id])]
regions = {pr for pr in point_regions}
# loop over the regions
for region in regions:
# get the count of points that belong in that region
point_count = len([pr for pr in point_regions if pr == region])
# select the region polygon
query = f"{polygon_id} = '{region}'" # my id fields are text fields. if yours are not, remove the single quotes around {region}
arcpy.management.SelectLayerByAttribute(polygon_layer, "NEW_SELECTION", query)
# generate random points in that region and extract their geometries
random_points = arcpy.management.CreateRandomPoints("memory", "RandomPoints", polygon_layer, None, point_count)
new_shapes = [row[0] for row in arcpy.da.SearchCursor(random_points, ["SHAPE@"])]
# start updating the points that belong in this region
query = f"{point_polygon_id} = '{region}'" # again, remove the single quotes if you're working with numbers
with arcpy.da.UpdateCursor(point_layer, ["SHAPE@"], query) as u_cursor:
# loop over the points
for i, row in enumerate(u_cursor):
# copy the new geometries
u_cursor.updateRow([new_shapes[i]]) Before: After:
... View more
02-14-2023
02:17 AM
|
2
|
1
|
2979
|
|
POST
|
$feature.count_id seems to be a text field, but you're missing the quotes in the query. In line 20, either add the single quotes around {id} or use the @ notation like you did in line 10
... View more
02-10-2023
02:14 PM
|
0
|
0
|
934
|
|
POST
|
Regarding irregular cluster shapes: This would be an easy way to generate irregular (but always convex) buffer shapes: def irregular_buffer(point_geometry, min_dist, max_dist, num_points):
points = []
for i in range(num_points):
angle = random.randint(0, 359)
dist = random.randint(min_dist, max_dist)
points.append(point_geometry.pointFromAngleAndDistance(angle, dist).firstPoint)
multipoint = arcpy.Multipoint(arcpy.Array(points), spatial_reference=point_geometry.spatialReference)
return multipoint.convexHull() The num_points argument controls how much the buffer shapes resemble a circle. Higher value -> more circle-like. num_points = 5: num_points = 10: num_points = 30: To use this method, replace lines 41-42 in my original answer with this: cluster_buffer = irregular_buffer(cluster_center, min_cluster_radius, max_cluster_radius, 5) Which indeed results in more irregular clusters: And you can still add a random offset at the end.
... View more
02-10-2023
06:48 AM
|
1
|
0
|
5704
|
| 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
|