|
POST
|
The expression you found executes a Merge: Take two (or more) datasets with the same fields and copy all rows of those datasets into a new dataset. What you describe sounds like a Join: Assign the rows of one dataset to the rows of another dataset (different fields) based on the values of a common field. Can you please confirm which of these you want? Also, if you want a join, what is the common field?
... View more
07-14-2023
04:29 PM
|
1
|
1
|
3123
|
|
POST
|
To post code: Your example will return null for zinc == 0.067! Also, it can be simplified like this: var zinc = $feature.Zinc
var status = IIf(zinc > 0.067, 'Fail', 'Pass')
return `${zinc} mg/l (${status})` For ranges, you just have to edit the boolean evaluation in IIf(): var zinc = $feature.Zinc
var status = IIf(zinc >= 6 && zinc <= 9, 'Pass', 'Fail')
return `${zinc} mg/l (${status})`
... View more
07-14-2023
04:21 PM
|
1
|
1
|
3972
|
|
POST
|
Like the others have said, you actually have to call the function, and you should compare to None, not space. x = [1, None, 2]
for y in x:
print(y is None)
# False
# True
# False Also, your function is needlessly complicated. Just use something like this: # BFS_concat_trial =
concat_if_not_empty([!Field1!, !Field2!, !Field3!, !Field4!, !Field5!, !Field6!], [None, "", " "], "/")
# code block
def concat_if_not_empty(values, empty, separator):
"""Concatenates non-empty values.
values: list of values to concatenate
empty: list of values considered empty
separator: character used for concatenation
"""
values = [str(v) for v in values if v not in empty]
return separator.join(values)
... View more
07-13-2023
01:16 PM
|
1
|
0
|
2172
|
|
POST
|
I just posted this Idea to do those replacements behind the scenes. Go lend your support to it to hopefully solve this problem in future ArcGIS Pro versions.
... View more
07-13-2023
11:25 AM
|
0
|
0
|
5392
|
|
IDEA
|
Whey you use Formatting Tags in your label expression, the expression breaks for features that have special characters like "<", ">", or "&" in their label fields. See this question for examples. This is because these characters are reserved in HTML: they make up the syntax. To solve this, you have to replace those characters with their HTML entity, eg var txt = $feature.TextField
txt = Replace("&", "&")
txt = Replace(txt, "<", "<")
txt = Replace(txt, ">", ">")
return "<COL red='255'>" + txt + "</COL>" This is a lot of work, you can really easily forget to do this, you have to remember or look up the HTML entities, and users inexperienced with HTML (and probably many experienced ones, too) don't have a clue why their expression breaks for some features. Solution: Just do those replacements behind the scenes.
... View more
07-13-2023
11:23 AM
|
2
|
0
|
2406
|
|
POST
|
The HTML entity for "<" is "<" "<CLR red='255'>" + $feature.Bla + TextFormatting.NewLine + Replace($feature.Bla, "<", "<") + "</CLR>"
... View more
07-13-2023
11:10 AM
|
0
|
0
|
5394
|
|
POST
|
To insert code: This is your script, so that I can call out line numbers: import glob
import arcpy
import os
import re
arcpy.env.overwriteOutput = True
# Set the directory to search
directory = r"G:\GIS_Projects\ArcGIS_Pro\Photo_attachments\Test"
# Set the pattern to search for
pattern = "????-??-????"
# Find all files that match the pattern
files = glob.glob(directory + "\\" + pattern)
# Print the list of matching files
print(files)
# Set the workspace and output location
workspace = r"C:\TEMP\Test_gd.gdb\Tax_parcels"
output_table = r"C:\TEMP\Test_gd.gdb\tblMatch_6"
# Set the character to search for
search_character = pattern
# Create an empty list to store attachment paths
attachment_paths = []
# Walk through the workspace directory and find attachments
for root, dirs, files in os.walk(workspace):
for file in files:
attachment_path = os.path.join(root, file)
attachment_paths.append(attachment_path)
# Call the GenerateAttachmentMatchTable function with the appropriate input parameters
attachment_folder = workspace # The folder containing the attachments
attachment_key_field = "OBJECTID" # The field in the input table that corresponds to the attachment key field
file_extension = "*.jpg; *.pdf" # The file extensions of the attachments to match
relative_path = "RELATIVE" # The path type of the attachment relative to the workspace
arcpy.GenerateAttachmentMatchTable_management(workspace, directory, output_table, attachment_key_field, file_extension, relative_path)
# Open an insert cursor to populate the table with match results
with arcpy.da.InsertCursor(output_table, ["AttachmentPath", "MatchCount"]) as cursor:
# Loop through the attachment paths and count the occurrences of the search character
for attachment_path in attachment_paths:
with open(attachment_path, "r") as attachment_file:
content = attachment_file.read()
match_count = content.count(search_character)
cursor.insertRow([attachment_path, match_count])
filename = os.path.basename(attachment_path) Honestly, I'm amazed that your script runs at all. Line 15: glob() shouldn't find anything here, because your files don't match the pattern "????-??-????", they match the pattern "????-??-????*", note the asterisk wildcard at the end. The whole operation is useless anyway (except maybe for information purposes), because you overwrite the variable in line 31. Line 21: You set the variable workspace to your feature class, but later on you use it like it was the folder that contains the images. Line 31: You're trying to walk through a feature class, not the directory. Line 33/34: Now you're just appending each file in the folder, without checking for your pattern. Line 37: Nope, still not the correct variable. Line 38: Why OBJECTID? Your key field is GPIN! Lines 45 - end: I have no idea what you're trying to do here. You open an InsertCursor on the generated Attachment Match Table, using non-existing fields. Then you loop through the paths you found earlier and read their content as text (but they're jpg or pdf!). And then I assume you want to search for your pattern in the content of these files, but you actually search for the literal string "????-??-????". This all seems like there is some confusion about what the tool Generate Attachment Match Table does. The tool creates a table that matches table rows to files based on the files' names and a corresponding field in the table. The output is meant to be used for Add Attachments, to add the matched files as attachments to those rows. After that the output table can be deleted, it doesn't serve any further purpose. In previous ArcGIS versions, the file name and field value had to match perfectly, else there would be no match. Also, the tool could only do a 1-1 match. If you had multiple files that belonged to the same row, you could only match one of them. If you work in ArcGIS Pro version < 3.1, I have a script here, where I do what I think you want to do. Just replace your paths in lines 1-4 and use GPIN as key_field in line 5. ArcGIS Pro 3.1 added the "Match Pattern" parameter that makes the tool much more flexible. Just set it to "Any" or "Prefix" and you should get all your matches correctly:
... View more
07-13-2023
10:23 AM
|
1
|
0
|
2467
|
|
IDEA
|
Is this what you want? aprx = arcpy.mp.ArcGISProject("current")
m = aprx.listMaps()[0]
m.openView()
l = aprx.listLayouts()[0]
l.openView()
... View more
07-12-2023
12:38 PM
|
0
|
0
|
1926
|
|
POST
|
One of these "CAP" + str(!OBJECTID!)
"CAP{}".format(!OBJECTID!)
f"CAP{!OBJECTID!}" # only ArcGIS Pro
... View more
07-12-2023
11:54 AM
|
0
|
1
|
1387
|
|
POST
|
https://pro.arcgis.com/en/pro-app/latest/help/data/excel/work-with-excel-in-arcgis-pro.htm https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/refresh-excel.htm
... View more
07-11-2023
02:33 PM
|
1
|
0
|
2804
|
|
POST
|
doesn't create a new feature layer The three easiest ways to solve the original question in Python are: create a layer with a definition query and append that layer (this is what my original answer does) create a layer of the whole feature class, select the wanted rows and append that layer do it all with arcpy.da.*Cursors Options one and two create a temporal layer. If you run the script in the Python Window of an ArcGIS Project, that layer will be added to the current map. If that is your problem, you can add these lines to the end to remove the layer. try:
m = arcpy.mp.ArcGISProject("current").activeMap
lyr = m.listLayers("append_layer")[0]
m.removeLayer(lyr)
except:
print("Could not remove the temp layer") If you don't want to create the layer for a different reason, you can use option 3 (untested, will probably be slower for large datasets): target_class = "path:/to/class_2"
append_class = "path:/to/class_1"
id_field = "RowID"
# read the ids that are already in the target class
existing_ids = [row[0] for row in arcpy.da.SearchCursor(target_class, [id_field])]
# create an SQL where clause "IdField NOT IN (1, 2, 3)"
if isinstance(existing_ids[0], str):
id_list = ["'{}'".format(i) for i in existing_ids]
else:
id_list = [str(i) for i in existing_ids]
where_clause = "{} NOT IN ({})".format(id_field, ", ".join(id_list))
# get a list of all field names
fields = [f.name for f in arcpy.ListFields(target_class)]
# exclude some of those fields to avoid raising errors
# replace the field "Shape" with "SHAPE@"
exclude_fields = ["OBJECTID", "GlobalID", "Shape_Length", "Shape_Area"]
fields = [f for f in fields if f not in exclude_fields]
fields = ["SHAPE@" if f == "Shape" else f for f in fields]
# start inserting into the target class
with arcpy.da.InsertCursor(target_class, fields) as i_cursor:
# start reading from the append_class, use the query we defined earlier
with arcpy.da.SearchCursor(append_class, fields, where_clause) as s_cursor:
# copy the rows
for row in s_cursor:
i_cursor.insertRow(row)
... View more
07-11-2023
02:20 PM
|
0
|
3
|
3317
|
|
IDEA
|
Ooh, I missed that update, thanks for the link! It actually does solve your problem. function closest_feature(test_feature, compare_feature_set) {
// ...
}
function project_orthogonally(point_geometry, line_geometry) {
// ...
}
function snap_point_to_polyline(point_geometry, polyline_geometry) {
// ...
}
var line = Polyline({
paths: [[ [0, 0], [1, 1], [1, 5], ]],
spatialReference: {wkid: 3857}
})
var p = Point({x: 2, y: 2, spatialReference: {wkid: 3857}})
var sp1 = snap_point_to_polyline(p, line)
var sp2 = NearestCoordinate(line, p).coordinate
Console("With 3 custom functions: " + sp1)
Console("With NearestCoordinate: " + sp2) With 3 custom functions: {"spatialReference":{"wkid":3857},"x":1,"y":2}
With NearestCoordinate: {"spatialReference":{"wkid":3857},"x":1,"y":2}
... View more
07-11-2023
10:52 AM
|
0
|
0
|
1969
|
|
POST
|
FeaturesetByName() asks for a Featureset Collection. $layer is a Featureset (the Featureset that the current $feature belongs to). To loop through each feature in the current layer, you can just use the $layer global like this: for(var f in $layer) {
// do something with f
}
... View more
07-05-2023
12:06 PM
|
1
|
2
|
1767
|
|
POST
|
Your Artwissenschaftlich field is most probably a text field, containing values like "Homo sapiens sapiens". Your constructed SQL query looks like this: Art_wissenschaftlich = Homo sapiens sapiens But it should look like this: Art_wissenschaftlich = 'Homo sapiens sapiens' Arcade automatically cares about the correct syntax if you use the @ notation. Other notes: You're not loading your lookup field You're need to check if your Filter() found any related features var lookupField = "Kategorie_Gruppe"
var commonField = "Art_wissenschaftlich"
var sourceTable = FeatureSetByName($datastore,"Arten_gesamt", [commonField, lookupField], false)
var commonValue = $feature[commonField]
var matchedFeatures = Filter(sourceTable, `${commonField} = @commonValue`)
var matchedFeature = First(matchedFeatures)
return Iif(matchedFeature == null, "not found", matchedFeature[lookupField]) Or shorter, with hard-coded field names: var sourceTable = FeatureSetByName($datastore,"Arten_gesamt", ["Art_wissenschaftlich", "Kategorie_Gruppe"], false)
var art= $feature.Art_wissenschaftlich
var matchedFeature = First(Filter(sourceTable, "Art_wissenschaftlich = @ART"))
return Iif(matchedFeature == null, "not found", matchedFeature.Kategorie_Gruppe)
... View more
07-05-2023
04:24 AM
|
0
|
0
|
2642
|
|
POST
|
Yeah, getting YMax is easy. Would also be a one-liner with Arcade/Python. But Calculate Geometry Attributes won't give you the X coordinate of the northern-most vertex.
... View more
07-05-2023
12:57 AM
|
0
|
0
|
1528
|
| 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
|