|
POST
|
You don't need to clear the selection. Activate the Move tool this changes the cursor Click on a point the yellow outline appears Move the point, apply by clicking on the checkmark or by pressing F2 The yellow outline disappears, the point is still selected Continue with 2. You don't need to clear the selection, you can just click on the next point. Actually, you don't even need to apply the move, that happens automatically when you select the next point or clear the selection. So it can be done in 2 clicks per point: select it, move it.
... View more
05-30-2022
03:11 AM
|
1
|
1
|
3890
|
|
POST
|
You can also calculate a new field that tells you if a point is the closest point: shapes_points = arcpy.management.GeneratePointsAlongLines("shapes_lyr", "memory/shapes_points", 'PERCENTAGE', Percentage=7)
arcpy.analysis.Near(shapes_points, road)
arcade_expression = """
var fs_points = FeatureSetByName($datastore, "shapes_points", ["ORIG_FID", "NEAR_DIST"], false)
var fid = $feature.ORIG_FID
fs_points = Filter(fs_points, "ORIG_FID = @fid")
return $feature.NEAR_DIST == Min(fs_points, "NEAR_DIST")
"""
arcpy.management.CalculateField(shapes_points, "IsNearest", arcade_expression, "ARCADE", field_type="Short")
with arcpy.da.UpdateCursor("shapes_points", ["IsNearest"], "IsNearest = 0") as cursor:
for row in cursor:
cursor.deleteRow()
arcpy.management.DeleteField(shapes_points, "IsNearest")
... View more
05-30-2022
02:45 AM
|
0
|
0
|
3508
|
|
POST
|
This calculates the distance to the closest building in the same block: // load the whole feature class
var fs_buildings = FeatureSetByName($datastore, "BuildingFC", ["BlockID", "BuildingID"], false)
// only select rows with the current feature's BlockID and not this building
var block_id = $feature.BlockID
var building_id = $feature.BuildingID
var fs_buildings_block = Filter(fs_buildings, "BlockID = @block_id AND BuildingID <> @building_id")
function closest_feature(fs) {
var min_dist = 99999999
var closest_feature = null
for(var f in fs) {
var f_dist = Distance(f, $feature)
if(f_dist < min_dist) {
closest_building = f
min_dist = f_dist
}
}
return closest_feature
}
var closest_building = closest_feature(fs_buildings_block)
if(closest_building == null) { return null }
return Distance($feature, closest_building)
... View more
05-30-2022
01:55 AM
|
0
|
2
|
2687
|
|
POST
|
Dude, relax. We all have our own jobs to take care of before helping others here...
... View more
05-30-2022
01:46 AM
|
0
|
0
|
3825
|
|
POST
|
Well, you just take Josh's answer and apply it to your table: // load the whole feature class
var fs_buildings = FeatureSetByName($datastore, "BuildingFC", ["BlockID", "BuildingID", "BuildingHeight", "BuildingArea"], false)
// only select rows with the current feature's BlockID
var id = $feature.BlockID
var fs_buildings_block = Filter(fs_buildings, "BlockID = @ID")
// define a median function
function median(values) {
var c = Count(values)
var ordered = Sort(values)
Console('Odd number of items. Returning central item')
if(c%2 == 1) {
return ordered[((c+1)/2)-1]
}
var a = ordered[(c/2)-1]
var b = ordered[(c/2)]
return (a+b)/2
}
// get your values
var values = []
for(var f in fs_buildings_block) {
Push(values, f.BuildingHeight)
}
// calculate and return the median
return median(values)
... View more
05-30-2022
01:45 AM
|
1
|
1
|
3825
|
|
POST
|
You won't be able to do it from inside Calculate Field. In Arcade there's no way to get the shape file's path, maaaybe you could do it with Python (I doubt it), but that would be complicated. This is a job for a simple Python script. Edit the script and execute it in the Python Window, in a Notebook, or in your IDE: import arcpy
from pathlib import Path
# get a list of your shape files
# if they are in different sub folders, use rglob instead of glob
folder = Path(r"H:\Test")
shape_files = folder.glob("*.shp")
# go through the list and calculate the field for each shape file
for shape_file in shape_files:
shape_file = str(shape_file) # CalculateField is old and can't handle Path objects...
print(f"Adding field to {shape_file}")
arcpy.management.CalculateField(
in_table=shape_file,
field="OrigPath", # shape file, so can only be 10 characters
expression=f"'{shape_file}'" # this is a string argument, but we also want to return a string, so we use single quotes inside the expression
)
... View more
05-30-2022
01:24 AM
|
1
|
0
|
2980
|
|
POST
|
what is the type of your output? string, list, dict, something else? are the types actually just letters or are you simplifying things? Assuming that you return a string and that the types are just letters (getting more important in ascending alphabetical order): output = "A = 0, B = 1, C = 0 , D = 1"
# change to [ [type, count] ]
converted_output = output.replace(" ", "").split(",")
converted_output = [tc.split("=") for tc in converted_output]
print(f"converted output: {converted_output}")
# sort by count and type (both descending), return first element
sorted_output = sorted(converted_output, key=lambda r: (r[1], r[0]), reverse=True)
print(f"sorted output: {sorted_output}")
most_significant_output = sorted_output[0]
print(f"most significant output: {most_significant_output}")
#converted output: [['A', '0'], ['B', '1'], ['C', '0'], ['D', '1']]
#sorted output: [['D', '1'], ['B', '1'], ['C', '0'], ['A', '0']]
#most significant output: ['D', '1'] If your types are actually not letters but e.g. species, you have to define how to rank them and then use the list.index(element) method in the sort: output = "Pig = 1, Lamb = 1, Chicken = 0, Duck = 1, Cow = 0"
# specify the ranking of the types, starting from lowest
ranked_types = ["Cow", "Pig", "Duck", "Horse", "Lamb", "Chicken"]
# change to [ [type, count] ]
converted_output = output.replace(" ", "").split(",")
converted_output = [tc.split("=") for tc in converted_output]
print(f"converted output: {converted_output}")
# sort by count and type (both descending), return first element
sorted_output = sorted(converted_output, key=lambda r: (r[1], ranked_types.index(r[0])), reverse=True)
print(f"sorted output: {sorted_output}")
most_significant_output = sorted_output[0]
print(f"most significant output: {most_significant_output}")
#converted output: [['Pig', '1'], ['Lamb', '1'], ['Chicken', '0'], ['Duck', '1'], ['Cow', '0']]
#sorted output: [['Lamb', '1'], ['Duck', '1'], ['Pig', '1'], ['Chicken', '0'], ['Cow', '0']]
#most significant output: ['Lamb', '1']
... View more
05-30-2022
12:44 AM
|
0
|
3
|
3797
|
|
POST
|
How do I get the variable loopResults to find the first empty field You're currently looking for !IsEmpty(), so it returns the value of the first non-empty field. Remove the bangs: var loopResults = When(IsEmpty(Project_Design), Project_Design,
IsEmpty(PA_Sent), PA_Sent,
IsEmpty(PA_Recvd), PA_Recvd,
'')
... View more
05-29-2022
11:56 PM
|
0
|
0
|
873
|
|
POST
|
Something like this? var g = Geometry($feature)
var fromPoint= g.paths[0][0]
// test manholes
var Manhole = FeatureSetByName($datastore, "ssManhole", ["facilityid"], false)
var fromManhole = First(Intersects(Manhole, fromPoint))
if(fromManHole != null) { return fromManhole.facilityid }
// test pumps
var Pumps = FeatureSetByName(...)
var fromPump = First(Intersects(Pumps, fromPoint))
if(fromPump != null) { return fromPump.facilityid }
// test fitting
//...
// default return value
return "no intersecting points found"
... View more
05-29-2022
11:22 PM
|
1
|
1
|
1627
|
|
POST
|
It's probably because you're checking length for null, not name_id. As a side note: just use multiple if statements. Your statement is hard to read and understand because of all the parantheses in there, and the $feature stuff doesn't help... var name_id = $feature.name_id
var o_name_id = $originalfeature.name_id
if(name_id == o_name_id) { // you're not changing it
return true
}
if(IsEmpty(name_id)) { // it's blank
return true
}
var len = Count(Text(name_id))
return len == 12
... View more
05-29-2022
10:50 PM
|
1
|
1
|
1240
|
|
POST
|
Explode the multipart features Calculate a new field that tells you whether a singlepart line is the longest part of a multipart feature var id = $feature.ORIG_FID
var fs = $featureset
var all_line_parts = Filter(fs, "ORIG_FID = @ID")
if($feature.Shape_Length == Max(all_line_parts, "Shape_Length")) {
return 1
}
return 0 select and delete all exploded lines where "LongestLine = 0" Calculate the central point coordinates This is not actually the midpoint. This is what the tool help says: "This point is the same as the centroid if the centroid is inside the feature, otherwise it is an inner label point." But it's probably the best you're going to get without pretty large code blocks... Convert to points export to actual point feature class Find nearby polygon features Join MidPoints to the original Line FC using "OBJECTID = ORIG_FID" Add the polygons to that join, using "MidPoints.NEAR_FID = OBJECTID" Calculate the PolygonID field Remove all joins
... View more
05-25-2022
12:26 AM
|
1
|
0
|
3479
|
|
POST
|
If you mean you can't edit feature attributes or add/delete features, then yes, that is impossible, because query layers and database views are readonly. If you have to do your workflow manually, you can add this query layer to your map to show you where problematic features are, but you have to edit the original feature class. If you don't have to do it manually, it seems that this can be easily done with the Calculate Field tool. Use Arcade as language, edit and copy this code: // if poly_id is already there, just return it
if($feature.poly_id != null) {
return $feature.poly_id
}
// load the parcel_poly fc
var fs_parcel_poly = FeatureSetByName($datastore, "DATA.GIS.parcel_poly", ["roll", "correct_id_field"], false)
// filter parcel_poly by "roll = roll_num"
var roll_num = $feature.roll_num
fs_parcel_poly = Filter(fs_parcel_poly, "roll = @roll_num")
// if there is a related parcel_poly, return its parcel id
var parcel_poly = First(fs_parcel_poly)
if(parcel_poly != null) {
return parcel_poly.correct_id_field
}
// else return null
return null
... View more
05-24-2022
09:31 AM
|
1
|
0
|
1149
|
|
POST
|
I would like to know if it's possible to get a pic(image) instead the bus line? Sadly, not in the way you want. Ideally, you would do something like this in the Arcade expression: // this does not work!
Push(
out_arr,
`<img src="https://url.fr/images/line${f.ligne}.png"> vers ${f.destination}...`
) But in the classic Map Viewer, Arcade expressions escape the HTML commands, so they get shown as text. If you limit it to show only one arrival/departure, you can do it like you do for the images above: Use an Arcade expression to return an image url and use that url in the HTML code. Also, it is possible to sort the values on a push function? Well, your sort does work, but it sorts the array alphabetically, and so it sorts first by line, then by destination, and only then by time. To change this behavior, you can use the optional comparatorFunction argument (documentation😞 function sort_by_time(a, b) {
var time_a = Split(a, " ")[-1]
var time_b = Split(b, " ")[-1]
if(time_a < time_b) {return -1}
if(time_a > time_b) {return 1}
return 0
}
var out_arr = [
"Lianes 15 vers Courrejean 09:57:07",
"Lianes 15 vers Pont De La Maye 09:51:45",
]
out_arr = Sort(out_arr, sort_by_time)
Concatenate(out_arr, "\n") Lianes 15 vers Pont De La Maye 09:51:45
Lianes 15 vers Courrejean 09:57:07 Out of interest: Your screenshot is only halfway through the HTML and you're at expression 135. How fast is the popup loading?
... View more
05-24-2022
09:12 AM
|
0
|
1
|
1347
|
|
POST
|
Doing this on the original data is going to be hard or impossible. The two possibilities I see: Use SQL Create a Query Layer or Database View. In a very basic form: SELECT PointName, Max(Value) AS "MaxValue"
FROM Featureclass
GROUP BY PointName Use Attribute Rules Create a new point feature class. Needs a value field. On your original point feature class, create an Attribute Rule that edits the newly created fc, something like this (untested): // Calculation Attribute Rule on original point fc
// field: empty
// triggers: insert, update, delete
// load the label point fc
var labels = FeatureSetByName($datastore, "LabelPoints", ["OBJECTID", "Value"], false)
// intersect the label fc with the active $feature
var label = First(Intersects(labels, $feature))
// create empty arrays to hold commands to add, update, or delete features in the label fc
var adds = []
var updates = []
var deletes = []
// if we're inserting or updating a point and there is no label point there, add it
if($editcontext.editType != "DELETE" && label == null) {
var new_label = {
"geometry": Geometry($feature),
"attributes": {"Value": $feature.Value}
}
Push(adds, new_label)
}
// if we're inserting or updating and there already is a label point there, update its value
if($editcontext.editType != "DELETE" && label != null) {
var updated_label = {
"objectID": label.OBJECTID,
"attributes": {"Value": Max(label.Value, $feature.Value)}
}
Push(updates, updated_label)
}
// if we're deleting a point and there are no other points in that location, delete the label
if($editcontext.editType == "DELETE" && label != null) {
// load the point fc
var points = FeatureSetByName($datastore, "Points", ["OBJECTID"], false)
// intersect with label
var points_at_location = Intersects(label, points)
if(Count(points) == 1) { // only the current $feature, no other points
var deleted_label = {"objectID": label.OBJECTID}
Push(deletes, deleted_label)
}
}
// return, this instructs the gdb to insert, update, or delete a feature in the label fc
return {
"edit": [{
"className": "LabelPoints",
"adds": adds,
"updates": updates,
"deletes": deletes
}]
}
... View more
05-24-2022
08:45 AM
|
0
|
0
|
1471
|
|
POST
|
Use the Text() function: var before = $feature.LASTUPDATE
var after = Text($feature.LASTUPDATE, "MM/Y")
Console(before)
Console(after) 2010-01-19T01:00:00+01:00
01/2010
... View more
05-24-2022
12:33 AM
|
0
|
0
|
603
|
| 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
|