POST
|
If your land covers are all in the same feature class (untested): var covers = FeaturesetByName(...)
var i_covers = Intersects(covers, $feature)
var out = []
for(var c in i_covers) {
Push(out, c.LandCoverField)
}
return Concatenate(Distinct(out), ", ") If you have each land cover class in its own feature class (untested): var covers = {
"Forest": FeaturesetByName(...),
"Agriculture": FeaturesetByName(...),
"Water": FeaturesetByName(...),
}
var out = []
for(var cover in covers) {
var i_cover = First(Intersects(covers[cover], $feature))
if(i_cover != null) {
Push(out, cover)
}
}
return Concatenate(out, ", ")
... View more
09-27-2023
03:42 AM
|
0
|
1
|
906
|
POST
|
Manually: Summarize Nearby, choosing your point layer for both input feature classes Select and delete each feature in the output fc where point count > 1 Select points by location, intersect with the summarize fc, these are the points you want to keep. Python: points = "TestPoints"
min_dist = 50
# buffer the points and intersect the points with the buffers
# (this is basically what Summaize Nearby does)
buffers = arcpy.analysis.Buffer(points, "memory/buffers", min_dist)
intersects = arcpy.analysis.Intersect([points, buffers], "memory/intersects")
# count the occurence of each ORIG_FID (the point OID) in the intersections
orig_fids = [row[0] for row in arcpy.da.SearchCursor(intersects, ["ORIG_FID"])]
orig_fid_counts = {fid: len([fid1 for fid1 in orig_fids if fid1 == fid]) for fid in orig_fids}
# create a new field in the point layer that stores the count of nearby points
arcpy.management.AddField(points, "NearbyPoints", "LONG")
# calculate that field
with arcpy.da.UpdateCursor(points, ["OID@", "NearbyPoints"]) as cursor:
for oid, np in cursor:
try:
np = orig_fid_counts[oid] - 1
cursor.updateRow([oid, np])
except KeyError:
pass This will create a new field in your point layer. You only want to include points where that field is 0 in the heatmap. Delete the others or exclude them through selection/definition query.
... View more
09-24-2023
06:09 AM
|
1
|
2
|
1286
|
POST
|
That is absolutely possible. There are two ways to exchange values between (spatially) related tables: Pull: When you add or edit a feature, the rule pulls values from features in related tables and stores them in this feature Push: When you add or edit a feature, the rule pushes values from this feature to features in related tables Which method you implement depends on your use case. Some examples (not tested, there might be some missing parentheses and such): Examples for Pulling: Featureclass "Assets" and related table "Inspections". New Inspection should use the Asset's "Value1" attribute. // Calculation Attribute Rule on Inspections
// Field: Value1
// Triggers: Insert
// get the related asset
var asset_id = $feature.AssetID
var assets = FeaturesetByName($datastore, "Assets")
var asset = First(Filter(assets, "AssetID = @asset_id"))
// if there is no related asset, abort
if(asset == null) { return }
// else return the asset's Value1 attribute
return asset.Value1 Same as above, but the new Inspection should use the Asset's "Value1" and "Value2" attributes. // Calculation Attribute Rule on Inspections
// Field: leave empty
// Triggers: Insert
// get the related asset
var asset_id = $feature.AssetID
var assets = FeaturesetByName($datastore, "Assets")
var asset = First(Filter(assets, "AssetID = @asset_id"))
// if there is no related asset, abort
if(asset == null) { return }
// else return the asset's Value1 and Value2 attributes
return {
result: {
attributes: {
Value1: asset.Value1,
Value2: asset.Value2
}
}
} Polygon featureclass "Parks" and point featureclass "Benches". They are related spatially, but Benches should also store the Park's name. // Calculation Attribute Rule on Benches
// Field: ParkName
// Triggers: Insert
// get the park
var parks = FeaturesetByName($datastore, "Parks")
var park = First(Intersects($feature, parks))
// if there is no intersected park, abort
if(park == null) { return }
// else return the park's name
return park.Name Examples for Pushing: Probably the most common one: Featureclass "Assets" and related table "Inspections". When a new Inspection is added, the date of that latest inspection should be stored in the Asset. // Calculation Attribute Rule on Inspections
// field: leave empty
// Triggers: Insert
// Exclude from application evaluation!
// get the related asset
var asset_id = $feature.AssetID
var assets = FeaturesetByName($datastore, "Assets")
var asset = First(Filter(assets, "AssetID = @asset_id"))
// if there is no related asset, abort
if(asset == null) { return }
// else push an edit to that asset
return {
edit: [{
className: "Assets",
updates: [{
objectID: asset.OBJECTID,
attributes: {
LastInspectionDate: $feature.InspectionDate
}
}]
}]
} Polygon featureclass "Parks" and point featureclass "Benches". They are related spatially, but Benches also store the Park's name (see examples for pulling). Point featureclass "Trees" also stores the Park's name. If the park is renamed, the new name should be pushed to Benches and Trees. // Calculation Attribute Rule on Parks
// field: leave empty
// Triggers: Update
// Exclude from application evaluation!
// get the benches
var benches = FeaturesetByName($datastore, "Benches")
var benches_in_park = Intersects($feature, benches)
// create an empty array that will store the update info
var bench_updates = []
// loop over the intersected benches and fill the update array
for(var bench in benches_in_park) {
var update = {
objectID: bench.OBJECTID,
attributes: {ParkName: $feature.Name}
}
Push(bench_updates, update)
}
// do the same for trees
var trees = FeaturesetByName($datastore, "Trees")
var trees_in_park = Intersects($feature, trees)
var tree_updates = []
for(var tree in trees_in_park) {
var update = {
objectID: tree.OBJECTID,
attributes: {ParkName: $feature.Name}
}
Push(tree_updates, update)
}
// push the edits to the other featureclasses
return {
edit: [{
className: "Benches",
updates: bench_updates
},
{
className: "Trees",
updates: tree_updates
}]
} Point fc and polygon fc. The polygon fc is just a buffer around the point, they are related by PointID. If you add/move/delete a point, the buffer should automatically be created/moved/deleted. // Calculation Attribute Rule on Points
// field: leave empty
// Triggers: Insert, Update, Delete
// Exclude from application evaluation!
// abort if PointID is null
if($feature.PointID == null) { return }
// create empty arrays to store the edits to the polygon fc
var adds = []
var updates = []
var deletes = []
// get the edit type
var mode = $editcontext.editType
// create the new geometry for the polygon
var default_distance = 10
var buffer_distance = DefaultValue($feature.BufferDistance, default_distance)
var new_geometry = Buffer($feature, buffer_distance)
// get the related polygon
var polygons = FeaturesetByName($datastore, "Polygons")
var point_id = $feature.PointID
var poly = First(Filter(polygons, "PointID = @point_id"))
// if no polygon was found (we're inserting a new point or updating a point with missing buffer), create a new polygon
if(poly == null) {
var new_poly = {
geometry: new_geometry,
attributes: {PointID: $feature.PointID}
}
Push(adds, new_poly)
}
// if a polygon exists
else {
// update? -> set new geometry
if(mode == "UPDATE") {
var updated_poly = {
objectID: poly.OBJECTID,
geometry: new_geometry
}
Push(updates, updated_poly)
}
// delete? -> delete the buffer polygon
if(mode == "DELETE") {
var deleted_poly = {objectID: poly.OBJECTID}
Push(deletes, deleted_poly)
}
}
// Push the edits to the polygon fc
return {
edit: [{
className: "Polygons",
adds: adds,
updates: updates,
deletes: deletes,
}]
} Push and Pull combined "Assets" and "Inspections" // Calculation Attribute Rule on Inspections
// field: leave empty
// Triggers: Insert
// Exclude from application evaluation!
// get the related asset
var asset_id = $feature.AssetID
var assets = FeaturesetByName($datastore, "Assets")
var asset = First(Filter(assets, "AssetID = @asset_id"))
// if there is no related asset, abort
if(asset == null) { return }
// else push an edit to that asset
return {
result: {
attributes: {
Value1: asset.Value1,
Value2: asset.Value2
}
},
edit: [{
className: "Assets",
updates: [{
objectID: asset.OBJECTID,
attributes: {
LastInspectionDate: $feature.InspectionDate
}
}]
}]
} For more reading: https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-editing-external-features-with-attribute-rules/
... View more
09-23-2023
01:11 AM
|
3
|
3
|
3028
|
POST
|
No. The SQL Expression parameter requires a dependency. You don't have to set that dependency in the parameter editor. You can also use the parameter.parameterDependencies property in the validation: class ToolValidator:
def __init__(self):
self.params = arcpy.GetParameterInfo()
def updateParameters(self):
self.params[1].parameterDependencies = ["layer"] But for the tool to fill out the lists of field names and values, the parameter needs a dependency. If you don't want to do it that way, you could use a string parameter. Users can then simply input their query (or you can prepare a dropdown).
... View more
09-21-2023
12:26 PM
|
2
|
0
|
409
|
POST
|
&& and != are logical operators used in many programming languages. SQL uses more natural operators, in this case AND and IS NOT NULL, as Ken pointed out. Instead of writing the query yourself, which quickly gets unwieldy and hard to read with all those plusses and apostrophes, you can use the @ notation of the Filter function: var species = Replace($feature.species, "'", "''")
var sql = "Species = @species AND batch_number IS NOT NULL"
return Count(Filter($layer, sql))
... View more
09-21-2023
11:36 AM
|
0
|
0
|
541
|
POST
|
You have to set the dependency of the Sql Expression parameter to a layer/feature class parameter: Then it will grab the possible fields and values from that parameter. Without a selected layer: With a selected layer:
... View more
09-21-2023
11:22 AM
|
0
|
2
|
1045
|
POST
|
arcpy.analysis.Clip is the native Python function call, i.e. Clip is a function in the module analysis from the site package arcpy, it can be found in the file "Path://to/ArcGIS/ArcPy/arcpy/analysis.py" arcpy.Clip_analysis is the syntax you can use after you import a toolbox using ImportToolbox, which arcpy does automatically for the system tools. Both work in ArcMap and ArcGIS Pro.
... View more
09-21-2023
01:24 AM
|
3
|
0
|
440
|
POST
|
You can get and set them via the CIM. # get the layer
aprx = arcpy.mp.ArcGISProject("current")
layer = aprx.activeMap.listLayers("LayerName")[0]
# get the layer's cim
cim = layer.getDefinition("V3")
# create a new display filter
new_filter = arcpy.cim.CIMVectorLayers.CIMDisplayFilter()
new_filter.whereClause = "Your query here"
# set the CIM's displayFilters attribute and apply the CIM to the layer
cim.displayFilters = [new_filter]
layer.setDefinition(cim)
# to remove all filters:
cim.displayFilters = []
layer.setDefinition(cim) Prepare a layer with display queries and get it's CIM to play around with the relevant attributes: displayFilterChoices displayFilterName displayFilters displayFiltersType
... View more
09-18-2023
04:55 AM
|
0
|
0
|
440
|
POST
|
To insert formatted code: If your definition query is the same for all specified layers: layer_names = ["Layer A", "Layer B", "Layer E"]
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name in layer_names and lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = "INSERT_YOUR_DQ_HERE" If you want different queries for the layers: queries = {
"Layer A": "Query for Layer A",
"Layer B": "Query for Layer B",
"Layer E": "Query for Layer E",
}
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name in queries and lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = queries[lyr.name]
... View more
09-18-2023
04:20 AM
|
0
|
0
|
460
|
POST
|
I'm not really sure what your question is... Do you have a table like this and want to construct the lines? Use XY Table To Point to convert the coordinates to points Use Points To Line to convert the points to lines Do you have a coordinate table and want to calculate the ID field like in your example? Use Calculate Field with this Python expression: # UniqueID =
get_id()
# Code Block
i = 0
is_second = True
def get_id():
global i
global is_second
is_second = not is_second
if not is_second:
i += 1
return i
... View more
09-12-2023
03:16 AM
|
0
|
0
|
279
|
POST
|
But doesn't my first script solve this case? Just select both features and run the script. The script will take the first feature of the copy layer (which has only one feature selected, so it doesn't matter) and copies it to all selected features in the paste layer (which also has only one feature selected), so you get a 1-to-1 copy.
... View more
09-11-2023
09:16 AM
|
0
|
7
|
720
|
POST
|
Instead of using a field as category, you can use an Arcade expression: return IIf($feature.YourField < 0, "x < 0", "x >= 0") Using this, you can easily create Bar and Pie Charts: You can also use the expression to calculate a new field in your table and use that field as category field for bar/pie charts. This has the added advantage that you can also use it in other chart types. FOr example, here is a box plot of the integer values by category:
... View more
09-11-2023
03:36 AM
|
1
|
0
|
259
|
POST
|
The Advanced Formatting expression controls how the items are displayed, not which items are displayed. To do what you want, create a one-to-one view.
... View more
09-11-2023
03:15 AM
|
0
|
0
|
405
|
POST
|
This is intentional behavior. For performance reasons, Arcade only loads the fields that are needed in the expression. It does that by checking the expressions for string literals of field names ($feature.Field or $feature["Field"]). That approach fails when you request fields dynamically like you do here. In this case, Arcade (actually probably the Javascript controlling the popup) just doesn't load any fields, because it doesn't realize that you need them. For cases like this, Arcade has the Expects() function. Here you can explicitly state which fields should be available. For convenience, you can also use a wildcard. Just put this at the start of your expression: Expects($feature, "*")
... View more
09-11-2023
02:55 AM
|
1
|
1
|
463
|
Title | Kudos | Posted |
---|---|---|
1 | 01-12-2023 06:22 AM | |
1 | 06-09-2022 10:42 PM | |
1 | 01-12-2022 04:43 AM | |
1 | 03-03-2023 02:01 PM | |
1 | 08-30-2022 08:26 AM |
Online Status |
Offline
|
Date Last Visited |
02-03-2024
06:14 PM
|