POST
|
I have this issue as well, never been able to find answer, I have just used addDataFromPath() to re-add the layer.
... View more
07-11-2025
04:07 PM
|
0
|
0
|
270
|
POST
|
I'm developing a script tool that allows users to select specific features on a map. The tool has three parameters: Layer – The user selects the target map layer. Layer Field – The user chooses a field within the selected layer. Layer Field Attribute – The user selects an attribute value within the chosen field. Once all parameters are set, the user runs the tool. However, despite receiving no errors, nothing gets selected on the map. Script import arcpy
class ToolValidator:
def __init__(self):
self.params = None
def initializeParameters(self):
return
def updateParameters(self):
# If the layer is selected, and it is a feature layer
if self.params[0].value:
layer_name = self.params[0].valueAsText
try:
fields = [f.name for f in arcpy.ListFields(layer_name)]
if "PLAT_NAME" in fields:
self.params[1].value = "PLAT_NAME" # Auto-populate the field name
# Get unique values from the PLAT_NAME field
values = set()
with arcpy.da.SearchCursor(layer_name, ["PLAT_NAME"]) as cursor:
for row in cursor:
if row[0]:
values.add(row[0])
self.params[2].filter.list = sorted(values)
else:
self.params[1].value = None
self.params[2].filter.list = []
except Exception as e:
self.params[1].value = None
self.params[2].filter.list = []
return
def updateMessages(self):
return
def main():
# Parameters
layer_name = arcpy.GetParameterAsText(0) # Layer name to select from map
field_name = arcpy.GetParameterAsText(1) # Field to search (e.g., PLAT_NAME)
acc_val = arcpy.GetParameterAsText(2) # Attribute value (e.g., "BRIDGEWATER ESTATES #3")
if not layer_name or not field_name or not acc_val:
arcpy.AddError("Layer, field name, or search value is missing.")
return
# Access current project, map, and layout
project = arcpy.mp.ArcGISProject("CURRENT")
active_map = project.listMaps()[0]
layout = project.listLayouts()[0] # Layout is not used here, but included if needed
# Get the target layer by name
try:
target_layer = active_map.listLayers(layer_name)[0]
except IndexError:
arcpy.AddError(f"Layer '{layer_name}' not found in the map.")
return
# Build where clause using input values directly (no escaping)
expression = "{0} = '{1}'".format(field_name, acc_val)
where_clause = str(expression)
arcpy.AddMessage(f"Where clause: {where_clause}")
# Perform the selection
arcpy.management.SelectLayerByAttribute(target_layer, "NEW_SELECTION", where_clause)
# Count and report results
count = int(arcpy.management.GetCount(target_layer)[0])
if count == 0:
arcpy.AddWarning(f"No features found where {field_name} = '{acc_val}'.")
else:
arcpy.AddMessage(f"Selected {count} feature(s) where {field_name} = '{acc_val}'.")
... View more
05-15-2025
03:02 PM
|
0
|
2
|
400
|
POST
|
Using what you posted, I didn't get an error. I have both the polygon and point layer added to my map, when start editing and create the point, the point is created but the ParcelID field is not populated in the point layer. The attribute rule is setup with the following settings, immediate calculation, Field - ParcelID, triggers - both insert & Update.
... View more
02-25-2025
11:31 AM
|
0
|
0
|
307
|
POST
|
I am trying to create an attribute rule that will allow me to create a point and take the attributes from a polygon and transfer them to the point when the point is created, if it's possible. in the attribute rules i get, Error002717: invalid arcade expression, Arcade error: Unexpected null My attribute rule // Read the polygon layer
var poly = FeatureSetByName($datastore, "polygons");
// Find intersecting polygon
var int = Intersects(poly, $feature);
// Check if there is an intersection
if (Count(int) > 0) {
// Get the first intersecting polygon's ParcelID value
var firstPoly = First(int);
return firstPoly.ParcelID;
} else {
// If there's no intersection, retain the existing ParcelID value
return firstPoly.ParcelID;
}
... View more
02-24-2025
03:52 PM
|
0
|
4
|
333
|
POST
|
Thanks for the HTML tips, I made the adjustments you suggested, but nothing gets populated in the columns except for the Fire District column. I am still in Classic Map Viewer because we are still on an older version that doesn't have the "Source" button in the New Map Viewer. Current HTML <table style="border-collapse: collapse; width: 100%;">
<tbody>
<tr>
<th style="border: 1px solid #ddd; padding: 8px;">Fire District</th>
<th style="border: 1px solid #ddd; padding: 8px;">Contact Name</th>
<th style="border: 1px solid #ddd; padding: 8px;">Phone</th>
<th style="border: 1px solid #ddd; padding: 8px;">Email</th>
<th style="border: 1px solid #ddd; padding: 8px;">Address</th>
</tr>
<tr>
<td style="border: 1px solid #ddd; padding: 8px;">{FireDist}</td>
<td style="border: 1px solid #ddd; padding: 8px;">{ContactName1}</td>
<td style="border: 1px solid #ddd; padding: 8px;">{Phone1}</td>
<td style="border: 1px solid #ddd; padding: 8px;">{Email1}</td>
<td style="border: 1px solid #ddd; padding: 8px;">{Address1}</td>
</tr>
<tr>
<td style="border: 1px solid #ddd; padding: 8px;"></td>
<td style="border: 1px solid #ddd; padding: 8px;">{ContactName2}</td>
<td style="border: 1px solid #ddd; padding: 8px;"></td>
<td style="border: 1px solid #ddd; padding: 8px;">{Email2}</td>
<td style="border: 1px solid #ddd; padding: 8px;">{Address2}</td>
</tr>
</tbody>
</table> Current Arcade code, // Debugging: Trim whitespace and standardize case for comparison
var fireDistValue = Upper(Trim($feature.FireDist));
// Define contact information for Fire
var Contact1 = {
name: "xyz",
phone: "xyzx",
email: "xyz",
address: "xyzxy"
};
var Contact2 = {
name: "xyz",
phone: "xyzx",
email: "xyzx",
address: "xyzxy"
};
// Function to format contact details
function formatContact(contact) {
return "Contact: " + contact.name +
"\nPhone: " + contact.phone +
"\nEmail: " + contact.email +
"\nAddress: " + contact.address;
}
// Initialize result string
var result = "Fire District: " + fireDistValue + "\n\n";
// Check the fire district and append the appropriate contact info
if (fireDistValue == "xyzx xyzx FIRE") {
result += formatContact(Contact1) + "\n\n" + formatContact(Contact2);
} else {
result += "No contact information available for this Fire District.";
}
// Return the result
return result;
... View more
02-10-2025
09:58 AM
|
0
|
0
|
629
|
POST
|
I clicked on the "Source" button and pasted the HTML code block, Click the source button once again. My expression name is Custom{expression/expr13} table style="border-collapse: collapse; width: 100%;"> Fire District Contact Name Phone Email Address {FireDist} {ContactName1} {Phone1} {Email1} {Address1} {ContactName2} {Email2} {Address2} I get , table style="border-collapse: collapse; width: 100%;"> Fire District Contact Name Phone Email Address xyzx xyzx FIRE I can do <td rowspan="2" style="border: 1px solid #ddd; padding: 8px;">{expression/expr8}</td>
<td style="border: 1px solid #ddd; padding: 8px;">{expression/expr13}</td> But it puts all the info in both columns, it's not being separated out.
... View more
02-10-2025
08:08 AM
|
0
|
0
|
631
|
POST
|
I am trying to build a popup in an ArcGIS Online map that displays fire district contact information using Arcade and HTML. My Arcade script successfully retrieves and formats the data, but I want to link it to the HTML table for a cleaner, structured display. Is this possible? Arcade // Debugging: Trim whitespace and standardize case for comparison
var fireDistValue = Upper(Trim($feature.FireDist));
// Define contact information for Fire
var Contact1 = {
name: "xyzxy xyzxy",
phone: "xyz-xyz-xyzx",
email: "xyz@xyzxyz.xyz",
address: "xyz xyzxyzxy, xyzxyz, xy xyzxy"
};
var Contact2 = {
name: "xyzxy xyzxy",
phone: "xyz-xyz-xyzx",
email: "xyz@xyzxyz.xyz",
address: "xyz xyzxyzxy, xyzxyz, xy xyzxy"
};
// Function to format contact details
function formatContact(contact) {
return "Contact: " + contact.name +
"\nPhone: " + contact.phone +
"\nEmail: " + contact.email +
"\nAddress: " + contact.address;
}
// Initialize result string
var result = "Fire District: " + fireDistValue + "\n\n";
// Check the fire district and append the appropriate contact info
if (fireDistValue == "FIRE") {
result += formatContact(Contact1) + "\n\n" + formatContact(Contact2);
} else {
result += "No contact information available for this Fire District.";
}
// Return the result
return result; html table style="border-collapse: collapse; width: 100%;">
<tbody>
<tr>
<th style="border: 1px solid #ddd; padding: 8px;">Fire District</th>
<th style="border: 1px solid #ddd; padding: 8px;">Contact Name</th>
<th style="border: 1px solid #ddd; padding: 8px;">Phone</th>
<th style="border: 1px solid #ddd; padding: 8px;">Email</th>
<th style="border: 1px solid #ddd; padding: 8px;">Address</th>
</tr>
<tr>
<td style="border: 1px solid #ddd; padding: 8px;">${FireDist}</td>
<td style="border: 1px solid #ddd; padding: 8px;">${ContactName1}</td>
<td style="border: 1px solid #ddd; padding: 8px;">${Phone1}</td>
<td style="border: 1px solid #ddd; padding: 8px;">${Email1}</td>
<td style="border: 1px solid #ddd; padding: 8px;">${Address1}</td>
</tr>
<tr>
<td style="border: 1px solid #ddd; padding: 8px;"></td>
<td style="border: 1px solid #ddd; padding: 8px;">${ContactName2}</td>
<td style="border: 1px solid #ddd; padding: 8px;"></td>
<td style="border: 1px solid #ddd; padding: 8px;">${Email2}</td>
<td style="border: 1px solid #ddd; padding: 8px;">${Address2}</td>
</tr>
</tbody>
</table>
... View more
02-07-2025
03:03 PM
|
0
|
4
|
686
|
POST
|
I have a DEM from the USGS and I would like to make slope percent and contours layers from the DEM and I need to convert from GCS_North_American_1983 to State Plane and if I use project Raster tool to re-project the DEM Do I still need to worry about apply the z-factor when using the Slope and Contour tool?
... View more
08-28-2024
03:38 PM
|
0
|
0
|
245
|
POST
|
I am on 3.7, but I was not able to get past the ,from arcpy.typing.describe import FeatureClass. The issue ended up being the Shape@ and Legnth fields. For some reason they were not calculated correctly in the File Geodatabase. So my code did work by updating the NewIDField.
... View more
08-01-2024
07:19 AM
|
1
|
1
|
1339
|
POST
|
Yes, I did know that, which is why I am trying to populate the new filed "NewIDField". I am still having issue with the sort.
... View more
07-26-2024
11:08 AM
|
0
|
1
|
1471
|
POST
|
I am need to reorder the objectID, but I am having difficulties getting the code correct. The OriginalOrder.png is what it currently is and the ReOrder.png is what I want. see pictures. I need the reorder to match the ReOrder picture. code, import arcpy
# Define paths
input_fc = r"C:\Temp\Grid.gdb\Clipped_Grid_Polygons"
# Add fields for Max_Longitude and Min_Latitude if they don't already exist
fields = [f.name for f in arcpy.ListFields(input_fc)]
if "Max_Longitude" not in fields:
arcpy.AddField_management(input_fc, "Max_Longitude", "DOUBLE")
if "Min_Latitude" not in fields:
arcpy.AddField_management(input_fc, "Min_Latitude", "DOUBLE")
if "NewIDField" not in fields:
arcpy.AddField_management(input_fc, "NewIDField", "LONG")
# Calculate Max_Longitude and Min_Latitude for each feature
with arcpy.da.UpdateCursor(input_fc, ["OBJECTID", "SHAPE@", "Max_Longitude", "Min_Latitude"]) as cursor:
for row in cursor:
polygon = row[1]
max_longitude = max(point.X for part in polygon for point in part)
min_latitude = min(point.Y for part in polygon for point in part)
row[2] = max_longitude
row[3] = min_latitude
cursor.updateRow(row)
print("Max_Longitude and Min_Latitude fields calculated and updated.")
# Extract the features into a list
features = []
with arcpy.da.SearchCursor(input_fc, ["OBJECTID", "Max_Longitude", "Min_Latitude"]) as cursor:
for row in cursor:
features.append((row[0], row[1], row[2]))
# Sort the list based on Min_Latitude (ascending) and Max_Longitude (descending)
features.sort(key=lambda x: (x[2], -x[1]))
# Create a dictionary to map the new OID values
new_oid_mapping = {oid_tuple[0]: index + 1 for index, oid_tuple in enumerate(features)}
# Update the original feature class with the new NewIDField values based on the sorted order
with arcpy.da.UpdateCursor(input_fc, ["OBJECTID", "NewIDField"]) as cursor:
for row in cursor:
current_oid = row[0]
if current_oid in new_oid_mapping:
row[1] = new_oid_mapping[current_oid]
cursor.updateRow(row)
print("NewIDField values reordered based on Min_Latitude and Max_Longitude sorting.")
... View more
07-26-2024
09:38 AM
|
1
|
6
|
1502
|
POST
|
I have some fields that I need to remove the # and numbers, but I need to keep one that matches exactly HIGHWAY DISTRICT #4. I can't seem to get to bypass "HIGHWAY DISTRICT #4". When I run my code, it removes the #4 from HIGHWAY DISTRICT #4 import arcpy
import time
fc3 = r"C:\Default.gdb\Table_1"
fld = ['FireDist', 'HighwayDist', 'SchoolDist']
def dump_stuff(val):
"""Remove unwanted characters from fields except 'HIGHWAY DISTRICT #4'"""
if isinstance(val, str):
if val.strip() == "HIGHWAY DISTRICT #4":
return val # Keep "HIGHWAY DISTRICT #4" unchanged
else:
return "".join([i for i in val if not (i.isdigit() or i == '#')])
return val
start_time = time.time() # Record the start time
with arcpy.da.UpdateCursor(fc3, fld) as cursor:
for row in cursor:
# Process each field in the row
new_row = [dump_stuff(val) for val in row]
cursor.updateRow(new_row)
end_time = time.time() # Record the end time
elapsed_time = end_time - start_time
minutes, seconds = divmod(elapsed_time, 60)
print(f"Process time: {int(minutes)} minutes {int(seconds)} seconds")
... View more
06-14-2024
11:03 AM
|
0
|
2
|
547
|
POST
|
Thanks for the reply. I was coming back to my post to add code that worked for me. try:
# Update the street names in the table
with arcpy.da.UpdateCursor(table, "STREET") as cursor:
for row in cursor:
street_name = row[0]
# List of common street prefixes to be removed
prefixes = ['N ', 'S ', 'E ', 'W ', 'North ', 'South ', 'East ', 'West ']
# Remove prefixes from the street name
for prefix in prefixes:
if street_name.startswith(prefix):
row[0] = street_name[len(prefix):].strip()
cursor.updateRow(row)
break Your code did work tho. Again thanks for the reply!
... View more
01-08-2024
09:44 AM
|
1
|
2
|
2211
|
Title | Kudos | Posted |
---|---|---|
1 | 08-01-2024 07:19 AM | |
1 | 07-26-2024 09:38 AM | |
1 | 01-08-2024 09:44 AM | |
1 | 03-07-2023 11:46 AM | |
1 | 11-02-2020 08:24 AM |
Online Status |
Offline
|
Date Last Visited |
07-14-2025
07:49 AM
|